@@ -2000,6 +2000,40 @@ def test_get_dhcp_hosts_in_use(self, mock_get_adapter_addresses):
20002000 mock .sentinel .mac_address ,
20012001 mock .sentinel .dhcp_server )], response )
20022002
2003+ def test_fix_network_adapter_dhcp (self ):
2004+ self ._test_fix_network_adapter_dhcp (True )
2005+
2006+ def test_fix_network_adapter_dhcp_no_network_adapter (self ):
2007+ self ._test_fix_network_adapter_dhcp (False )
2008+
2009+ def _test_fix_network_adapter_dhcp (self , no_net_interface_found ):
2010+ mock_interface_name = "eth12"
2011+ mock_enable_dhcp = True
2012+ mock_address_family = self .windows_utils .AF_INET
2013+
2014+ conn = self ._wmi_mock .WMI .return_value
2015+ existing_net_interface = mock .Mock ()
2016+ existing_net_interface .Dhcp = 0
2017+
2018+ if not no_net_interface_found :
2019+ conn .MSFT_NetIPInterface .return_value = [existing_net_interface ]
2020+
2021+ if no_net_interface_found :
2022+ with self .assertRaises (exception .ItemNotFoundException ):
2023+ self ._winutils ._fix_network_adapter_dhcp (
2024+ mock_interface_name , mock_enable_dhcp ,
2025+ mock_address_family )
2026+ else :
2027+ self ._winutils ._fix_network_adapter_dhcp (
2028+ mock_interface_name , mock_enable_dhcp ,
2029+ mock_address_family )
2030+
2031+ conn .MSFT_NetIPInterface .assert_called_once_with (
2032+ InterfaceAlias = mock_interface_name ,
2033+ AddressFamily = mock_address_family )
2034+ self .assertEqual (existing_net_interface .Dhcp , 1 )
2035+ existing_net_interface .put .assert_called_once ()
2036+
20032037 @mock .patch ('cloudbaseinit.osutils.windows.WindowsUtils'
20042038 '.check_sysnative_dir_exists' )
20052039 @mock .patch ('cloudbaseinit.osutils.windows.WindowsUtils'
0 commit comments