Skip to content

Commit

Permalink
Grab the vif directly on release instead of lookup
Browse files Browse the repository at this point in the history
 * adds extra error handling and logging
 * safer fix for bug 968457

Change-Id: I6d8c27c642e70dc701548550c0d94a8e0e64ce99
  • Loading branch information
vishvananda committed Apr 3, 2012
1 parent 32f07e6 commit c96e75d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
22 changes: 18 additions & 4 deletions nova/network/manager.py
Expand Up @@ -1219,12 +1219,26 @@ def deallocate_fixed_ip(self, context, address, **kwargs):

if FLAGS.force_dhcp_release:
dev = self.driver.get_dev(network)
vif = self.db.virtual_interface_get_by_instance_and_network(
context, instance_id, network['id'])
vif_id = fixed_ip_ref['virtual_interface_id']

# NOTE(vish): The below errors should never happen, but there may
# be a race condition that is causing them per
# https://code.launchpad.net/bugs/968457, so we log
# an error to help track down the possible race.
msg = _("Unable to release %s because vif doesn't exist.")
if not vif_id:
LOG.error(msg % address)
return

vif = self.db.virtual_interface_get(context, vif_id)

if not vif:
LOG.error(msg % address)
return

# NOTE(vish): This forces a packet so that the release_fixed_ip
# callback will get called by nova-dhcpbridge.
if vif:
self.driver.release_dhcp(dev, address, vif['address'])
self.driver.release_dhcp(dev, address, vif['address'])

def lease_fixed_ip(self, context, address):
"""Called by dhcp-bridge when ip is leased."""
Expand Down
5 changes: 2 additions & 3 deletions nova/tests/network/test_manager.py
Expand Up @@ -883,11 +883,10 @@ def network_get(_context, network_id):

self.stubs.Set(db, 'network_get', network_get)

def vif_get(_context, _instance_id, _network_id):
def vif_get(_context, _vif_id):
return None

self.stubs.Set(db, 'virtual_interface_get_by_instance_and_network',
vif_get)
self.stubs.Set(db, 'virtual_interface_get', vif_get)
context1 = context.RequestContext('user', 'project1')

instance = db.instance_create(context1,
Expand Down

0 comments on commit c96e75d

Please sign in to comment.