Merge "Make nova-network use FixedIP object for updates"

This commit is contained in:
Jenkins 2014-02-14 19:35:15 +00:00 committed by Gerrit Code Review
commit 311652325b
2 changed files with 28 additions and 25 deletions
nova
network
tests/network

@ -857,9 +857,9 @@ class NetworkManager(manager.Manager):
context.elevated(), network['id'], instance_id) context.elevated(), network['id'], instance_id)
vif = vif_obj.VirtualInterface.get_by_instance_and_network( vif = vif_obj.VirtualInterface.get_by_instance_and_network(
context, instance_id, network['id']) context, instance_id, network['id'])
values = {'allocated': True, fip.allocated = True
'virtual_interface_id': vif['id']} fip.virtual_interface_id = vif.id
self.db.fixed_ip_update(context, str(fip.address), values) fip.save()
self._do_trigger_security_group_members_refresh_for_instance( self._do_trigger_security_group_members_refresh_for_instance(
instance_id) instance_id)
@ -916,9 +916,9 @@ class NetworkManager(manager.Manager):
self.instance_dns_manager.delete_entry(n, self.instance_dns_manager.delete_entry(n,
self.instance_dns_domain) self.instance_dns_domain)
self.db.fixed_ip_update(context, address, fixed_ip_ref.allocated = False
{'allocated': False, fixed_ip_ref.virtual_interface_id = None
'virtual_interface_id': None}) fixed_ip_ref.save()
if teardown: if teardown:
network = fixed_ip_ref.network network = fixed_ip_ref.network
@ -974,11 +974,8 @@ class NetworkManager(manager.Manager):
LOG.warn(_('IP %s leased that is not associated'), address, LOG.warn(_('IP %s leased that is not associated'), address,
context=context) context=context)
return return
now = timeutils.utcnow() fixed_ip.leased = True
self.db.fixed_ip_update(context, fixed_ip.save()
fixed_ip.address,
{'leased': True,
'updated_at': now})
if not fixed_ip.allocated: if not fixed_ip.allocated:
LOG.warn(_('IP |%s| leased that isn\'t allocated'), address, LOG.warn(_('IP |%s| leased that isn\'t allocated'), address,
context=context) context=context)
@ -995,9 +992,8 @@ class NetworkManager(manager.Manager):
if not fixed_ip.leased: if not fixed_ip.leased:
LOG.warn(_('IP %s released that was not leased'), address, LOG.warn(_('IP %s released that was not leased'), address,
context=context) context=context)
self.db.fixed_ip_update(context, fixed_ip.leased = False
fixed_ip.address, fixed_ip.save()
{'leased': False})
if not fixed_ip.allocated: if not fixed_ip.allocated:
fixed_ip.disassociate() fixed_ip.disassociate()
@ -1725,7 +1721,7 @@ class VlanManager(RPCAllocateFixedIP, floating_ips.FloatingIP, NetworkManager):
if kwargs.get('vpn', None): if kwargs.get('vpn', None):
address = network['vpn_private_address'] address = network['vpn_private_address']
fixed_ip_obj.FixedIP.associate(context, address, instance_id, fip = fixed_ip_obj.FixedIP.associate(context, address, instance_id,
network['id'], reserved=True) network['id'], reserved=True)
else: else:
address = kwargs.get('address', None) address = kwargs.get('address', None)
@ -1741,9 +1737,9 @@ class VlanManager(RPCAllocateFixedIP, floating_ips.FloatingIP, NetworkManager):
vif = vif_obj.VirtualInterface.get_by_instance_and_network( vif = vif_obj.VirtualInterface.get_by_instance_and_network(
context, instance_id, network['id']) context, instance_id, network['id'])
values = {'allocated': True, fip.allocated = True
'virtual_interface_id': vif.id} fip.virtual_interface_id = vif.id
self.db.fixed_ip_update(context, str(address), values) fip.save()
if not kwargs.get('vpn', None): if not kwargs.get('vpn', None):
self._do_trigger_security_group_members_refresh_for_instance( self._do_trigger_security_group_members_refresh_for_instance(
@ -1903,10 +1899,11 @@ class VlanManager(RPCAllocateFixedIP, floating_ips.FloatingIP, NetworkManager):
self.driver.kill_dhcp(dev) self.driver.kill_dhcp(dev)
self.l3driver.remove_gateway(network) self.l3driver.remove_gateway(network)
if not CONF.share_dhcp_address: if not CONF.share_dhcp_address:
values = {'allocated': False, fip = fixed_ip_obj.FixedIP.get_by_address(
'host': None} context, network.dhcp_server)
self.db.fixed_ip_update(context, network['dhcp_server'], fip.allocated = False
values) fip.host = None
fip.save()
else: else:
self.driver.update_dhcp(elevated, dev, network) self.driver.update_dhcp(elevated, dev, network)

@ -1364,7 +1364,8 @@ class VlanNetworkTestCase(test.TestCase):
@mock.patch('nova.db.fixed_ip_get_by_address') @mock.patch('nova.db.fixed_ip_get_by_address')
@mock.patch('nova.db.network_get') @mock.patch('nova.db.network_get')
def test_deallocate_fixed_no_vif(self, net_get, fixed_get): @mock.patch('nova.db.fixed_ip_update')
def test_deallocate_fixed_no_vif(self, fixed_update, net_get, fixed_get):
"""Verify that deallocate doesn't raise when no vif is returned. """Verify that deallocate doesn't raise when no vif is returned.
Ensures https://bugs.launchpad.net/nova/+bug/968457 doesn't return Ensures https://bugs.launchpad.net/nova/+bug/968457 doesn't return
@ -1384,13 +1385,18 @@ class VlanNetworkTestCase(test.TestCase):
elevated = context1.elevated() elevated = context1.elevated()
fix_addr = db.fixed_ip_associate_pool(elevated, 1, instance['uuid']) fix_addr = db.fixed_ip_associate_pool(elevated, 1, instance['uuid'])
fixed_get.return_value = dict(test_fixed_ip.fake_fixed_ip, fixed_get.return_value = dict(test_fixed_ip.fake_fixed_ip,
address=fix_addr.address,
allocated=True, allocated=True,
virtual_interface_id=3, virtual_interface_id=3,
instance_uuid=instance.uuid, instance_uuid=instance.uuid,
network=dict(test_network.fake_network, network=dict(test_network.fake_network,
**networks[1])) **networks[1]))
self.flags(force_dhcp_release=True) self.flags(force_dhcp_release=True)
fixed_update.return_value = fixed_get.return_value
self.network.deallocate_fixed_ip(context1, fix_addr.address, 'fake') self.network.deallocate_fixed_ip(context1, fix_addr.address, 'fake')
fixed_update.assert_called_once_with(context1, fix_addr.address,
{'allocated': False,
'virtual_interface_id': None})
@mock.patch('nova.db.fixed_ip_get_by_address') @mock.patch('nova.db.fixed_ip_get_by_address')
@mock.patch('nova.db.network_get') @mock.patch('nova.db.network_get')