Send a full instance via rpc for inject_file.
Change the inject_file 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: Ife38a87cb8a597b40b2b87d9a6a8c7e81d4439c4
This commit is contained in:
@@ -298,7 +298,7 @@ def _get_additional_capabilities():
|
||||
class ComputeManager(manager.SchedulerDependentManager):
|
||||
"""Manages the running instances from creation to destruction."""
|
||||
|
||||
RPC_API_VERSION = '1.17'
|
||||
RPC_API_VERSION = '1.18'
|
||||
|
||||
def __init__(self, compute_driver=None, *args, **kwargs):
|
||||
"""Load configuration options and connect to the hypervisor."""
|
||||
@@ -1302,20 +1302,22 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
|
||||
@checks_instance_lock
|
||||
@wrap_instance_fault
|
||||
def inject_file(self, context, instance_uuid, path, file_contents):
|
||||
def inject_file(self, context, path, file_contents, instance_uuid=None,
|
||||
instance=None):
|
||||
"""Write a file to the specified path in an instance on this host."""
|
||||
context = context.elevated()
|
||||
instance_ref = self.db.instance_get_by_uuid(context, instance_uuid)
|
||||
current_power_state = self._get_power_state(context, instance_ref)
|
||||
if not instance:
|
||||
instance = self.db.instance_get_by_uuid(context, instance_uuid)
|
||||
current_power_state = self._get_power_state(context, instance)
|
||||
expected_state = power_state.RUNNING
|
||||
if current_power_state != expected_state:
|
||||
LOG.warn(_('trying to inject a file into a non-running '
|
||||
'(state: %(current_power_state)s '
|
||||
'expected: %(expected_state)s)') % locals(),
|
||||
instance=instance_ref)
|
||||
instance=instance)
|
||||
LOG.audit(_('injecting file to %(path)s') % locals(),
|
||||
instance=instance_ref)
|
||||
self.driver.inject_file(instance_ref, path, file_contents)
|
||||
instance=instance)
|
||||
self.driver.inject_file(instance, path, file_contents)
|
||||
|
||||
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
|
||||
@checks_instance_lock
|
||||
|
||||
@@ -79,6 +79,7 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
|
||||
finish_revert_resize()
|
||||
1.16 - Remove instance_uuid, add instance argument to get_diagnostics()
|
||||
1.17 - Remove instance_uuid, add instance argument to get_vnc_console()
|
||||
1.18 - Remove instance_uuid, add instance argument to inject_file()
|
||||
'''
|
||||
|
||||
BASE_RPC_API_VERSION = '1.0'
|
||||
@@ -215,10 +216,12 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
|
||||
action=action), topic)
|
||||
|
||||
def inject_file(self, ctxt, instance, path, file_contents):
|
||||
instance_p = jsonutils.to_primitive(instance)
|
||||
self.cast(ctxt, self.make_msg('inject_file',
|
||||
instance_uuid=instance['uuid'], path=path,
|
||||
instance=instance, path=path,
|
||||
file_contents=file_contents),
|
||||
topic=_compute_topic(self.topic, ctxt, None, instance))
|
||||
topic=_compute_topic(self.topic, ctxt, None, instance),
|
||||
version='1.18')
|
||||
|
||||
def inject_network_info(self, ctxt, instance):
|
||||
self.cast(ctxt, self.make_msg('inject_network_info',
|
||||
|
||||
@@ -682,10 +682,10 @@ class ComputeTestCase(BaseTestCase):
|
||||
self.stubs.Set(nova.virt.fake.FakeDriver, 'inject_file',
|
||||
fake_driver_inject_file)
|
||||
|
||||
instance = self._create_fake_instance()
|
||||
instance = jsonutils.to_primitive(self._create_fake_instance())
|
||||
self.compute.run_instance(self.context, instance['uuid'])
|
||||
self.compute.inject_file(self.context, instance['uuid'], "/tmp/test",
|
||||
"File Contents")
|
||||
self.compute.inject_file(self.context, "/tmp/test",
|
||||
"File Contents", instance=instance)
|
||||
self.assertTrue(called['inject'])
|
||||
self.compute.terminate_instance(self.context, instance['uuid'])
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ class ComputeRpcAPITestCase(test.TestCase):
|
||||
'check_can_live_migrate_source', 'confirm_resize',
|
||||
'detach_volume', 'finish_resize', 'finish_revert_resize',
|
||||
'get_console_output', 'get_diagnostics', 'get_vnc_console',
|
||||
'inject_file',
|
||||
'pause_instance', 'reboot_instance', 'suspend_instance',
|
||||
'unpause_instance'
|
||||
]
|
||||
@@ -198,7 +199,8 @@ class ComputeRpcAPITestCase(test.TestCase):
|
||||
|
||||
def test_inject_file(self):
|
||||
self._test_compute_api('inject_file', 'cast',
|
||||
instance=self.fake_instance, path='path', file_contents='fc')
|
||||
instance=self.fake_instance, path='path', file_contents='fc',
|
||||
version='1.18')
|
||||
|
||||
def test_inject_network_info(self):
|
||||
self._test_compute_api('inject_network_info', 'cast',
|
||||
|
||||
Reference in New Issue
Block a user