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
This commit is contained in:
watanabe.isao 2015-02-20 17:38:16 +09:00 committed by watanabe isao
parent c5188d8bf8
commit 2acdbf3bac
2 changed files with 16 additions and 3 deletions

View 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(

View 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,