]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Prevent stale DHCP directories for dhcp agent nodes
authorarmando-migliaccio <amigliaccio@nicira.com>
Wed, 11 Sep 2013 18:49:48 +0000 (11:49 -0700)
committerarmando-migliaccio <amigliaccio@nicira.com>
Fri, 13 Sep 2013 18:34:20 +0000 (11:34 -0700)
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

neutron/agent/linux/dhcp.py
neutron/tests/unit/test_linux_dhcp.py

index 86e2b52301fe348a20fb1b307bcbcf54d40e7dbb..b3ec08becb67a86de35572171b6317954f811a06 100644 (file)
@@ -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):
index 34f16267fa5a5735dbc8ed3ed5f8b88c8238dc5d..6fd86174a65bfb865b7ce23305aea75b403fb186 100644 (file)
@@ -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):