From 643f9d22b5b1b7c0ad9c2f45a78d40d5dafe7f34 Mon Sep 17 00:00:00 2001 From: Naveed Massjouni Date: Wed, 23 Nov 2011 14:30:47 -0500 Subject: Updating set_admin_password in compute.api and compute.manager to use instance uuids instead of instance ids. Blueprint internal-uuids Change-Id: I4c06df9a7148f5223b2925272201c1bc67e4811d --- nova/compute/api.py | 8 +++++--- nova/compute/manager.py | 6 +++--- nova/tests/test_compute.py | 6 ++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/nova/compute/api.py b/nova/compute/api.py index 60a54ae91..67730250e 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1441,7 +1441,7 @@ class API(base.Base): @scheduler_api.reroute_compute("set_admin_password") def set_admin_password(self, context, instance, password=None): """Set the root/admin password for the given instance.""" - instance_id = instance['id'] + instance_uuid = instance['uuid'] self.update(context, instance, task_state=task_states.UPDATING_PASSWORD) @@ -1450,8 +1450,10 @@ class API(base.Base): rpc.cast(context, self.db.queue_get_for(context, FLAGS.compute_topic, host), - {"method": "set_admin_password", - "args": {"instance_id": instance_id, "new_pass": password}}) + { + "method": "set_admin_password", + "args": { + "instance_uuid": instance_uuid, "new_pass": password}}) @scheduler_api.reroute_compute("inject_file") def inject_file(self, context, instance, path, file_contents): diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 2f0b0c71c..1ced5ea54 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -831,8 +831,8 @@ class ComputeManager(manager.SchedulerDependentManager): image_service.delete(context, image_id) @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) - @checks_instance_lock - def set_admin_password(self, context, instance_id, new_pass=None): + @checks_instance_lock_uuid + def set_admin_password(self, context, instance_uuid, new_pass=None): """Set the root/admin password for an instance on this host. This is generally only called by API password resets after an @@ -848,7 +848,7 @@ class ComputeManager(manager.SchedulerDependentManager): max_tries = 10 for i in xrange(max_tries): - instance_ref = self.db.instance_get(context, instance_id) + instance_ref = self.db.instance_get_by_uuid(context, instance_uuid) instance_id = instance_ref["id"] instance_state = instance_ref["power_state"] expected_state = power_state.RUNNING diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 20db94f4e..365527223 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -300,7 +300,9 @@ class ComputeTestCase(BaseTestCase): def test_set_admin_password(self): """Ensure instance can have its admin password set""" - instance_id = self._create_instance() + instance = self._create_fake_instance() + instance_id = instance['id'] + instance_uuid = instance['uuid'] self.compute.run_instance(self.context, instance_id) db.instance_update(self.context, instance_id, {'task_state': task_states.UPDATING_PASSWORD}) @@ -309,7 +311,7 @@ class ComputeTestCase(BaseTestCase): self.assertEqual(inst_ref['vm_state'], vm_states.ACTIVE) self.assertEqual(inst_ref['task_state'], task_states.UPDATING_PASSWORD) - self.compute.set_admin_password(self.context, instance_id) + self.compute.set_admin_password(self.context, instance_uuid) inst_ref = db.instance_get(self.context, instance_id) self.assertEqual(inst_ref['vm_state'], vm_states.ACTIVE) -- cgit