From b3843021b78a5150d8fd577fda523a52f8ce5b26 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Mon, 5 Nov 2012 17:47:55 +0000 Subject: Fix migrations when not using multi-host network Commit d96102b6251d caused rpc.calls to network manager to occur for non-multi-host configs, but they get sent to the network. topic when they should just go to 'network'. Fixes bug 1075245 Change-Id: If2bb8b3897efb59b8dc41ea136b08146e4e56270 --- nova/tests/network/test_api.py | 64 +++++++++++++++++++++++++++++++++++++++ nova/tests/network/test_rpcapi.py | 50 +++++++++++++++++++++++++++++- 2 files changed, 113 insertions(+), 1 deletion(-) (limited to 'nova/tests') diff --git a/nova/tests/network/test_api.py b/nova/tests/network/test_api.py index 9bbd7ba92..04f646ef0 100644 --- a/nova/tests/network/test_api.py +++ b/nova/tests/network/test_api.py @@ -19,6 +19,7 @@ from nova import context from nova import network +from nova.network import rpcapi as network_rpcapi from nova.openstack.common import rpc from nova import test @@ -78,3 +79,66 @@ class ApiTestCase(test.TestCase): def test_associate_unassociated_floating_ip(self): self._do_test_associate_floating_ip(None) + + def _stub_migrate_instance_calls(self, method, multi_host, info): + fake_instance_type = {'rxtx_factor': 'fake_factor'} + fake_instance = {'uuid': 'fake_uuid', + 'instance_type': fake_instance_type, + 'project_id': 'fake_project_id'} + fake_migration = {'source_compute': 'fake_compute_source', + 'dest_compute': 'fake_compute_dest'} + + def fake_mig_inst_method(*args, **kwargs): + info['kwargs'] = kwargs + + def fake_is_multi_host(*args, **kwargs): + return multi_host + + def fake_get_floaters(*args, **kwargs): + return ['fake_float1', 'fake_float2'] + + self.stubs.Set(network_rpcapi.NetworkAPI, method, + fake_mig_inst_method) + self.stubs.Set(self.network_api, '_is_multi_host', + fake_is_multi_host) + self.stubs.Set(self.network_api, '_get_floating_ip_addresses', + fake_get_floaters) + + expected = {'instance_uuid': 'fake_uuid', + 'source_compute': 'fake_compute_source', + 'dest_compute': 'fake_compute_dest', + 'rxtx_factor': 'fake_factor', + 'project_id': 'fake_project_id', + 'floating_addresses': None} + if multi_host: + expected['host'] = 'fake_compute_dest' + expected['floating_addresses'] = ['fake_float1', 'fake_float2'] + return fake_instance, fake_migration, expected + + def test_migrate_instance_start_with_multhost(self): + info = {'kwargs': {}} + arg1, arg2, expected = self._stub_migrate_instance_calls( + 'migrate_instance_start', True, info) + self.network_api.migrate_instance_start(self.context, arg1, arg2) + self.assertEqual(info['kwargs'], expected) + + def test_migrate_instance_start_without_multhost(self): + info = {'kwargs': {}} + arg1, arg2, expected = self._stub_migrate_instance_calls( + 'migrate_instance_start', False, info) + self.network_api.migrate_instance_start(self.context, arg1, arg2) + self.assertEqual(info['kwargs'], expected) + + def test_migrate_instance_finish_with_multhost(self): + info = {'kwargs': {}} + arg1, arg2, expected = self._stub_migrate_instance_calls( + 'migrate_instance_finish', True, info) + self.network_api.migrate_instance_finish(self.context, arg1, arg2) + self.assertEqual(info['kwargs'], expected) + + def test_migrate_instance_finish_without_multhost(self): + info = {'kwargs': {}} + arg1, arg2, expected = self._stub_migrate_instance_calls( + 'migrate_instance_finish', False, info) + self.network_api.migrate_instance_finish(self.context, arg1, arg2) + self.assertEqual(info['kwargs'], expected) diff --git a/nova/tests/network/test_rpcapi.py b/nova/tests/network/test_rpcapi.py index a087ba97f..de3f19cea 100644 --- a/nova/tests/network/test_rpcapi.py +++ b/nova/tests/network/test_rpcapi.py @@ -36,11 +36,17 @@ class NetworkRpcAPITestCase(test.TestCase): expected_version = kwargs.pop('version', rpcapi.BASE_RPC_API_VERSION) expected_topic = FLAGS.network_topic expected_msg = rpcapi.make_msg(method, **kwargs) + if 'source_compute' in expected_msg['args']: + # Fix up for migrate_instance_* calls. + args = expected_msg['args'] + args['source'] = args.pop('source_compute') + args['dest'] = args.pop('dest_compute') targeted_methods = [ 'lease_fixed_ip', 'release_fixed_ip', 'rpc_setup_network_on_host', '_rpc_allocate_fixed_ip', 'deallocate_fixed_ip', '_associate_floating_ip', '_disassociate_floating_ip', - 'lease_fixed_ip', 'release_fixed_ip' + 'lease_fixed_ip', 'release_fixed_ip', + 'migrate_instance_start', 'migrate_instance_finish', ] if method in targeted_methods and 'host' in kwargs: if method != 'deallocate_fixed_ip': @@ -258,3 +264,45 @@ class NetworkRpcAPITestCase(test.TestCase): def test_release_fixed_ip(self): self._test_network_api('release_fixed_ip', rpc_method='cast', address='fake_addr', host='fake_host') + + def test_migrate_instance_start(self): + self._test_network_api('migrate_instance_start', rpc_method='call', + instance_uuid='fake_instance_uuid', + rxtx_factor='fake_factor', + project_id='fake_project', + source_compute='fake_src_compute', + dest_compute='fake_dest_compute', + floating_addresses='fake_floating_addresses', + version='1.2') + + def test_migrate_instance_start_multi_host(self): + self._test_network_api('migrate_instance_start', rpc_method='call', + instance_uuid='fake_instance_uuid', + rxtx_factor='fake_factor', + project_id='fake_project', + source_compute='fake_src_compute', + dest_compute='fake_dest_compute', + floating_addresses='fake_floating_addresses', + host='fake_host', + version='1.2') + + def test_migrate_instance_finish(self): + self._test_network_api('migrate_instance_finish', rpc_method='call', + instance_uuid='fake_instance_uuid', + rxtx_factor='fake_factor', + project_id='fake_project', + source_compute='fake_src_compute', + dest_compute='fake_dest_compute', + floating_addresses='fake_floating_addresses', + version='1.2') + + def test_migrate_instance_finish_multi_host(self): + self._test_network_api('migrate_instance_finish', rpc_method='call', + instance_uuid='fake_instance_uuid', + rxtx_factor='fake_factor', + project_id='fake_project', + source_compute='fake_src_compute', + dest_compute='fake_dest_compute', + floating_addresses='fake_floating_addresses', + host='fake_host', + version='1.2') -- cgit