summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-11-06 01:29:56 +0000
committerGerrit Code Review <review@openstack.org>2012-11-06 01:29:56 +0000
commit3e6dc4c3b4eee2f939f9d2091b6d7f6d66dce71b (patch)
treec8c43f50a0cb8c8c53041a9540b87815093518ce
parent43f639a5adf0c15940ef0fe55208c2ca77dc2817 (diff)
parentb3843021b78a5150d8fd577fda523a52f8ce5b26 (diff)
downloadnova-3e6dc4c3b4eee2f939f9d2091b6d7f6d66dce71b.tar.gz
nova-3e6dc4c3b4eee2f939f9d2091b6d7f6d66dce71b.tar.xz
nova-3e6dc4c3b4eee2f939f9d2091b6d7f6d66dce71b.zip
Merge "Fix migrations when not using multi-host network"
-rw-r--r--nova/network/api.py2
-rw-r--r--nova/network/rpcapi.py22
-rw-r--r--nova/tests/network/test_api.py64
-rw-r--r--nova/tests/network/test_rpcapi.py50
4 files changed, 129 insertions, 9 deletions
diff --git a/nova/network/api.py b/nova/network/api.py
index bb05a0c2a..d2ce876b8 100644
--- a/nova/network/api.py
+++ b/nova/network/api.py
@@ -353,6 +353,7 @@ class API(base.Base):
if self._is_multi_host(context, instance):
args['floating_addresses'] = \
self._get_floating_ip_addresses(context, instance)
+ args['host'] = migration['dest_compute']
self.network_rpcapi.migrate_instance_start(context, **args)
@@ -370,5 +371,6 @@ class API(base.Base):
if self._is_multi_host(context, instance):
args['floating_addresses'] = \
self._get_floating_ip_addresses(context, instance)
+ args['host'] = migration['dest_compute']
self.network_rpcapi.migrate_instance_finish(context, **args)
diff --git a/nova/network/rpcapi.py b/nova/network/rpcapi.py
index 6f31e140b..8dd5e3a69 100644
--- a/nova/network/rpcapi.py
+++ b/nova/network/rpcapi.py
@@ -267,7 +267,11 @@ class NetworkAPI(rpc_proxy.RpcProxy):
def migrate_instance_start(self, ctxt, instance_uuid, rxtx_factor,
project_id, source_compute, dest_compute,
- floating_addresses):
+ floating_addresses, host=None):
+ if host is not None:
+ topic = rpc.queue_get_for(ctxt, self.topic, host)
+ else:
+ topic = self.topic
return self.call(ctxt, self.make_msg(
'migrate_instance_start',
instance_uuid=instance_uuid,
@@ -276,13 +280,16 @@ class NetworkAPI(rpc_proxy.RpcProxy):
source=source_compute,
dest=dest_compute,
floating_addresses=floating_addresses),
- topic=rpc.queue_get_for(ctxt, self.topic,
- dest_compute),
- version='1.2')
+ topic=topic,
+ version='1.2')
def migrate_instance_finish(self, ctxt, instance_uuid, rxtx_factor,
project_id, source_compute, dest_compute,
- floating_addresses):
+ floating_addresses, host=None):
+ if host is not None:
+ topic = rpc.queue_get_for(ctxt, self.topic, host)
+ else:
+ topic = self.topic
return self.call(ctxt, self.make_msg(
'migrate_instance_finish',
instance_uuid=instance_uuid,
@@ -291,6 +298,5 @@ class NetworkAPI(rpc_proxy.RpcProxy):
source=source_compute,
dest=dest_compute,
floating_addresses=floating_addresses),
- topic=rpc.queue_get_for(ctxt, self.topic,
- dest_compute),
- version='1.2')
+ topic=topic,
+ version='1.2')
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')