From: watanabe.isao Date: Fri, 20 Feb 2015 08:38:16 +0000 (+0900) Subject: When disabling dhcp, delete fixed ip properly X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=2acdbf3bac7f4a967e2ef8f98b2ac14fa0f7f861;p=openstack-build%2Fneutron-build.git When disabling dhcp, delete fixed ip properly 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 --- diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index f594b775c..70453d265 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -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( diff --git a/neutron/tests/unit/agent/dhcp/test_agent.py b/neutron/tests/unit/agent/dhcp/test_agent.py index 24c0d1056..69c71a32c 100644 --- a/neutron/tests/unit/agent/dhcp/test_agent.py +++ b/neutron/tests/unit/agent/dhcp/test_agent.py @@ -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,