]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Only setup dhcp interface if dhcp is not active on network
authorOleg Bondarev <obondarev@mirantis.com>
Thu, 18 Sep 2014 14:39:43 +0000 (18:39 +0400)
committerOleg Bondarev <obondarev@mirantis.com>
Thu, 18 Sep 2014 14:53:58 +0000 (18:53 +0400)
When enabling (DhcpLocalProcess.enable()) dhcp for a network the agent
first sets dhcp interface, then checks if dhcp is curently active and
if it's true then the agent restarts dhcp.
Restart (DhcpBase.restart()) first disables dhcp and then enables it again
by calling DhcpLocalProcess.enable() recursively which in turn sets
dhcp interface again (it doesn't see the port created earlier as network
is not re-fetched from db). This leads to duplicate dhcp interface
for the network.

The fix is to only setup dhcp interface if dhcp is not active.

Closes-Bug: #1339968

Change-Id: I3a6d2fd5b18a97138ac5b699ecd4d4b30dbdbacb

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

index 36bce4ee2e925cc3d0a71e017cb4c4c3c53837ee..aba75af571621b3bc3f97eb2c5c6fdb716069edd 100644 (file)
@@ -198,10 +198,10 @@ class DhcpLocalProcess(DhcpBase):
 
     def enable(self):
         """Enables DHCP for this network by spawning a local process."""
-        interface_name = self.device_manager.setup(self.network)
         if self.active:
             self.restart()
         elif self._enable_dhcp():
+            interface_name = self.device_manager.setup(self.network)
             self.interface_name = interface_name
             self.spawn_process()
 
index d06a7139e2a145fb33443754ef986d2de4eb4910..f6f5fc6a23a13da81487ccb034a26d351ef8b036 100644 (file)
@@ -583,6 +583,7 @@ class TestDhcpLocalProcess(TestBase):
             lp.enable()
 
             self.assertEqual(lp.called, ['restart'])
+            self.assertFalse(self.mock_mgr.return_value.setup.called)
 
     def test_enable(self):
         attrs_to_mock = dict(