diff options
| author | Jenkins <jenkins@review.openstack.org> | 2011-11-29 21:05:56 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2011-11-29 21:05:56 +0000 |
| commit | a668c6c7fdd50758a109d7eddeb24bf17575b010 (patch) | |
| tree | d518fdd27fb6c92a7ed67de1633c8f1fb7b448ca | |
| parent | 80d832b39b937e41685b6ae3f6c4e06238b80d6d (diff) | |
| parent | a57bc7e99499f39e4eb31265983d75a9b09e1932 (diff) | |
Merge "Use uuids for file injection."
| -rw-r--r-- | nova/compute/api.py | 3 | ||||
| -rw-r--r-- | nova/compute/manager.py | 9 | ||||
| -rw-r--r-- | 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 09fcbc85a..d42857d36 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 90ff71ccb..d0793d020 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 02c8698cb..861c611ae 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -406,11 +406,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""" |
