]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
When disabling dhcp, delete fixed ip properly
authorwatanabe.isao <zou.yun@jp.fujitsu.com>
Fri, 20 Feb 2015 08:38:16 +0000 (17:38 +0900)
committerwatanabe isao <zou.yun@jp.fujitsu.com>
Wed, 13 May 2015 04:54:47 +0000 (04:54 +0000)
When setting enable_dhcp parameter of subnet to False, the fixed ip of
dhcp port of this subnet is not been removed.
Also a resync will be triggered.

Change-Id: Iebd2c7922978bec0ef154866f24319e899e3b88e
Closes-Bug: 1417379

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

index f594b775c0f74b6170b3c098abef42254b041374..70453d265f7362972be1f1c7c041ed8f9e78f391 100644 (file)
@@ -861,15 +861,19 @@ class DeviceManager(object):
             port_device_id = getattr(port, 'device_id', None)
             if port_device_id == device_id:
                 port_fixed_ips = []
+                ips_needs_removal = False
                 for fixed_ip in port.fixed_ips:
-                    port_fixed_ips.append({'subnet_id': fixed_ip.subnet_id,
-                                           'ip_address': fixed_ip.ip_address})
                     if fixed_ip.subnet_id in dhcp_enabled_subnet_ids:
+                        port_fixed_ips.append(
+                            {'subnet_id': fixed_ip.subnet_id,
+                             'ip_address': fixed_ip.ip_address})
                         dhcp_enabled_subnet_ids.remove(fixed_ip.subnet_id)
+                    else:
+                        ips_needs_removal = True
 
                 # If there are dhcp_enabled_subnet_ids here that means that
                 # we need to add those to the port and call update.
-                if dhcp_enabled_subnet_ids:
+                if dhcp_enabled_subnet_ids or ips_needs_removal:
                     port_fixed_ips.extend(
                         [dict(subnet_id=s) for s in dhcp_enabled_subnet_ids])
                     dhcp_port = self.plugin.update_dhcp_port(
index 24c0d10564cd6b5de78d55ea67dfefe22e9f775c..69c71a32caa3c79a64501a4c9b78650c9290b835 100644 (file)
@@ -1340,6 +1340,15 @@ class TestDeviceManager(base.BaseTestCase):
         self.assertFalse(plugin.setup_dhcp_port.called)
         self.assertFalse(plugin.update_dhcp_port.called)
 
+    def test_setup_dhcp_port_with_non_enable_dhcp_subnet(self):
+        plugin = mock.Mock()
+        dh = dhcp.DeviceManager(cfg.CONF, plugin)
+        fake_network_copy = copy.deepcopy(fake_network)
+        fake_network_copy.ports[0].device_id = dh.get_device_id(fake_network)
+        plugin.update_dhcp_port.return_value = fake_port1
+        self.assertEqual(fake_subnet1.id,
+                dh.setup_dhcp_port(fake_network_copy).fixed_ips[0].subnet_id)
+
     def test_destroy(self):
         fake_net = dhcp.NetModel(
             True, dict(id=FAKE_NETWORK_UUID,