Object-ify server_password APIv2 extension

This makes the server_password extension use the Instance object
instead of direct database access.

Related to blueprint compute-manager-objects-juno

Change-Id: I54f7762d14868278ef72589a8c6e3fc80c0e48c8
This commit is contained in:
Dan Smith 2014-06-17 11:36:44 -07:00
parent 5ace1c27b4
commit 1f3ad72829
2 changed files with 11 additions and 5 deletions

View File

@ -22,7 +22,6 @@ from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova import compute
from nova import db
from nova import exception
@ -43,7 +42,7 @@ class ServerPasswordController(object):
def _get_instance(self, context, server_id):
try:
return self.compute_api.get(context, server_id)
return self.compute_api.get(context, server_id, want_objects=True)
except exception.InstanceNotFound as exp:
raise webob.exc.HTTPNotFound(explanation=exp.format_message())
@ -62,8 +61,8 @@ class ServerPasswordController(object):
authorize(context)
instance = self._get_instance(context, server_id)
meta = password.convert_password(context, None)
db.instance_system_metadata_update(context, instance['uuid'],
meta, False)
instance.system_metadata.update(meta)
instance.save()
class Server_password(extensions.ExtensionDescriptor):

View File

@ -22,6 +22,7 @@ from nova import compute
from nova.openstack.common import jsonutils
from nova import test
from nova.tests.api.openstack import fakes
from nova.tests import fake_instance
CONF = cfg.CONF
@ -34,7 +35,13 @@ class ServerPasswordTest(test.TestCase):
def setUp(self):
super(ServerPasswordTest, self).setUp()
fakes.stub_out_nw_api(self.stubs)
self.stubs.Set(compute.api.API, 'get', lambda *a, **kw: {'uuid': ''})
self.stubs.Set(
compute.api.API, 'get',
lambda self, ctxt, *a, **kw:
fake_instance.fake_instance_obj(
ctxt,
system_metadata={},
expected_attrs=['system_metadata']))
self.password = 'fakepass'
def fake_extract_password(instance):