DhcpLocalProcess._enable should not call DhcpLocalProcess.restart

"DhcpLocalProcess._enable", instead of calling
"DhcpLocalProcess.restart", should only stop the server and continue
the method. This will avoid getting into a second active wait context.

Change-Id: Id321430c344723363786ab48584b1b48ba69f679
Closes-Bug: #1854940
This commit is contained in:
Rodolfo Alonso Hernandez 2019-12-03 14:56:32 +00:00
parent 0c348947ec
commit f758bc9980
2 changed files with 8 additions and 9 deletions

View File

@ -261,8 +261,9 @@ class DhcpLocalProcess(DhcpBase):
def _enable(self):
try:
if self.active:
self.restart()
elif self._enable_dhcp():
self.disable(retain_port=True, block=True)
if self._enable_dhcp():
fileutils.ensure_tree(self.network_conf_dir, mode=0o755)
interface_name = self.device_manager.setup(self.network)
self.interface_name = interface_name

View File

@ -1019,9 +1019,6 @@ class LocalChild(dhcp.DhcpLocalProcess):
def reload_allocations(self):
self.called.append('reload')
def restart(self):
self.called.append('restart')
def spawn_process(self):
self.called.append('spawn')
@ -1120,12 +1117,13 @@ class TestDhcpLocalProcess(TestBase):
def test_enable_already_active(self):
with mock.patch.object(LocalChild, 'active') as patched:
patched.__get__ = mock.Mock(return_value=True)
patched.__get__ = mock.Mock(side_effect=[True, False])
lp = LocalChild(self.conf, FakeV4Network())
lp.enable()
with mock.patch.object(ip_lib, 'delete_network_namespace'):
lp.enable()
self.assertEqual(lp.called, ['restart'])
self.assertFalse(self.mock_mgr.return_value.setup.called)
self.assertEqual(lp.called, ['spawn'])
self.assertTrue(self.mock_mgr.return_value.setup.called)
@mock.patch.object(fileutils, 'ensure_tree')
def test_enable(self, ensure_dir):