Skip to content

Commit

Permalink
deallocate_fixed_ip attempts to update deleted ip
Browse files Browse the repository at this point in the history
Fixes bug 1017633. When deleting a vm, the nova
network manager looks to deallocate wrong fixed
ip when context has read_deleted set to 'yes',
in case when a network had been deleted and re-
created , it attempts to update already deleted
fixed_ips and therefore looks to teardown from
wrong network_id as well.

Change-Id: I574a20273220ef81498403da80f489732ae81eb1
(cherry picked from commit 61ab72d)
  • Loading branch information
jhtran authored and vishvananda committed Sep 25, 2012
1 parent 20f98c5 commit ae9c5f4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 1 addition & 2 deletions nova/network/manager.py
Expand Up @@ -923,8 +923,7 @@ def deallocate_for_instance(self, context, **kwargs):
context=read_deleted_context)
# deallocate fixed ips
for fixed_ip in fixed_ips:
self.deallocate_fixed_ip(read_deleted_context, fixed_ip['address'],
**kwargs)
self.deallocate_fixed_ip(context, fixed_ip['address'], **kwargs)

# deallocate vifs (mac addresses)
self.db.virtual_interface_delete_by_instance(read_deleted_context,
Expand Down
35 changes: 35 additions & 0 deletions nova/tests/network/test_manager.py
Expand Up @@ -909,6 +909,41 @@ def vif_get(_context, _vif_id):
fixed = db.fixed_ip_get_by_address(elevated, fix_addr)
self.assertFalse(fixed['allocated'])

def test_deallocate_fixed_deleted(self):
"""Verify doesn't deallocate deleted fixed_ip from deleted network"""

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

def teardown_network_on_host(_context, network):
if network['id'] == 0:
raise Exception('Correct network/fixed_ip assertion')

self.stubs.Set(db, 'network_get', network_get)
self.stubs.Set(self.network, '_teardown_network_on_host',
teardown_network_on_host)

context1 = context.RequestContext('user', 'project1')

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

elevated = context1.elevated()
fix_addr = db.fixed_ip_associate_pool(elevated, 1, instance['id'])
db.fixed_ip_update(elevated, fix_addr, {'deleted': 1})
elevated.read_deleted = 'yes'
delfixed = db.fixed_ip_get_by_address(elevated, fix_addr)
values = {'address': fix_addr,
'network_id': 0,
'instance_id': delfixed['instance_id']}
db.fixed_ip_create(elevated, values)
elevated.read_deleted = 'no'
newfixed = db.fixed_ip_get_by_address(elevated, fix_addr)
elevated.read_deleted = 'yes'

deallocate = self.network.deallocate_fixed_ip
self.assertRaises(Exception, deallocate, context1, fix_addr, 'fake')

def test_deallocate_fixed_no_vif(self):
"""Verify that deallocate doesn't raise when no vif is returned.
Expand Down

0 comments on commit ae9c5f4

Please sign in to comment.