diff options
author | Brett Holman <brett.holman@canonical.com> | 2023-04-19 16:12:55 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-19 16:12:55 -0600 |
commit | 5942f4023e2581a43f31d547995095ca49954353 (patch) | |
tree | 510009a412671c4adb041c05fc803db1ea4e8c22 /tests/unittests/sources/test_cloudstack.py | |
parent | 9e4cb4f06b2e362889bcbda77ef6fad52afed52b (diff) | |
download | cloud-init-git-5942f4023e2581a43f31d547995095ca49954353.tar.gz |
[1/2] DHCP: Refactor dhcp client code (#2122)
Move isc-dhclient code to dhcp.py
In support of the upcoming deprecation of
isc-dhcp-client, this code refactors current
dhcp code into classes in dhcp.py. The
primary user-visible change should be the
addition of the following log:
dhcp.py[DEBUG]: DHCP client selected: dhclient
This code lays groundwork to enable
alternate implementations to live side by
side in the codebase to be selected with
distro-defined priority fallback. Note that
maybe_perform_dhcp_discovery() now selects
which dhcp client to call, and then runs the
corresponding client's dhcp_discovery()
method. Currently only class IscDhclient is
implemented, however a yet-to-be-implemented
class Dhcpcd exists to test fallback behavior
and this will be implemented in part two of
this series.
Part of this refactor includes shifting
dhclient service management from hardcoded
calls to the distro-defined manage_service()
method in the *BSDs. Future work is required
in this area to support multiple clients via
select_dhcp_client().
Diffstat (limited to 'tests/unittests/sources/test_cloudstack.py')
-rw-r--r-- | tests/unittests/sources/test_cloudstack.py | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/tests/unittests/sources/test_cloudstack.py b/tests/unittests/sources/test_cloudstack.py index b37400d3..463a9c7a 100644 --- a/tests/unittests/sources/test_cloudstack.py +++ b/tests/unittests/sources/test_cloudstack.py @@ -4,10 +4,8 @@ import os import time from cloudinit import helpers, util -from cloudinit.sources.DataSourceCloudStack import ( - DataSourceCloudStack, - get_latest_lease, -) +from cloudinit.net.dhcp import IscDhclient +from cloudinit.sources.DataSourceCloudStack import DataSourceCloudStack from tests.unittests.helpers import CiTestCase, ExitStack, mock MOD_PATH = "cloudinit.sources.DataSourceCloudStack" @@ -25,7 +23,10 @@ class TestCloudStackPasswordFetching(CiTestCase): default_gw = "192.201.20.0" get_latest_lease = mock.MagicMock(return_value=None) self.patches.enter_context( - mock.patch(mod_name + ".get_latest_lease", get_latest_lease) + mock.patch( + mod_name + ".dhcp.IscDhclient.get_latest_lease", + get_latest_lease, + ) ) get_default_gw = mock.MagicMock(return_value=default_gw) @@ -151,7 +152,8 @@ class TestGetLatestLease(CiTestCase): lease_d = self.tmp_dir() self._populate_dir_list(lease_d, files) self.assertEqual( - self.tmp_path(expected, lease_d), get_latest_lease(lease_d) + self.tmp_path(expected, lease_d), + IscDhclient.get_latest_lease(lease_d), ) def test_skips_dhcpv6_files(self): @@ -198,13 +200,10 @@ class TestGetLatestLease(CiTestCase): valid_2_path = self.tmp_path(valid_2, lease_d) self._populate_dir_list(lease_d, [valid_1, valid_2]) - self.assertEqual(valid_2_path, get_latest_lease(lease_d)) + self.assertEqual(valid_2_path, IscDhclient.get_latest_lease(lease_d)) # now update mtime on valid_2 to be older than valid_1 and re-check. mtime = int(os.path.getmtime(valid_1_path)) - 1 os.utime(valid_2_path, (mtime, mtime)) - self.assertEqual(valid_1_path, get_latest_lease(lease_d)) - - -# vi: ts=4 expandtab + self.assertEqual(valid_1_path, IscDhclient.get_latest_lease(lease_d)) |