Merge "Send a full instance via rpc for check_can_live_migrate_destination."

This commit is contained in:
Jenkins 2012-07-26 04:04:28 +00:00 committed by Gerrit Code Review
commit 2999e1143d
5 changed files with 37 additions and 29 deletions

View File

@ -297,7 +297,7 @@ def _get_additional_capabilities():
class ComputeManager(manager.SchedulerDependentManager):
"""Manages the running instances from creation to destruction."""
RPC_API_VERSION = '1.9'
RPC_API_VERSION = '1.10'
def __init__(self, compute_driver=None, *args, **kwargs):
"""Load configuration options and connect to the hypervisor."""
@ -2092,25 +2092,28 @@ class ComputeManager(manager.SchedulerDependentManager):
raise rpc_common.RPCException(message=_('Deprecated from version 1.2'))
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
def check_can_live_migrate_destination(self, ctxt, instance_id,
block_migration=False,
disk_over_commit=False):
def check_can_live_migrate_destination(self, ctxt, block_migration=False,
disk_over_commit=False,
instance_id=None, instance=None):
"""Check if it is possible to execute live migration.
This runs checks on the destination host, and then calls
back to the source host to check the results.
:param context: security context
:param instance_id: nova.db.sqlalchemy.models.Instance.Id
:param instance: dict of instance data
:param instance_id: (deprecated and only supplied if no instance passed
in) nova.db.sqlalchemy.models.Instance.Id
:param block_migration: if true, prepare for block migration
:param disk_over_commit: if true, allow disk over commit
"""
instance_ref = self.db.instance_get(ctxt, instance_id)
if not instance:
instance = self.db.instance_get(ctxt, instance_id)
dest_check_data = self.driver.check_can_live_migrate_destination(ctxt,
instance_ref, block_migration, disk_over_commit)
instance, block_migration, disk_over_commit)
try:
self.compute_rpcapi.check_can_live_migrate_source(ctxt,
instance_ref, dest_check_data)
instance, dest_check_data)
finally:
self.driver.check_can_live_migrate_destination_cleanup(ctxt,
dest_check_data)

View File

@ -68,6 +68,8 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
1.8 - Remove instance_uuid, add instance argument to
add_fixed_ip_to_instance()
1.9 - Remove instance_uuid, add instance argument to attach_volume()
1.10 - Remove instance_id, add instance argument to
check_can_live_migrate_destination()
'''
BASE_RPC_API_VERSION = '1.0'
@ -107,12 +109,13 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
def check_can_live_migrate_destination(self, ctxt, instance, destination,
block_migration, disk_over_commit):
instance_p = jsonutils.to_primitive(instance)
self.call(ctxt, self.make_msg('check_can_live_migrate_destination',
instance_id=instance['id'],
instance=instance_p,
block_migration=block_migration,
disk_over_commit=disk_over_commit),
topic=_compute_topic(self.topic, ctxt, destination, None),
version='1.2')
version='1.10')
def check_can_live_migrate_source(self, ctxt, instance, dest_check_data):
self.call(ctxt, self.make_msg('check_can_live_migrate_source',

View File

@ -1425,11 +1425,11 @@ class ComputeTestCase(BaseTestCase):
def test_check_can_live_migrate_destination_works_correctly(self):
"""Confirm check_can_live_migrate_destination works on positive path"""
context = self.context.elevated()
inst_ref = self._create_fake_instance({'host': 'fake_host_2'})
inst_ref = jsonutils.to_primitive(self._create_fake_instance(
{'host': 'fake_host_2'}))
inst_id = inst_ref["id"]
dest = "fake_host_1"
self.mox.StubOutWithMock(db, 'instance_get')
self.mox.StubOutWithMock(self.compute.driver,
'check_can_live_migrate_destination')
self.mox.StubOutWithMock(self.compute.compute_rpcapi,
@ -1437,7 +1437,6 @@ class ComputeTestCase(BaseTestCase):
self.mox.StubOutWithMock(self.compute.driver,
'check_can_live_migrate_destination_cleanup')
db.instance_get(context, inst_id).AndReturn(inst_ref)
dest_check_data = {"test": "data"}
self.compute.driver.check_can_live_migrate_destination(context,
inst_ref, True, False).AndReturn(dest_check_data)
@ -1447,37 +1446,38 @@ class ComputeTestCase(BaseTestCase):
context, dest_check_data)
self.mox.ReplayAll()
self.compute.check_can_live_migrate_destination(context, inst_id,
True, False)
self.compute.check_can_live_migrate_destination(context,
block_migration=True, disk_over_commit=False,
instance=inst_ref)
def test_check_can_live_migrate_destination_fails_dest_check(self):
"""Confirm check_can_live_migrate_destination works on positive path"""
context = self.context.elevated()
inst_ref = self._create_fake_instance({'host': 'fake_host_2'})
inst_ref = jsonutils.to_primitive(self._create_fake_instance(
{'host': 'fake_host_2'}))
inst_id = inst_ref["id"]
dest = "fake_host_1"
self.mox.StubOutWithMock(db, 'instance_get')
self.mox.StubOutWithMock(self.compute.driver,
'check_can_live_migrate_destination')
db.instance_get(context, inst_id).AndReturn(inst_ref)
self.compute.driver.check_can_live_migrate_destination(context,
inst_ref, True, False).AndRaise(exception.Invalid())
self.mox.ReplayAll()
self.assertRaises(exception.Invalid,
self.compute.check_can_live_migrate_destination,
context, inst_id, True, False)
context, block_migration=True,
disk_over_commit=False, instance=inst_ref)
def test_check_can_live_migrate_destination_fails_source(self):
"""Confirm check_can_live_migrate_destination works on positive path"""
context = self.context.elevated()
inst_ref = self._create_fake_instance({'host': 'fake_host_2'})
inst_ref = jsonutils.to_primitive(self._create_fake_instance(
{'host': 'fake_host_2'}))
inst_id = inst_ref["id"]
dest = "fake_host_1"
self.mox.StubOutWithMock(db, 'instance_get')
self.mox.StubOutWithMock(self.compute.driver,
'check_can_live_migrate_destination')
self.mox.StubOutWithMock(self.compute.compute_rpcapi,
@ -1485,7 +1485,6 @@ class ComputeTestCase(BaseTestCase):
self.mox.StubOutWithMock(self.compute.driver,
'check_can_live_migrate_destination_cleanup')
db.instance_get(context, inst_id).AndReturn(inst_ref)
dest_check_data = {"test": "data"}
self.compute.driver.check_can_live_migrate_destination(context,
inst_ref, True, False).AndReturn(dest_check_data)
@ -1497,7 +1496,8 @@ class ComputeTestCase(BaseTestCase):
self.mox.ReplayAll()
self.assertRaises(exception.Invalid,
self.compute.check_can_live_migrate_destination,
context, inst_id, True, False)
context, block_migration=True,
disk_over_commit=False, instance=inst_ref)
def test_pre_live_migration_instance_has_no_fixed_ip(self):
"""Confirm raising exception if instance doesn't have fixed_ip."""

View File

@ -49,7 +49,8 @@ class ComputeRpcAPITestCase(test.TestCase):
ctxt = context.RequestContext('fake_user', 'fake_project')
methods_with_instance = [
'add_fixed_ip_to_instance', 'attach_volume', 'get_console_output',
'add_fixed_ip_to_instance', 'attach_volume',
'check_can_live_migrate_destination', 'get_console_output',
'pause_instance', 'reboot_instance', 'suspend_instance',
'unpause_instance'
]
@ -132,8 +133,9 @@ class ComputeRpcAPITestCase(test.TestCase):
def test_check_can_live_migrate_destination(self):
self._test_compute_api('check_can_live_migrate_destination', 'call',
version='1.2', instance=self.fake_instance, destination='dest',
block_migration=True, disk_over_commit=True)
version='1.10', instance=self.fake_instance,
destination='dest', block_migration=True,
disk_over_commit=True)
def test_check_can_live_migrate_source(self):
self._test_compute_api('check_can_live_migrate_source', 'call',

View File

@ -450,7 +450,7 @@ class SchedulerTestCase(test.TestCase):
dest = 'fake_host2'
block_migration = True
disk_over_commit = True
instance = self._live_migration_instance()
instance = jsonutils.to_primitive(self._live_migration_instance())
instance_id = instance['id']
instance_uuid = instance['uuid']
db.instance_get(self.context,
@ -484,10 +484,10 @@ class SchedulerTestCase(test.TestCase):
rpc.call(self.context, "compute.fake_host2",
{"method": 'check_can_live_migrate_destination',
"args": {'instance_id': instance_id,
"args": {'instance': instance,
'block_migration': block_migration,
'disk_over_commit': disk_over_commit},
"version": "1.2"},
"version": "1.10"},
None)
db.instance_update_and_get_original(self.context, instance_uuid,