Adds mac address as return value in get_dhcp_hosts_in_use

This commit is contained in:
Alessandro Pilotti 2014-06-11 20:38:12 +03:00
parent b512170ace
commit d0f0b9c803
4 changed files with 7 additions and 4 deletions

View File

@ -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):

View File

@ -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:

View File

@ -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')

View File

@ -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'