Skip to content

Commit fd0eabc

Browse files
committed
dhcp: fix usage of helper function to retrieve process name
Usage of the helper function which retrieves the name of the process based on the usage of the segments was missing for unregister which leads an issue when disabling dhcp agent for a network. Closes-Bug: #2051690 Signed-off-by: Sahid Orentino Ferdjaoui <[email protected]> Change-Id: Ic6e999214210383f17c29982bf5673eea1bb55c0 (cherry picked from commit b37c0f4) (cherry picked from commit 0b5ffd1)
1 parent ce640c8 commit fd0eabc

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

neutron/agent/linux/dhcp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ def _get_process_manager(self, cmd_callback=None):
357357

358358
def disable(self, retain_port=False, block=False, **kwargs):
359359
"""Disable DHCP for this network by killing the local process."""
360-
self.process_monitor.unregister(self.network.id, DNSMASQ_SERVICE_NAME)
361360
pm = self._get_process_manager()
361+
self.process_monitor.unregister(pm.uuid, DNSMASQ_SERVICE_NAME)
362362
pm.disable(sig=str(int(signal.SIGTERM)))
363363
if block:
364364
try:
@@ -602,7 +602,7 @@ def _spawn_or_reload_process(self, reload_with_HUP):
602602

603603
pm.enable(reload_cfg=reload_with_HUP, ensure_active=True)
604604

605-
self.process_monitor.register(uuid=self.get_process_uuid(),
605+
self.process_monitor.register(uuid=pm.uuid,
606606
service_name=DNSMASQ_SERVICE_NAME,
607607
monitored_process=pm)
608608

neutron/tests/unit/agent/linux/test_dhcp.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,12 @@ def __init__(self):
10931093
self.namespace = 'qdhcp-ns'
10941094

10951095

1096+
class FakeSegment(object):
1097+
def __init__(self):
1098+
self.id = 'iiiiiiii-iiii-iiii-iiii-iiiiiiiiiiii'
1099+
self.segmentation_id = 1212
1100+
1101+
10961102
class LocalChild(dhcp.DhcpLocalProcess):
10971103
PORTS = {4: [4], 6: [6]}
10981104

@@ -1294,6 +1300,26 @@ def test_disable(self):
12941300

12951301
delete_ns.assert_called_with('qdhcp-ns')
12961302

1303+
def test_disable_with_segment(self):
1304+
attrs_to_mock = {'active': mock.DEFAULT}
1305+
1306+
self.external_process().uuid = "1212/net-id"
1307+
1308+
with mock.patch.multiple(LocalChild, **attrs_to_mock) as mocks:
1309+
mocks['active'].__get__ = mock.Mock(return_value=False)
1310+
lp = LocalChild(
1311+
self.conf, FakeDualNetwork(), segment=FakeSegment())
1312+
with mock.patch('neutron.agent.linux.ip_lib.'
1313+
'delete_network_namespace') as delete_ns:
1314+
lp.disable()
1315+
self.rmtree.assert_called_once()
1316+
1317+
lp.process_monitor.unregister.assert_called_once_with(
1318+
'1212/net-id', 'dnsmasq')
1319+
self.assertTrue(self.external_process().disable.called)
1320+
1321+
delete_ns.assert_called_with('qdhcp-ns')
1322+
12971323
def test_enable_disable_two_networks(self):
12981324
attrs_to_mock = {'active': mock.DEFAULT}
12991325

0 commit comments

Comments
 (0)