@@ -875,23 +875,37 @@ def _process_manager_constructor_call(self, ns=FAKE_NETWORK_DHCP_NS):
875875 def _enable_dhcp_helper (self , network , enable_isolated_metadata = False ,
876876 is_isolated_network = False , is_ovn_network = False ):
877877 self .dhcp ._process_monitor = mock .Mock ()
878+ # The disable() call
879+ gmppm_expected_calls = [mock .call (FAKE_NETWORK_UUID , cfg .CONF ,
880+ ns_name = FAKE_NETWORK_DHCP_NS )]
878881 if enable_isolated_metadata :
879882 cfg .CONF .set_override ('enable_isolated_metadata' , True )
883+ if is_isolated_network :
884+ # The enable() call
885+ gmppm_expected_calls .append (
886+ mock .call (FAKE_NETWORK_UUID , cfg .CONF ,
887+ ns_name = FAKE_NETWORK_DHCP_NS ,
888+ callback = mock .ANY ))
880889 self .plugin .get_network_info .return_value = network
881- self .dhcp .enable_dhcp_helper (network .id )
890+ process_instance = mock .Mock (active = False )
891+ with mock .patch .object (metadata_driver .MetadataDriver ,
892+ '_get_metadata_proxy_process_manager' ,
893+ return_value = process_instance ) as gmppm :
894+ self .dhcp .enable_dhcp_helper (network .id )
895+ gmppm .assert_has_calls (gmppm_expected_calls )
882896 self .plugin .assert_has_calls ([
883897 mock .call .get_network_info (network .id )])
884898 self .call_driver .assert_called_once_with ('enable' , network )
885899 self .cache .assert_has_calls ([mock .call .put (network )])
886900 if (is_isolated_network and enable_isolated_metadata and not
887901 is_ovn_network ):
888- self .external_process .assert_has_calls ([
889- self ._process_manager_constructor_call (),
890- mock .call ().enable ()], any_order = True )
902+ process_instance .assert_has_calls ([
903+ mock .call .disable (sig = str (int (signal .SIGTERM ))),
904+ mock .call .get_pid_file_name (),
905+ mock .call .enable ()])
891906 else :
892- self .external_process .assert_has_calls ([
893- self ._process_manager_constructor_call (),
894- mock .call ().disable (sig = str (int (signal .SIGTERM )))])
907+ process_instance .assert_has_calls ([
908+ mock .call .disable (sig = str (int (signal .SIGTERM )))])
895909
896910 def test_enable_dhcp_helper_enable_metadata_isolated_network (self ):
897911 self ._enable_dhcp_helper (isolated_network ,
@@ -1065,11 +1079,16 @@ def test_disable_dhcp_helper_driver_failure(self):
10651079
10661080 def test_enable_isolated_metadata_proxy (self ):
10671081 self .dhcp ._process_monitor = mock .Mock ()
1068- self .dhcp .enable_isolated_metadata_proxy (fake_network )
1069- self .external_process .assert_has_calls ([
1070- self ._process_manager_constructor_call (),
1071- mock .call ().enable ()
1072- ], any_order = True )
1082+ process_instance = mock .Mock (active = False )
1083+ with mock .patch .object (metadata_driver .MetadataDriver ,
1084+ '_get_metadata_proxy_process_manager' ,
1085+ return_value = process_instance ) as gmppm :
1086+ self .dhcp .enable_isolated_metadata_proxy (fake_network )
1087+ gmppm .assert_called_with (FAKE_NETWORK_UUID ,
1088+ cfg .CONF ,
1089+ ns_name = FAKE_NETWORK_DHCP_NS ,
1090+ callback = mock .ANY )
1091+ process_instance .enable .assert_called_once ()
10731092
10741093 def test_disable_isolated_metadata_proxy (self ):
10751094 method_path = ('neutron.agent.metadata.driver.MetadataDriver'
0 commit comments