From 3f6739e2a8acdf20d01c0b5039a33f26d879587b Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Wed, 13 Feb 2013 16:56:29 -0800 Subject: Only dhcp the first ip for each mac address. When using add-fixed-ip there can be more than one ip for each mac so make dnsmasq just serve the first one. Also, make sure to disassociate the fixed ips when they are removed since dnsmasq will never know about them. Fixes bug 1124692 Change-Id: If41c03e1adb408ce28d8e8a25706ebc76fb3c4e1 --- nova/network/linux_net.py | 5 ++++- nova/network/manager.py | 16 ++++++++++++---- nova/tests/fake_network.py | 3 +++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py index 08a2ae354..a6d785784 100644 --- a/nova/network/linux_net.py +++ b/nova/network/linux_net.py @@ -775,10 +775,13 @@ def get_dhcp_hosts(context, network_ref): host = None if network_ref['multi_host']: host = CONF.host + macs = set() for data in db.network_get_associated_fixed_ips(context, network_ref['id'], host=host): - hosts.append(_host_dhcp(data)) + if data['vif_address'] not in macs: + hosts.append(_host_dhcp(data)) + macs.add(data['vif_address']) return '\n'.join(hosts) diff --git a/nova/network/manager.py b/nova/network/manager.py index 4b3863498..ef967383c 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -778,6 +778,12 @@ class NetworkManager(manager.SchedulerDependentManager): for fixed_ip in fixed_ips: if fixed_ip['address'] == address: self.deallocate_fixed_ip(context, address, host) + # NOTE(vish): this probably isn't a dhcp ip so just + # deallocate it now. In the extremely rare + # case that this is a race condition, we + # will just get a warn in lease or release. + if not fixed_ip.get('leased'): + self.db.fixed_ip_disassociate(context, address) return self.get_instance_nw_info(context, instance_id, rxtx_factor, host) raise exception.FixedIpNotFoundForSpecificInstance( @@ -909,8 +915,9 @@ class NetworkManager(manager.SchedulerDependentManager): fixed_ip = self.db.fixed_ip_get_by_address(context, address) if fixed_ip['instance_uuid'] is None: - msg = _('IP %s leased that is not associated') % address - raise exception.NovaException(msg) + LOG.warn(_('IP %s leased that is not associated'), address, + context=context) + return now = timeutils.utcnow() self.db.fixed_ip_update(context, fixed_ip['address'], @@ -926,8 +933,9 @@ class NetworkManager(manager.SchedulerDependentManager): fixed_ip = self.db.fixed_ip_get_by_address(context, address) if fixed_ip['instance_uuid'] is None: - msg = _('IP %s released that is not associated') % address - raise exception.NovaException(msg) + LOG.warn(_('IP %s released that is not associated'), address, + context=context) + return if not fixed_ip['leased']: LOG.warn(_('IP %s released that was not leased'), address, context=context) diff --git a/nova/tests/fake_network.py b/nova/tests/fake_network.py index 6618c58ea..ac21da628 100644 --- a/nova/tests/fake_network.py +++ b/nova/tests/fake_network.py @@ -148,6 +148,9 @@ class FakeNetworkManager(network_manager.NetworkManager): return [ip for ip in self.fixed_ips if ip['virtual_interface_id'] == vif_id] + def fixed_ip_disassociate(self, context, address): + return True + def __init__(self): self.db = self.FakeDB() self.deallocate_called = None -- cgit