Fix migrate_instance_*() using DB for floating addresses
This fixes the network api's migrate_instance_start() and migrate_instance_finish() methods that are still hitting the database directly for an oddball call to get a list of floating addresses. Change-Id: Ia310e31d31aaf5c979e41c64af8223202a18e03a Closes-bug: #1310966
This commit is contained in:
parent
0c0a848c7d
commit
625e48f82b
@ -25,6 +25,7 @@ from nova.network import floating_ips
|
||||
from nova.network import model as network_model
|
||||
from nova.network import rpcapi as network_rpcapi
|
||||
from nova.objects import fixed_ip as fixed_ip_obj
|
||||
from nova.objects import floating_ip as floating_ip_obj
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.objects import network as network_obj
|
||||
from nova.openstack.common.gettextutils import _
|
||||
@ -470,9 +471,8 @@ class API(base_api.NetworkAPI):
|
||||
return network.multi_host
|
||||
|
||||
def _get_floating_ip_addresses(self, context, instance):
|
||||
floating_ips = self.db.instance_floating_address_get_all(context,
|
||||
instance['uuid'])
|
||||
return floating_ips
|
||||
return floating_ip_obj.FloatingIP.get_addresses_by_instance(
|
||||
context, instance)
|
||||
|
||||
@wrap_check_policy
|
||||
def migrate_instance_start(self, context, instance, migration):
|
||||
|
@ -22,6 +22,9 @@ FLOATING_IP_OPTIONAL_ATTRS = ['fixed_ip']
|
||||
|
||||
|
||||
class FloatingIP(obj_base.NovaPersistentObject, obj_base.NovaObject):
|
||||
# Version 1.0: Initial version
|
||||
# Version 1.1: Added _get_addresses_by_instance_uuid()
|
||||
VERSION = '1.1'
|
||||
fields = {
|
||||
'id': fields.IntegerField(),
|
||||
'address': fields.IPAddressField(),
|
||||
@ -118,6 +121,14 @@ class FloatingIP(obj_base.NovaPersistentObject, obj_base.NovaObject):
|
||||
expected_attrs=['network']))
|
||||
return floating
|
||||
|
||||
@obj_base.remotable_classmethod
|
||||
def _get_addresses_by_instance_uuid(cls, context, instance_uuid):
|
||||
return db.instance_floating_address_get_all(context, instance_uuid)
|
||||
|
||||
@classmethod
|
||||
def get_addresses_by_instance(cls, context, instance):
|
||||
return cls._get_addresses_by_instance_uuid(context, instance['uuid'])
|
||||
|
||||
@obj_base.remotable
|
||||
def save(self, context):
|
||||
updates = self.obj_get_changes()
|
||||
@ -135,7 +146,9 @@ class FloatingIPList(obj_base.ObjectListBase, obj_base.NovaObject):
|
||||
}
|
||||
child_versions = {
|
||||
'1.0': '1.0',
|
||||
'1.1': '1.1',
|
||||
}
|
||||
VERSION = '1.1'
|
||||
|
||||
@obj_base.remotable_classmethod
|
||||
def get_all(cls, context):
|
||||
|
@ -180,6 +180,15 @@ class _TestFloatingIPObject(object):
|
||||
self._compare(floatingips[0], fake_floating_ip)
|
||||
get.assert_called_with(self.context, 123)
|
||||
|
||||
@mock.patch('nova.db.instance_floating_address_get_all')
|
||||
def test_get_addresses_by_instance(self, get_all):
|
||||
expected = ['1.2.3.4', '4.5.6.7']
|
||||
get_all.return_value = list(expected)
|
||||
ips = floating_ip.FloatingIP.get_addresses_by_instance(
|
||||
self.context, {'uuid': '1234'})
|
||||
self.assertEqual(expected, ips)
|
||||
get_all.assert_called_once_with(self.context, '1234')
|
||||
|
||||
|
||||
class TestFloatingIPObject(test_objects._LocalTest,
|
||||
_TestFloatingIPObject):
|
||||
|
Loading…
Reference in New Issue
Block a user