From 6d61b63f34bc8388b5d51090b9788410082cfa76 Mon Sep 17 00:00:00 2001 From: Brett Holman Date: Tue, 20 Feb 2024 02:07:50 -0700 Subject: [PATCH] feat(dhcp): Make dhcpcd the default dhcp client (#4912) isc-dhcp-client is no longer supported by upstream BREAKING CHANGE: dhcpcd has been promoted to the default dhcp client. Previous behavior can be configured in cloud.cfg via the dhcp_client_priority key. --- cloudinit/net/dhcp.py | 2 +- config/cloud.cfg.tmpl | 2 +- tests/unittests/distros/test__init__.py | 4 ++-- tests/unittests/net/test_dhcp.py | 4 ++-- tests/unittests/sources/test_cloudstack.py | 22 ++++++++++++++-------- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/cloudinit/net/dhcp.py b/cloudinit/net/dhcp.py index 1b3f1f961be..0e81b925e36 100644 --- a/cloudinit/net/dhcp.py +++ b/cloudinit/net/dhcp.py @@ -967,4 +967,4 @@ def parse_static_routes(routes: str) -> List[Tuple[str, str]]: return [] -ALL_DHCP_CLIENTS = [IscDhclient, Dhcpcd, Udhcpc] +ALL_DHCP_CLIENTS = [Dhcpcd, IscDhclient, Udhcpc] diff --git a/config/cloud.cfg.tmpl b/config/cloud.cfg.tmpl index 7d537cfb867..e21770326d0 100644 --- a/config/cloud.cfg.tmpl +++ b/config/cloud.cfg.tmpl @@ -301,7 +301,7 @@ system_info: {% elif variant in ["ubuntu", "unknown"] %} {# SRU_BLOCKER: do not ship network renderers on Xenial, Bionic or Eoan #} network: - dhcp_client_priority: [dhclient, dhcpcd, udhcpc] + dhcp_client_priority: [dhcpcd, dhclient, udhcpc] renderers: ['netplan', 'eni', 'sysconfig'] activators: ['netplan', 'eni', 'network-manager', 'networkd'] {% elif is_rhel %} diff --git a/tests/unittests/distros/test__init__.py b/tests/unittests/distros/test__init__.py index 028bcbfdddd..49401086afa 100644 --- a/tests/unittests/distros/test__init__.py +++ b/tests/unittests/distros/test__init__.py @@ -543,10 +543,10 @@ def test_get_tmp_exec_path( id="first_client_is_found_from_config_udhcpc", ), pytest.param( - IscDhclient, + Dhcpcd, {"network": {"dhcp_client_priority": []}}, None, - id="first_client_is_found_no_config_dhclient", + id="first_client_is_found_no_config_dhcpcd", ), pytest.param( Dhcpcd, diff --git a/tests/unittests/net/test_dhcp.py b/tests/unittests/net/test_dhcp.py index 15bca4de2dd..325b3983323 100644 --- a/tests/unittests/net/test_dhcp.py +++ b/tests/unittests/net/test_dhcp.py @@ -381,7 +381,7 @@ class TestDHCPDiscoveryClean(CiTestCase): @mock.patch("cloudinit.net.dhcp.os.remove") @mock.patch("cloudinit.net.dhcp.subp.subp") @mock.patch("cloudinit.net.dhcp.subp.which") - def test_dhclient_exits_with_error( + def test_dhcpcd_exits_with_error( self, m_which, m_subp, m_remove, m_fallback ): """Log and do nothing when nic is absent and no fallback is found.""" @@ -394,7 +394,7 @@ def test_dhclient_exits_with_error( maybe_perform_dhcp_discovery(Distro("fake but not", {}, None)) self.assertIn( - "DHCP client selected: dhclient", + "DHCP client selected: dhcpcd", self.logs.getvalue(), ) diff --git a/tests/unittests/sources/test_cloudstack.py b/tests/unittests/sources/test_cloudstack.py index 73cbb59786e..a64d80f3721 100644 --- a/tests/unittests/sources/test_cloudstack.py +++ b/tests/unittests/sources/test_cloudstack.py @@ -268,17 +268,23 @@ def test_get_hostname_fqdn_fallback(self): ) ) + lease = { + "interface": "eth0", + "fixed-address": "192.168.0.1", + "subnet-mask": "255.255.255.0", + "routers": "192.168.0.1", + "renew": "4 2017/07/27 18:02:30", + "expire": "5 2017/07/28 07:08:15", + } self.patches.enter_context( mock.patch( DHCP_MOD_PATH + ".IscDhclient.get_newest_lease", - return_value={ - "interface": "eth0", - "fixed-address": "192.168.0.1", - "subnet-mask": "255.255.255.0", - "routers": "192.168.0.1", - "renew": "4 2017/07/27 18:02:30", - "expire": "5 2017/07/28 07:08:15", - }, + return_value=lease, + ) + ) + self.patches.enter_context( + mock.patch( + DHCP_MOD_PATH + ".Dhcpcd.get_newest_lease", return_value=lease ) )