diff options
| -rw-r--r-- | nova/compute/manager.py | 16 | ||||
| -rw-r--r-- | nova/compute/rpcapi.py | 7 | ||||
| -rw-r--r-- | nova/tests/compute/test_compute.py | 6 | ||||
| -rw-r--r-- | nova/tests/compute/test_rpcapi.py | 4 |
4 files changed, 20 insertions, 13 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 7ae875430..9461faf52 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -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 diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py index 6382716ad..70747e5cc 100644 --- a/nova/compute/rpcapi.py +++ b/nova/compute/rpcapi.py @@ -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', diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index e6bc8547f..c6d349057 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -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']) diff --git a/nova/tests/compute/test_rpcapi.py b/nova/tests/compute/test_rpcapi.py index 2bbb7e665..fd4b5eb4e 100644 --- a/nova/tests/compute/test_rpcapi.py +++ b/nova/tests/compute/test_rpcapi.py @@ -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', |
