@@ -807,23 +807,37 @@ def _process_manager_constructor_call(self, ns=FAKE_NETWORK_DHCP_NS):
807807 def _enable_dhcp_helper (self , network , enable_isolated_metadata = False ,
808808 is_isolated_network = False , is_ovn_network = False ):
809809 self .dhcp ._process_monitor = mock .Mock ()
810+ # The disable() call
811+ gmppm_expected_calls = [mock .call (FAKE_NETWORK_UUID , cfg .CONF ,
812+ ns_name = FAKE_NETWORK_DHCP_NS )]
810813 if enable_isolated_metadata :
811814 cfg .CONF .set_override ('enable_isolated_metadata' , True )
815+ if is_isolated_network :
816+ # The enable() call
817+ gmppm_expected_calls .append (
818+ mock .call (FAKE_NETWORK_UUID , cfg .CONF ,
819+ ns_name = FAKE_NETWORK_DHCP_NS ,
820+ callback = mock .ANY ))
812821 self .plugin .get_network_info .return_value = network
813- self .dhcp .enable_dhcp_helper (network .id )
822+ process_instance = mock .Mock (active = False )
823+ with mock .patch .object (metadata_driver .MetadataDriver ,
824+ '_get_metadata_proxy_process_manager' ,
825+ return_value = process_instance ) as gmppm :
826+ self .dhcp .enable_dhcp_helper (network .id )
827+ gmppm .assert_has_calls (gmppm_expected_calls )
814828 self .plugin .assert_has_calls ([
815829 mock .call .get_network_info (network .id )])
816830 self .call_driver .assert_called_once_with ('enable' , network )
817831 self .cache .assert_has_calls ([mock .call .put (network )])
818832 if (is_isolated_network and enable_isolated_metadata and not
819833 is_ovn_network ):
820- self .external_process .assert_has_calls ([
821- self ._process_manager_constructor_call (),
822- mock .call ().enable ()], any_order = True )
834+ process_instance .assert_has_calls ([
835+ mock .call .disable (sig = str (int (signal .SIGTERM ))),
836+ mock .call .get_pid_file_name (),
837+ mock .call .enable ()])
823838 else :
824- self .external_process .assert_has_calls ([
825- self ._process_manager_constructor_call (),
826- mock .call ().disable (sig = str (int (signal .SIGTERM )))])
839+ process_instance .assert_has_calls ([
840+ mock .call .disable (sig = str (int (signal .SIGTERM )))])
827841
828842 def test_enable_dhcp_helper_enable_metadata_isolated_network (self ):
829843 self ._enable_dhcp_helper (isolated_network ,
@@ -997,11 +1011,16 @@ def test_disable_dhcp_helper_driver_failure(self):
9971011
9981012 def test_enable_isolated_metadata_proxy (self ):
9991013 self .dhcp ._process_monitor = mock .Mock ()
1000- self .dhcp .enable_isolated_metadata_proxy (fake_network )
1001- self .external_process .assert_has_calls ([
1002- self ._process_manager_constructor_call (),
1003- mock .call ().enable ()
1004- ], any_order = True )
1014+ process_instance = mock .Mock (active = False )
1015+ with mock .patch .object (metadata_driver .MetadataDriver ,
1016+ '_get_metadata_proxy_process_manager' ,
1017+ return_value = process_instance ) as gmppm :
1018+ self .dhcp .enable_isolated_metadata_proxy (fake_network )
1019+ gmppm .assert_called_with (FAKE_NETWORK_UUID ,
1020+ cfg .CONF ,
1021+ ns_name = FAKE_NETWORK_DHCP_NS ,
1022+ callback = mock .ANY )
1023+ process_instance .enable .assert_called_once ()
10051024
10061025 def test_disable_isolated_metadata_proxy (self ):
10071026 method_path = ('neutron.agent.metadata.driver.MetadataDriver'
0 commit comments