Skip to content

Commit

Permalink
Check vif exists before releasing ip
Browse files Browse the repository at this point in the history
 * adds test to make sure code doesn't raise
 * fixes bug 968457

Change-Id: I7110cb18a45fb955769247a9a0c5fb721ab3935a
  • Loading branch information
vishvananda committed Apr 2, 2012
1 parent ccb93c4 commit 256403e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion nova/network/manager.py
Expand Up @@ -1223,7 +1223,8 @@ def deallocate_fixed_ip(self, context, address, **kwargs):
context, instance_id, network['id'])
# NOTE(vish): This forces a packet so that the release_fixed_ip
# callback will get called by nova-dhcpbridge.
self.driver.release_dhcp(dev, address, vif['address'])
if vif:
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
26 changes: 26 additions & 0 deletions nova/tests/network/test_manager.py
Expand Up @@ -873,6 +873,32 @@ def network_get(_context, network_id):
db.floating_ip_destroy(context1.elevated(), float_addr)
db.fixed_ip_disassociate(context1.elevated(), fix_addr)

def test_deallocate_fixed_no_vif(self):
"""Verify that deallocate doesn't raise when no vif is returned.
Ensures https://bugs.launchpad.net/nova/+bug/968457 doesn't return"""

def network_get(_context, network_id):
return networks[network_id]

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

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

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

instance = db.instance_create(context1,
{'project_id': 'project1'})

fix_addr = db.fixed_ip_associate_pool(context1.elevated(),
1, instance['id'])

self.flags(force_dhcp_release=True)
self.network.deallocate_fixed_ip(context1, fix_addr, 'fake')


class CommonNetworkTestCase(test.TestCase):

Expand Down

0 comments on commit 256403e

Please sign in to comment.