From a57bc7e99499f39e4eb31265983d75a9b09e1932 Mon Sep 17 00:00:00 2001 From: Mark Washenberger Date: Mon, 28 Nov 2011 16:26:36 -0500 Subject: Use uuids for file injection. Related to blueprint internal-uuids. Change-Id: I35f2a4c5cafde7ed8831a01cb7a2816ccbc39808 --- nova/compute/api.py | 3 +-- nova/compute/manager.py | 9 ++++----- nova/tests/test_compute.py | 19 +++++++++++++++---- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/nova/compute/api.py b/nova/compute/api.py index 32f329a04..a55cc142a 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1448,10 +1448,9 @@ class API(base.Base): @scheduler_api.reroute_compute("inject_file") def inject_file(self, context, instance, path, file_contents): """Write a file to the given instance.""" - instance_id = instance['id'] params = {'path': path, 'file_contents': file_contents} self._cast_compute_message('inject_file', context, - instance_id, params=params) + instance['uuid'], params=params) def get_ajax_console(self, context, instance): """Get a url to an AJAX Console.""" diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 2eed738c1..905d43968 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -903,17 +903,16 @@ class ComputeManager(manager.SchedulerDependentManager): continue @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) - @checks_instance_lock - def inject_file(self, context, instance_id, path, file_contents): + @checks_instance_lock_uuid + def inject_file(self, context, instance_uuid, path, file_contents): """Write a file to the specified path in an instance on this host.""" context = context.elevated() - instance_ref = self.db.instance_get(context, instance_id) - instance_id = instance_ref['id'] + instance_ref = self.db.instance_get_by_uuid(context, instance_uuid) instance_state = instance_ref['power_state'] expected_state = power_state.RUNNING if instance_state != expected_state: LOG.warn(_('trying to inject a file into a non-running ' - 'instance: %(instance_id)s (state: %(instance_state)s ' + 'instance: %(instance_uuid)s (state: %(instance_state)s ' 'expected: %(expected_state)s)') % locals()) nm = instance_ref['name'] msg = _('instance %(nm)s: injecting file to %(path)s') % locals() diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index f03665d57..e829456b7 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -352,11 +352,22 @@ class ComputeTestCase(BaseTestCase): def test_inject_file(self): """Ensure we can write a file to an instance""" - instance_id = self._create_instance() - self.compute.run_instance(self.context, instance_id) - self.compute.inject_file(self.context, instance_id, "/tmp/test", + called = {'inject': False} + + def fake_driver_inject_file(self2, instance, path, contents): + self.assertEqual(path, "/tmp/test") + self.assertEqual(contents, "File Contents") + called['inject'] = True + + self.stubs.Set(nova.virt.fake.FakeConnection, 'inject_file', + fake_driver_inject_file) + + instance = self._create_fake_instance() + self.compute.run_instance(self.context, instance['id']) + self.compute.inject_file(self.context, instance['uuid'], "/tmp/test", "File Contents") - self.compute.terminate_instance(self.context, instance_id) + self.assertTrue(called['inject']) + self.compute.terminate_instance(self.context, instance['id']) def test_inject_network_info(self): """Ensure we can inject network info""" -- cgit