{"language": "Python", "id": 26, "repo_owner": "canonical", "repo_name": "cloud-init", "head_branch": "holman/dhcpcd", "workflow_name": "Lint Tests", "workflow_filename": "check_format.yml", "workflow_path": ".github/workflows/check_format.yml", "contributor": "holmanb", "sha_fail": "385c14d0ae500918cff5565ea836884bfaa2bfa5", "sha_success": "0193e09ca15ed70a351203ab6f21dc52a60d6253", "workflow": "name: Lint Tests\non:\n pull_request:\n push:\n branches:\n - main\n\nconcurrency:\n group: 'ci-${{ github.workflow }}-${{ github.ref }}'\n cancel-in-progress: true\ndefaults:\n run:\n shell: sh -ex {0}\n\njobs:\n check_format:\n strategy:\n fail-fast: false\n matrix:\n env: [ruff, mypy, pylint, black, isort]\n lint-with:\n - {tip-versions: false, os: ubuntu-20.04}\n - {tip-versions: true, os: ubuntu-latest}\n name: Check ${{ matrix.lint-with.tip-versions && 'tip-' || '' }}${{ matrix.env }}\n runs-on: ${{ matrix.lint-with.os }}\n steps:\n - name: \"Checkout #1\"\n uses: actions/checkout@v3.0.0\n\n - name: \"Checkout #2 (for tools/read-version)\"\n run: |\n git fetch --unshallow\n git remote add upstream https://git.launchpad.net/cloud-init\n\n - name: Dependencies\n run: |\n sudo DEBIAN_FRONTEND=noninteractive apt-get -qy update\n sudo DEBIAN_FRONTEND=noninteractive apt-get -qy install tox\n\n - name: Print version\n run: python3 --version\n\n - name: Test\n if: ${{ !matrix.lint-with.tip-versions }}\n env:\n # matrix env: not to be confused w/environment variables or testenv\n TOXENV: ${{ matrix.env }}\n run: tox\n - name: Test (tip versions)\n if: matrix.lint-with.tip-versions\n continue-on-error: true\n env:\n TOXENV: tip-${{ matrix.env }}\n run: tox\n schema-format:\n strategy:\n fail-fast: false\n name: Check json format\n runs-on: ubuntu-22.04\n steps:\n - name: \"Checkout #1\"\n uses: actions/checkout@v3.0.0\n\n - name: \"Test format\"\n run: |\n tools/check_json_format.sh cloudinit/config/schemas/schema-cloud-config-v1.json\n tools/check_json_format.sh cloudinit/config/schemas/schema-network-config-v1.json\n tools/check_json_format.sh cloudinit/config/schemas/versions.schema.cloud-config.json\n\n doc:\n strategy:\n fail-fast: false\n name: Check docs\n runs-on: ubuntu-22.04\n steps:\n - name: \"Checkout #1\"\n uses: actions/checkout@v3.0.0\n\n - name: \"Checkout #2 (for tools/read-version)\"\n run: |\n git fetch --unshallow\n git remote add upstream https://git.launchpad.net/cloud-init\n - name: \"Install Python 3.10\"\n uses: actions/setup-python@v4\n with:\n python-version: '3.10.8'\n - name: \"Install dependencies\"\n run: |\n sudo DEBIAN_FRONTEND=noninteractive apt-get -qy update\n sudo DEBIAN_FRONTEND=noninteractive apt-get -qy install tox\n - name: \"Spellcheck\"\n run: |\n tox\n env:\n TOXENV: doc-spelling\n - name: \"Build docs\"\n env:\n TOXENV: doc\n run: |\n tox\n\n shell-lint:\n name: Shell Lint\n runs-on: ubuntu-22.04\n steps:\n - name: Checkout\n uses: actions/checkout@v3.0.0\n\n - name: Install ShellCheck\n run: |\n sudo apt-get update\n sudo apt install shellcheck\n\n - name: Run ShellCheck\n run: |\n shellcheck ./tools/ds-identify\n\n check-cla-signers:\n runs-on: ubuntu-22.04\n steps:\n - uses: actions/checkout@v3.0.0\n\n - name: Check CLA signers file\n run: tools/check-cla-signers\n", "logs": [{"step_name": "Check pylint/6_Test.txt", "log": "##[group]Run tox\n\u001b[36;1mtox\u001b[0m\nshell: /usr/bin/sh -ex {0}\nenv:\n TOXENV: pylint\n##[endgroup]\n+ tox\nGLOB sdist-make: /home/runner/work/cloud-init/cloud-init/setup.py\npylint create: /home/runner/work/cloud-init/cloud-init/.tox/pylint\npylint installdeps: pylint===2.13.9, -r/home/runner/work/cloud-init/cloud-init/test-requirements.txt, -r/home/runner/work/cloud-init/cloud-init/integration-requirements.txt\npylint inst: /home/runner/work/cloud-init/cloud-init/.tox/.tmp/package/1/cloud-init-23.4+77.g80f699fe.zip\npylint installed: adal==1.2.7,anyio==4.2.0,appdirs==1.4.4,applicationinsights==0.11.10,argcomplete==3.1.6,astroid==2.11.7,attrs==23.2.0,autopage==0.5.2,azure-cli-core==2.55.0,azure-cli-telemetry==1.1.0,azure-common==1.1.28,azure-core==1.29.6,azure-identity==1.15.0,azure-mgmt-compute==30.4.0,azure-mgmt-core==1.4.0,azure-mgmt-network==25.2.0,azure-mgmt-resource==23.0.1,bcrypt==4.1.2,boto3==1.34.14,botocore==1.34.14,cachetools==5.3.2,certifi==2023.11.17,cffi==1.16.0,charset-normalizer==3.3.2,circuitbreaker==1.4.0,cliff==4.4.0,cloud-init==23.4+77.g80f699fe,cmd2==2.4.3,configobj==5.0.8,coverage==7.4.0,cryptography==41.0.7,debtcollector==2.5.0,decorator==5.1.1,dill==0.3.7,distro==1.9.0,dogpile.cache==1.3.0,exceptiongroup==1.2.0,google-api-core==2.15.0,google-api-python-client==2.112.0,google-auth==2.26.1,google-auth-httplib2==0.2.0,googleapis-common-protos==1.62.0,httplib2==0.22.0,humanfriendly==10.0,ibm-cloud-sdk-core==3.18.2,ibm-platform-services==0.48.1,ibm-vpc==0.20.0,idna==3.6,importlib-metadata==7.0.1,importlib-resources==6.1.1,iniconfig==2.0.0,iso8601==2.1.0,isodate==0.6.1,isort==5.13.2,Jinja2==3.1.2,jmespath==1.0.1,jsonpatch==1.33,jsonpointer==2.4,jsonschema==4.20.0,jsonschema-specifications==2023.12.1,keystoneauth1==5.4.0,knack==0.11.0,lazy-object-proxy==1.10.0,MarkupSafe==2.1.3,mccabe==0.7.0,msal==1.24.0b2,msal-extensions==1.0.0,msgpack==1.0.7,msrest==0.7.1,msrestazure==0.6.4,netaddr==0.10.1,netifaces==0.11.0,oauthlib==3.2.2,oci==2.118.0,openstacksdk==1.4.0,os-service-types==1.7.0,osc-lib==2.9.0,oslo.config==9.2.0,oslo.i18n==6.2.0,oslo.serialization==5.2.0,oslo.utils==6.3.0,packaging==23.2,paramiko==3.4.0,passlib==1.7.4,pbr==6.0.0,pkginfo==1.9.6,pkgutil-resolve-name==1.3.10,platformdirs==4.1.0,pluggy==1.3.0,portalocker==2.8.2,prettytable==3.9.0,protobuf==3.19.6,psutil==5.9.7,pyasn1==0.5.1,pyasn1-modules==0.3.0,pycloudlib==1!5.12.1,pycparser==2.21,pygments==2.17.2,PyJWT==2.8.0,pylint==2.13.9,PyNaCl==1.5.0,pyOpenSSL==23.3.0,pyparsing==2.4.7,pyperclip==1.8.2,pyserial==3.5,pytest==7.4.4,pytest-cov==4.1.0,pytest-mock==3.12.0,python-cinderclient==9.4.0,python-dateutil==2.8.2,python-keystoneclient==5.2.0,python-novaclient==18.4.0,python-openstackclient==6.4.0,pytz==2023.3.post1,PyYAML==6.0.1,qemu.qmp==0.0.3,referencing==0.32.1,requests==2.31.0,requests-oauthlib==1.3.1,requestsexceptions==1.4.0,responses==0.24.1,rfc3986==2.0.0,rpds-py==0.16.2,rsa==4.9,s3transfer==0.10.0,simplejson==3.19.2,six==1.16.0,sniffio==1.3.0,stevedore==5.1.0,tabulate==0.9.0,toml==0.10.0,tomli==2.0.1,typing-extensions==4.9.0,tzdata==2023.4,uritemplate==4.1.1,urllib3==2.1.0,wcwidth==0.2.12,wrapt==1.16.0,zipp==3.17.0\npylint run-test-pre: PYTHONHASHSEED='2276146897'\npylint run-test: commands[0] | /home/runner/work/cloud-init/cloud-init/.tox/pylint/bin/python -m pylint cloudinit/ tests/ tools/ conftest.py setup.py\n************* Module cloudinit.net.dhcp\ncloudinit/net/dhcp.py:575: [W0612(unused-variable), Dhcpcd.dhcp_discovery] Unused variable 'out'\ncloudinit/net/dhcp.py:575: [W0612(unused-variable), Dhcpcd.dhcp_discovery] Unused variable 'err'\n\n------------------------------------\nYour code has been rated at 10.00/10\n\nERROR: InvocationError for command /home/runner/work/cloud-init/cloud-init/.tox/pylint/bin/python -m pylint cloudinit/ tests/ tools/ conftest.py setup.py (exited with code 4)\n___________________________________ summary ____________________________________\nERROR: pylint: commands failed\n##[error]Process completed with exit code 1.\n"}, {"step_name": "Check black/6_Test.txt", "log": "##[group]Run tox\n\u001b[36;1mtox\u001b[0m\nshell: /usr/bin/sh -ex {0}\nenv:\n TOXENV: black\n##[endgroup]\n+ tox\nGLOB sdist-make: /home/runner/work/cloud-init/cloud-init/setup.py\nblack create: /home/runner/work/cloud-init/cloud-init/.tox/black\nblack installdeps: black===22.3.0\nblack inst: /home/runner/work/cloud-init/cloud-init/.tox/.tmp/package/1/cloud-init-23.4+77.g80f699fe.zip\nblack installed: attrs==23.2.0,black==22.3.0,certifi==2023.11.17,charset-normalizer==3.3.2,click==8.1.7,cloud-init==23.4+77.g80f699fe,configobj==5.0.8,idna==3.6,importlib-resources==6.1.1,Jinja2==3.1.2,jsonpatch==1.33,jsonpointer==2.4,jsonschema==4.20.0,jsonschema-specifications==2023.12.1,MarkupSafe==2.1.3,mypy-extensions==1.0.0,netifaces==0.11.0,oauthlib==3.2.2,pathspec==0.12.1,pkgutil-resolve-name==1.3.10,platformdirs==4.1.0,pyserial==3.5,PyYAML==6.0.1,referencing==0.32.1,requests==2.31.0,rpds-py==0.16.2,six==1.16.0,tomli==2.0.1,typing-extensions==4.9.0,urllib3==2.1.0,zipp==3.17.0\nblack run-test-pre: PYTHONHASHSEED='3554362748'\nblack run-test: commands[0] | /home/runner/work/cloud-init/cloud-init/.tox/black/bin/python -m black . --check\nwould reformat tests/unittests/net/test_dhcp.py\n\nOh no! \ud83d\udca5 \ud83d\udc94 \ud83d\udca5\n1 file would be reformatted, 549 files would be left unchanged.\nERROR: InvocationError for command /home/runner/work/cloud-init/cloud-init/.tox/black/bin/python -m black . --check (exited with code 1)\n___________________________________ summary ____________________________________\nERROR: black: commands failed\n##[error]Process completed with exit code 1.\n"}], "diff": "diff --git a/cloudinit/net/dhcp.py b/cloudinit/net/dhcp.py\nindex 1b8caee4f..6a4e5a3fa 100644\n--- a/cloudinit/net/dhcp.py\n+++ b/cloudinit/net/dhcp.py\n@@ -175,6 +175,11 @@ class DhcpClient(abc.ABC):\n client_name = \"\"\n max_wait = 5\n \n+ def __init__(self):\n+ self.dhcp_client_path = subp.which(self.client_name)\n+ if not self.dhcp_client_path:\n+ raise NoDHCPLeaseMissingDhclientError()\n+\n @classmethod\n def kill_dhcp_client(cls):\n subp.subp([\"pkill\", cls.client_name], rcs=[0, 1])\n@@ -200,14 +205,6 @@ class DhcpClient(abc.ABC):\n class IscDhclient(DhcpClient):\n client_name = \"dhclient\"\n \n- def __init__(self):\n- self.dhclient_path = subp.which(\"dhclient\")\n- if not self.dhclient_path:\n- LOG.debug(\n- \"Skip dhclient configuration: No dhclient command found.\"\n- )\n- raise NoDHCPLeaseMissingDhclientError()\n-\n @staticmethod\n def parse_dhcp_lease_file(lease_file: str) -> List[Dict[str, Any]]:\n \"\"\"Parse the given dhcp lease file returning all leases as dicts.\n@@ -298,7 +295,7 @@ class IscDhclient(DhcpClient):\n try:\n out, err = subp.subp(\n distro.build_dhclient_cmd(\n- self.dhclient_path,\n+ self.dhcp_client_path,\n lease_file,\n pid_file,\n interface,\n@@ -536,14 +533,6 @@ class IscDhclient(DhcpClient):\n class Dhcpcd:\n client_name = \"dhcpcd\"\n \n- def __init__(self):\n- self.dhclient_path = subp.which(\"dhcpcd\")\n- if not self.dhclient_path:\n- LOG.debug(\n- \"Skip dhclient configuration: No dhclient command found.\"\n- )\n- raise NoDHCPLeaseMissingDhclientError()\n-\n def dhcp_discovery(\n self,\n interface,\n@@ -572,9 +561,9 @@ class Dhcpcd:\n # /lib/dhcpcd/dhcpcd-hooks/ and pass each of those with the --nohook\n # argument to dhcpcd\n try:\n- out, err = subp.subp(\n+ subp.subp(\n [\n- \"dhcpcd\",\n+ self.client_name,\n \"--oneshot\", # get lease then exit\n \"--nobackground\", # don't fork\n \"--ipv4only\", # only attempt configuring ipv4\n@@ -584,6 +573,7 @@ class Dhcpcd:\n interface,\n ]\n )\n+ return self.parse_dhcp_lease_file(interface)\n except subp.ProcessExecutionError as error:\n LOG.debug(\n \"dhclient exited with code: %s stderr: %r stdout: %r\",\n@@ -592,7 +582,6 @@ class Dhcpcd:\n error.stdout,\n )\n raise NoDHCPLeaseError from error\n- return self.parse_dhcp_lease_file(interface)\n \n @staticmethod\n def parse_dhcpcd_lease(lease_dump: str, interface: str) -> List[dict]:\n@@ -656,7 +645,7 @@ class Dhcpcd:\n \n except subp.ProcessExecutionError as error:\n LOG.debug(\n- \"dhclient exited with code: %s stderr: %r stdout: %r\",\n+ \"dhcpcd exited with code: %s stderr: %r stdout: %r\",\n error.exit_code,\n error.stderr,\n error.stdout,\n@@ -667,12 +656,6 @@ class Dhcpcd:\n class Udhcpc(DhcpClient):\n client_name = \"udhcpc\"\n \n- def __init__(self):\n- self.udhcpc_path = subp.which(\"udhcpc\")\n- if not self.udhcpc_path:\n- LOG.debug(\"Skip udhcpc configuration: No udhcpc command found.\")\n- raise NoDHCPLeaseMissingUdhcpcError()\n-\n def dhcp_discovery(\n self,\n interface,\n@@ -702,7 +685,7 @@ class Udhcpc(DhcpClient):\n util.write_file(udhcpc_script, UDHCPC_SCRIPT, 0o755)\n \n cmd = [\n- self.udhcpc_path,\n+ self.dhcp_client_path,\n \"-O\",\n \"staticroutes\",\n \"-i\",\ndiff --git a/tests/unittests/net/test_dhcp.py b/tests/unittests/net/test_dhcp.py\nindex 2841a7244..fa8308068 100644\n--- a/tests/unittests/net/test_dhcp.py\n+++ b/tests/unittests/net/test_dhcp.py\n@@ -8,6 +8,7 @@ import pytest\n import responses\n \n from cloudinit.net.dhcp import (\n+ Dhcpcd,\n InvalidDHCPLeaseFileError,\n IscDhclient,\n NoDHCPLeaseError,\n@@ -438,7 +439,7 @@ class TestDHCPDiscoveryClean(CiTestCase):\n subp.ProcessExecutionError(exit_code=-5),\n ]\n \n- m_which.side_effect = [False, True]\n+ m_which.side_effect = [False, False, False]\n with pytest.raises(NoDHCPLeaseError):\n maybe_perform_dhcp_discovery(MockDistro())\n \n@@ -446,10 +447,6 @@ class TestDHCPDiscoveryClean(CiTestCase):\n \"DHCP client not found: dhclient\",\n self.logs.getvalue(),\n )\n- self.assertIn(\n- \"DHCP client not found: dhcpcd\",\n- self.logs.getvalue(),\n- )\n \n @mock.patch(\"cloudinit.net.dhcp.find_fallback_nic\", return_value=None)\n def test_provided_nic_does_not_exist(self, m_fallback_nic):\n@@ -473,7 +470,7 @@ class TestDHCPDiscoveryClean(CiTestCase):\n maybe_perform_dhcp_discovery(MockDistro())\n \n self.assertIn(\n- \"Skip dhclient configuration: No dhclient command found.\",\n+ \"DHCP client not found: dhclient\",\n self.logs.getvalue(),\n )\n \n@@ -975,24 +972,6 @@ class TestUDHCPCDiscoveryClean(CiTestCase):\n with_logs = True\n maxDiff = None\n \n- @mock.patch(\"cloudinit.net.dhcp.subp.which\")\n- @mock.patch(\"cloudinit.net.dhcp.find_fallback_nic\")\n- def test_absent_udhcpc_command(self, m_fallback, m_which):\n- \"\"\"When dhclient doesn't exist in the OS, log the issue and no-op.\"\"\"\n- m_fallback.return_value = \"eth9\"\n- m_which.return_value = None # udhcpc isn't found\n-\n- distro = MockDistro()\n- distro.dhcp_client_priority = [Udhcpc]\n-\n- with pytest.raises(NoDHCPLeaseMissingDhclientError):\n- maybe_perform_dhcp_discovery(distro)\n-\n- self.assertIn(\n- \"Skip udhcpc configuration: No udhcpc command found.\",\n- self.logs.getvalue(),\n- )\n-\n @mock.patch(\"cloudinit.net.dhcp.is_ib_interface\", return_value=False)\n @mock.patch(\"cloudinit.net.dhcp.subp.which\", return_value=\"/sbin/udhcpc\")\n @mock.patch(\"cloudinit.net.dhcp.os.remove\")\n@@ -1135,3 +1114,30 @@ class TestUDHCPCDiscoveryClean(CiTestCase):\n ),\n ]\n )\n+\n+\n+class TestDhcpcd:\n+ def test_parse_lease(self):\n+ lease = dedent(\n+ \"\"\"\n+ broadcast_address='192.168.15.255'\n+ dhcp_lease_time='3600'\n+ dhcp_message_type='5'\n+ dhcp_server_identifier='192.168.0.1'\n+ domain_name='us-east-2.compute.internal'\n+ domain_name_servers='192.168.0.2'\n+ host_name='ip-192-168-0-212'\n+ interface_mtu='9001'\n+ ip_address='192.168.0.212'\n+ network_number='192.168.0.0'\n+ routers='192.168.0.1'\n+ subnet_cidr='20'\n+ subnet_mask='255.255.240.0'\n+ \"\"\"\n+ )\n+ parsed_lease = Dhcpcd.parse_dhcpcd_lease(lease, \"eth0\")[0]\n+ assert \"eth0\" == parsed_lease[\"interface\"]\n+ assert \"192.168.15.255\" == parsed_lease[\"broadcast-address\"]\n+ assert \"192.168.0.212\" == parsed_lease[\"fixed-address\"]\n+ assert \"255.255.240.0\" == parsed_lease[\"subnet-mask\"]\n+ assert \"192.168.0.1\" == parsed_lease[\"routers\"]\n", "difficulty": 0, "changed_files": ["cloudinit/net/dhcp.py", "tests/unittests/net/test_dhcp.py"], "commit_link": "https://github.com/canonical/cloud-init/tree/385c14d0ae500918cff5565ea836884bfaa2bfa5"}