diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index b409d5b9c50..3ba26e9e02d 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -138,12 +138,12 @@ class DhcpBase(object): """Enables DHCP for this network.""" @abc.abstractmethod - def disable(self, retain_port=False): + def disable(self, retain_port=False, block=False): """Disable dhcp for this network.""" def restart(self): """Restart the dhcp service for the network.""" - self.disable(retain_port=True) + self.disable(retain_port=True, block=True) self.enable() @abc.abstractproperty @@ -231,10 +231,13 @@ class DhcpLocalProcess(DhcpBase): pid_file=self.get_conf_file_name('pid'), run_as_root=True) - def disable(self, retain_port=False): + def disable(self, retain_port=False, block=False): """Disable DHCP for this network by killing the local process.""" self.process_monitor.unregister(self.network.id, DNSMASQ_SERVICE_NAME) - self._get_process_manager().disable() + pm = self._get_process_manager() + pm.disable() + if block: + common_utils.wait_until_true(lambda: not pm.active) if not retain_port: self._destroy_namespace_and_port() self._remove_config_files() diff --git a/neutron/tests/unit/agent/linux/test_dhcp.py b/neutron/tests/unit/agent/linux/test_dhcp.py index e616be6eee5..c4140e2855b 100644 --- a/neutron/tests/unit/agent/linux/test_dhcp.py +++ b/neutron/tests/unit/agent/linux/test_dhcp.py @@ -1012,8 +1012,8 @@ class TestDhcpBase(TestBase): def enable(self): self.called.append('enable') - def disable(self, retain_port=False): - self.called.append('disable %s' % retain_port) + def disable(self, retain_port=False, block=False): + self.called.append('disable %s %s' % (retain_port, block)) def reload_allocations(self): pass @@ -1024,7 +1024,7 @@ class TestDhcpBase(TestBase): c = SubClass() c.restart() - self.assertEqual(c.called, ['disable True', 'enable']) + self.assertEqual(c.called, ['disable True True', 'enable']) class TestDhcpLocalProcess(TestBase):