diff --git a/cloudbaseinit/osutils/windows.py b/cloudbaseinit/osutils/windows.py index 060d0b2e..07754786 100644 --- a/cloudbaseinit/osutils/windows.py +++ b/cloudbaseinit/osutils/windows.py @@ -469,7 +469,8 @@ class WindowsUtils(base.BaseOSUtils): for net_cfg in conn.Win32_NetworkAdapterConfiguration( DHCPEnabled=True): if net_cfg.DHCPServer: - dhcp_hosts.append(str(net_cfg.DHCPServer)) + dhcp_hosts.append((str(net_cfg.MACAddress), + str(net_cfg.DHCPServer))) return dhcp_hosts def set_ntp_client_config(self, ntp_host): diff --git a/cloudbaseinit/plugins/windows/ntpclient.py b/cloudbaseinit/plugins/windows/ntpclient.py index 1fb8ca62..813eaefa 100644 --- a/cloudbaseinit/plugins/windows/ntpclient.py +++ b/cloudbaseinit/plugins/windows/ntpclient.py @@ -67,7 +67,7 @@ class NTPClientPlugin(base.BasePlugin): ntp_option_data = None - for dhcp_host in dhcp_hosts: + for (mac_address, dhcp_host) in dhcp_hosts: options_data = dhcp.get_dhcp_options(dhcp_host, [dhcp.OPTION_NTP_SERVERS]) if options_data: diff --git a/cloudbaseinit/tests/osutils/test_windows.py b/cloudbaseinit/tests/osutils/test_windows.py index bbcccdf0..b5f132d1 100644 --- a/cloudbaseinit/tests/osutils/test_windows.py +++ b/cloudbaseinit/tests/osutils/test_windows.py @@ -1195,6 +1195,7 @@ class WindowsUtilsTest(unittest.TestCase): @mock.patch('wmi.WMI') def test_get_dhcp_hosts_in_use(self, mock_WMI): mock_net_cfg = mock.MagicMock() + mock_net_cfg.MACAddress = 'fake mac address' mock_net_cfg.DHCPServer = 'fake dhcp server' mock_WMI().Win32_NetworkAdapterConfiguration.return_value = [ mock_net_cfg] @@ -1202,7 +1203,7 @@ class WindowsUtilsTest(unittest.TestCase): mock_WMI.assert_called_with(moniker='//./root/cimv2') mock_WMI().Win32_NetworkAdapterConfiguration.assert_called_with( DHCPEnabled=True) - self.assertEqual(response, ['fake dhcp server']) + self.assertEqual(response, [('fake mac address', 'fake dhcp server')]) @mock.patch('cloudbaseinit.osutils.windows.WindowsUtils' '.check_sysnative_dir_exists') diff --git a/cloudbaseinit/tests/plugins/windows/test_ntpclient.py b/cloudbaseinit/tests/plugins/windows/test_ntpclient.py index cdb31e10..72f8ce40 100644 --- a/cloudbaseinit/tests/plugins/windows/test_ntpclient.py +++ b/cloudbaseinit/tests/plugins/windows/test_ntpclient.py @@ -84,7 +84,8 @@ class NTPClientPluginTests(unittest.TestCase): mock_options_data = mock.MagicMock() mock_get_os_utils.return_value = mock_osutils - mock_osutils.get_dhcp_hosts_in_use.return_value = ['fake dhcp host'] + mock_osutils.get_dhcp_hosts_in_use.return_value = [('fake mac address', + 'fake dhcp host')] mock_get_dhcp_options.return_value = mock_options_data mock_options_data.get.return_value = ntp_data mock_inet_ntoa.return_value = 'fake host'