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 <sahid.ferdjaoui@industrialdiscipline.com>
Change-Id: Ic6e999214210383f17c29982bf5673eea1bb55c0
This commit is contained in:
Sahid Orentino Ferdjaoui 2024-01-30 11:40:31 +01:00
parent a98336043f
commit b37c0f45c8
2 changed files with 28 additions and 2 deletions

View File

@ -358,8 +358,8 @@ class DhcpLocalProcess(DhcpBase, metaclass=abc.ABCMeta):
def disable(self, retain_port=False, block=False, **kwargs):
"""Disable DHCP for this network by killing the local process."""
self.process_monitor.unregister(self.network.id, DNSMASQ_SERVICE_NAME)
pm = self._get_process_manager()
self.process_monitor.unregister(pm.uuid, DNSMASQ_SERVICE_NAME)
pm.disable(sig=str(int(signal.SIGTERM)))
if block:
try:
@ -602,7 +602,7 @@ class Dnsmasq(DhcpLocalProcess):
pm.enable(reload_cfg=reload_with_HUP, ensure_active=True)
self.process_monitor.register(uuid=self.get_process_uuid(),
self.process_monitor.register(uuid=pm.uuid,
service_name=DNSMASQ_SERVICE_NAME,
monitored_process=pm)

View File

@ -1094,6 +1094,12 @@ class FakeV6NetworkStatefulDHCPSameSubnetFixedIps(object):
self.namespace = 'qdhcp-ns'
class FakeSegment(object):
def __init__(self):
self.id = 'iiiiiiii-iiii-iiii-iiii-iiiiiiiiiiii'
self.segmentation_id = 1212
class LocalChild(dhcp.DhcpLocalProcess):
PORTS = {4: [4], 6: [6]}
@ -1295,6 +1301,26 @@ class TestDhcpLocalProcess(TestBase):
delete_ns.assert_called_with('qdhcp-ns')
def test_disable_with_segment(self):
attrs_to_mock = {'active': mock.DEFAULT}
self.external_process().uuid = "1212/net-id"
with mock.patch.multiple(LocalChild, **attrs_to_mock) as mocks:
mocks['active'].__get__ = mock.Mock(return_value=False)
lp = LocalChild(
self.conf, FakeDualNetwork(), segment=FakeSegment())
with mock.patch('neutron.agent.linux.ip_lib.'
'delete_network_namespace') as delete_ns:
lp.disable()
self.rmtree.assert_called_once()
lp.process_monitor.unregister.assert_called_once_with(
'1212/net-id', 'dnsmasq')
self.assertTrue(self.external_process().disable.called)
delete_ns.assert_called_with('qdhcp-ns')
def test_enable_disable_two_networks(self):
attrs_to_mock = {'active': mock.DEFAULT}