From: armando-migliaccio Date: Wed, 11 Sep 2013 18:49:48 +0000 (-0700) Subject: Prevent stale DHCP directories for dhcp agent nodes X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=eea6218e425766cefc62757da85b9de058d8e312;p=openstack-build%2Fneutron-build.git Prevent stale DHCP directories for dhcp agent nodes This change fixes an issue that is most acute in test/dev environments but that may affect production environments as well: the presence of DHCP directories that no longer represent networks that exist in the Neutron DB. This issue can manifest itself over time if you delete networks from the Server while the Agent node is down. Without this fix, at the agent start-up the method existing_dhcp_networks will return an empty list, and as a consequence the directories that belong to networks that have been removed from the server will stay because the sync logic will not process them as it only looks at the mismatch between active networks on the agent and active networks on the server. With the fix instead, we return *all* existing dhcp networks; if they are meant to be active, the agent will bring them up, if they no longer exist on the server, then the agent will dispose of the resources. The dnsmasq driver will do the right thing when enabling or disabling the process. Fixes bug #1195770 Change-Id: I194064a449801713051d01193adc706bcb687c82 --- diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index 86e2b5230..b3ec08bec 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -288,14 +288,9 @@ class Dnsmasq(DhcpLocalProcess): confs_dir = os.path.abspath(os.path.normpath(conf.dhcp_confs)) - class FakeNetwork: - def __init__(self, net_id): - self.id = net_id - return [ c for c in os.listdir(confs_dir) - if (uuidutils.is_uuid_like(c) and - cls(conf, FakeNetwork(c), root_helper).active) + if uuidutils.is_uuid_like(c) ] def spawn_process(self): diff --git a/neutron/tests/unit/test_linux_dhcp.py b/neutron/tests/unit/test_linux_dhcp.py index 34f16267f..6fd86174a 100644 --- a/neutron/tests/unit/test_linux_dhcp.py +++ b/neutron/tests/unit/test_linux_dhcp.py @@ -940,7 +940,8 @@ tag:tag1,249,%s,%s""".lstrip() % (fake_v6, result = dhcp.Dnsmasq.existing_dhcp_networks(self.conf, 'sudo') mock_listdir.assert_called_once_with(path) - self.assertEqual(['aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'], + self.assertEqual(['aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', + 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'], result) def _check_version(self, cmd_out, expected_value):