From 5d8868a4d58122dce6fdc81fa0ed17ae7fc55672 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 4 Feb 2013 12:12:43 -0500 Subject: Refactor server password metadata to avoid direct db usage This refactors the set_password() method in the server_password API extension to merely format the metadata and return it, leaving the job of updating the database to the caller. In the API extension case, the update can be done immediately against the database as before. In the case of the metadata API handler and the xenapi virt driver making the call, conductor can be used to update the instance's system_metadata, thereby avoiding a direct database access. Related to blueprint no-db-compute Change-Id: I0563feaa97d768a96f950c148b1dbf51c356c4ac --- .../api/openstack/compute/contrib/test_server_password.py | 5 +++-- nova/tests/test_metadata.py | 13 +++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/compute/contrib/test_server_password.py b/nova/tests/api/openstack/compute/contrib/test_server_password.py index 600c4eda4..87da90efe 100644 --- a/nova/tests/api/openstack/compute/contrib/test_server_password.py +++ b/nova/tests/api/openstack/compute/contrib/test_server_password.py @@ -40,11 +40,12 @@ class ServerPasswordTest(test.TestCase): def fake_extract_password(instance): return self.password - def fake_set_password(context, instance_uuid, password): + def fake_convert_password(context, password): self.password = password + return {} self.stubs.Set(password, 'extract_password', fake_extract_password) - self.stubs.Set(password, 'set_password', fake_set_password) + self.stubs.Set(password, 'convert_password', fake_convert_password) self.flags( osapi_compute_extension=[ 'nova.api.openstack.compute.contrib.select_extensions'], diff --git a/nova/tests/test_metadata.py b/nova/tests/test_metadata.py index f610cd6fc..827bfb398 100644 --- a/nova/tests/test_metadata.py +++ b/nova/tests/test_metadata.py @@ -549,6 +549,7 @@ class MetadataPasswordTestCase(test.TestCase): self.instance = copy.copy(INSTANCES[0]) self.mdinst = fake_InstanceMetadata(self.stubs, self.instance, address=None, sgroups=None) + self.flags(use_local=True, group='conductor') def test_get_password(self): request = webob.Request.blank('') @@ -566,8 +567,16 @@ class MetadataPasswordTestCase(test.TestCase): request = webob.Request.blank('') request.method = 'POST' request.body = val - self.stubs.Set(db, 'instance_system_metadata_update', - lambda *a, **kw: None) + self.stubs.Set(db, 'instance_get_by_uuid', + lambda *a, **kw: {'system_metadata': []}) + + def fake_instance_update(context, uuid, updates): + self.assertIn('system_metadata', updates) + self.assertIn('password_0', updates['system_metadata']) + return self.instance, self.instance + + self.stubs.Set(db, 'instance_update_and_get_original', + fake_instance_update) password.handle_password(request, self.mdinst) def test_set_password(self): -- cgit