deallocate_fixed_ip attempts to update deleted ip

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
This commit is contained in:
John H. Tran 2012-06-22 19:14:06 -07:00 committed by John Tran
parent 2c0083d84a
commit 61ab72d15b
2 changed files with 36 additions and 2 deletions

View File

@ -987,8 +987,7 @@ class NetworkManager(manager.SchedulerDependentManager):
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,

View File

@ -943,6 +943,41 @@ class VlanNetworkTestCase(test.TestCase):
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.