Send a full instance via rpc for finish_revert_resize.

Change the finish_revert_resize method of the compute rpc API to take
a full instance over rpc instead of just the instance UUID.
This cuts down on database access needed by nova-compute.

Part of blueprint no-db-messaging.

Change-Id: Ibe2f8b990cc8f2a3d05e8ba8216a1e74cbcfb67b
This commit is contained in:
Russell Bryant
2012-07-26 12:56:46 -04:00
parent 151017385a
commit eba4be81a1
4 changed files with 24 additions and 15 deletions

View File

@@ -298,7 +298,7 @@ def _get_additional_capabilities():
class ComputeManager(manager.SchedulerDependentManager):
"""Manages the running instances from creation to destruction."""
RPC_API_VERSION = '1.14'
RPC_API_VERSION = '1.15'
def __init__(self, compute_driver=None, *args, **kwargs):
"""Load configuration options and connect to the hypervisor."""
@@ -1449,7 +1449,8 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
@checks_instance_lock
@wrap_instance_fault
def finish_revert_resize(self, context, instance_uuid, migration_id):
def finish_revert_resize(self, context, migration_id, instance_uuid=None,
instance=None):
"""Finishes the second half of reverting a resize.
Power back on the source instance and revert the resized attributes
@@ -1457,23 +1458,24 @@ class ComputeManager(manager.SchedulerDependentManager):
"""
migration_ref = self.db.migration_get(context, migration_id)
instance_ref = self.db.instance_get_by_uuid(context,
migration_ref.instance_uuid)
network_info = self._get_instance_nw_info(context, instance_ref)
if not instance:
instance = self.db.instance_get_by_uuid(context,
migration_ref.instance_uuid)
network_info = self._get_instance_nw_info(context, instance)
self._notify_about_instance_usage(
context, instance_ref, "resize.revert.start")
context, instance, "resize.revert.start")
old_instance_type = migration_ref['old_instance_type_id']
instance_type = instance_types.get_instance_type(old_instance_type)
self.driver.finish_revert_migration(instance_ref,
self.driver.finish_revert_migration(instance,
self._legacy_nw_info(network_info))
# Just roll back the record. There's no need to resize down since
# the 'old' VM already has the preferred attributes
self._instance_update(context,
instance_ref['uuid'],
instance['uuid'],
memory_mb=instance_type['memory_mb'],
host=migration_ref['source_compute'],
vcpus=instance_type['vcpus'],
@@ -1488,7 +1490,7 @@ class ComputeManager(manager.SchedulerDependentManager):
{'status': 'reverted'})
self._notify_about_instance_usage(
context, instance_ref, "resize.revert.end")
context, instance, "resize.revert.end")
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
@checks_instance_lock

View File

@@ -75,6 +75,8 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
1.12 - Remove instance_uuid, add instance argument to confirm_resize()
1.13 - Remove instance_uuid, add instance argument to detach_volume()
1.14 - Remove instance_uuid, add instance argument to finish_resize()
1.15 - Remove instance_uuid, add instance argument to
finish_revert_resize()
'''
BASE_RPC_API_VERSION = '1.0'
@@ -156,9 +158,11 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
version='1.14')
def finish_revert_resize(self, ctxt, instance, migration_id, host):
instance_p = jsonutils.to_primitive(instance)
self.cast(ctxt, self.make_msg('finish_revert_resize',
instance_uuid=instance['uuid'], migration_id=migration_id),
topic=_compute_topic(self.topic, ctxt, host, None))
instance=instance_p, migration_id=migration_id),
topic=_compute_topic(self.topic, ctxt, host, None),
version='1.15')
def get_console_output(self, ctxt, instance, tail_length):
instance_p = jsonutils.to_primitive(instance)

View File

@@ -1376,8 +1376,9 @@ class ComputeTestCase(BaseTestCase):
# Finally, revert and confirm the old flavor has been applied
self.compute.revert_resize(context, inst_ref['uuid'],
migration_ref['id'])
self.compute.finish_revert_resize(context, inst_ref['uuid'],
migration_ref['id'])
self.compute.finish_revert_resize(context,
migration_id=migration_ref['id'],
instance=jsonutils.to_primitive(inst_ref))
instance = db.instance_get_by_uuid(context, instance['uuid'])
self.assertEqual(instance['vm_state'], vm_states.ACTIVE)

View File

@@ -52,7 +52,8 @@ class ComputeRpcAPITestCase(test.TestCase):
'add_fixed_ip_to_instance', 'attach_volume',
'check_can_live_migrate_destination',
'check_can_live_migrate_source', 'confirm_resize',
'detach_volume', 'finish_resize', 'get_console_output',
'detach_volume', 'finish_resize', 'finish_revert_resize',
'get_console_output',
'pause_instance', 'reboot_instance', 'suspend_instance',
'unpause_instance'
]
@@ -166,7 +167,8 @@ class ComputeRpcAPITestCase(test.TestCase):
def test_finish_revert_resize(self):
self._test_compute_api('finish_revert_resize', 'cast',
instance=self.fake_instance, migration_id='id', host='host')
instance=self.fake_instance, migration_id='id', host='host',
version='1.15')
def test_get_console_output(self):
self._test_compute_api('get_console_output', 'call',