From 625e48f82b5c7f1d55641b4207afd85b0b798cc2 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Tue, 22 Apr 2014 06:59:43 -0700 Subject: [PATCH] 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 --- nova/network/api.py | 6 +++--- nova/objects/floating_ip.py | 13 +++++++++++++ nova/tests/objects/test_floating_ip.py | 9 +++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/nova/network/api.py b/nova/network/api.py index 067c913596ef..7e5ee250e393 100644 --- a/nova/network/api.py +++ b/nova/network/api.py @@ -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): diff --git a/nova/objects/floating_ip.py b/nova/objects/floating_ip.py index 1bd2c2ea0132..3cd667ca8e68 100644 --- a/nova/objects/floating_ip.py +++ b/nova/objects/floating_ip.py @@ -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): diff --git a/nova/tests/objects/test_floating_ip.py b/nova/tests/objects/test_floating_ip.py index 41c9cb038cdd..f401412378d5 100644 --- a/nova/tests/objects/test_floating_ip.py +++ b/nova/tests/objects/test_floating_ip.py @@ -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):