Use common get_instance function in v2 consoles extension

This patch use common get_instance function in v2 consoles extension.
That can make the instance behavior consistent with v2.1 api. Then
v2.1 and v2 can share same unittest.

Change-Id: Idf501be21178c3c97b1693e48d3fd13b97525299
This commit is contained in:
He Jie Xu 2014-08-12 11:02:46 +08:00
parent 680c4430e6
commit 82f0c41bda
2 changed files with 11 additions and 11 deletions
nova
api/openstack/compute/contrib
tests/api/openstack/compute/contrib

@ -14,6 +14,7 @@
import webob import webob
from nova.api.openstack import common
from nova.api.openstack import extensions from nova.api.openstack import extensions
from nova.api.openstack import wsgi from nova.api.openstack import wsgi
from nova import compute from nova import compute
@ -37,14 +38,13 @@ class ConsolesController(wsgi.Controller):
# If type is not supplied or unknown, get_vnc_console below will cope # If type is not supplied or unknown, get_vnc_console below will cope
console_type = body['os-getVNCConsole'].get('type') console_type = body['os-getVNCConsole'].get('type')
instance = common.get_instance(self.compute_api, context, id,
want_objects=True)
try: try:
instance = self.compute_api.get(context, id, want_objects=True)
output = self.compute_api.get_vnc_console(context, output = self.compute_api.get_vnc_console(context,
instance, instance,
console_type) console_type)
except exception.InstanceNotFound as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceNotReady as e: except exception.InstanceNotReady as e:
raise webob.exc.HTTPConflict( raise webob.exc.HTTPConflict(
explanation=_('Instance not yet ready')) explanation=_('Instance not yet ready'))
@ -64,16 +64,15 @@ class ConsolesController(wsgi.Controller):
# If type is not supplied or unknown, get_spice_console below will cope # If type is not supplied or unknown, get_spice_console below will cope
console_type = body['os-getSPICEConsole'].get('type') console_type = body['os-getSPICEConsole'].get('type')
instance = common.get_instance(self.compute_api, context, id,
want_objects=True)
try: try:
instance = self.compute_api.get(context, id, want_objects=True)
output = self.compute_api.get_spice_console(context, output = self.compute_api.get_spice_console(context,
instance, instance,
console_type) console_type)
except exception.ConsoleTypeUnavailable as e: except exception.ConsoleTypeUnavailable as e:
raise webob.exc.HTTPBadRequest(explanation=e.format_message()) raise webob.exc.HTTPBadRequest(explanation=e.format_message())
except exception.InstanceNotFound as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceNotReady as e: except exception.InstanceNotReady as e:
raise webob.exc.HTTPConflict(explanation=e.format_message()) raise webob.exc.HTTPConflict(explanation=e.format_message())
except NotImplementedError: except NotImplementedError:
@ -91,16 +90,15 @@ class ConsolesController(wsgi.Controller):
# If type is not supplied or unknown, get_rdp_console below will cope # If type is not supplied or unknown, get_rdp_console below will cope
console_type = body['os-getRDPConsole'].get('type') console_type = body['os-getRDPConsole'].get('type')
instance = common.get_instance(self.compute_api, context, id,
want_objects=True)
try: try:
instance = self.compute_api.get(context, id, want_objects=True)
output = self.compute_api.get_rdp_console(context, output = self.compute_api.get_rdp_console(context,
instance, instance,
console_type) console_type)
except exception.ConsoleTypeUnavailable as e: except exception.ConsoleTypeUnavailable as e:
raise webob.exc.HTTPBadRequest(explanation=e.format_message()) raise webob.exc.HTTPBadRequest(explanation=e.format_message())
except exception.InstanceNotFound as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceNotReady as e: except exception.InstanceNotReady as e:
raise webob.exc.HTTPConflict(explanation=e.format_message()) raise webob.exc.HTTPConflict(explanation=e.format_message())
except NotImplementedError: except NotImplementedError:

@ -88,11 +88,13 @@ def fake_get_rdp_console_not_found(self, _context, instance, _console_type):
raise exception.InstanceNotFound(instance_id=instance["uuid"]) raise exception.InstanceNotFound(instance_id=instance["uuid"])
def fake_get(self, context, instance_uuid, want_objects=False): def fake_get(self, context, instance_uuid, want_objects=False,
expected_attrs=None):
return {'uuid': instance_uuid} return {'uuid': instance_uuid}
def fake_get_not_found(self, context, instance_uuid, want_objects=False): def fake_get_not_found(self, context, instance_uuid, want_objects=False,
expected_attrs=None):
raise exception.InstanceNotFound(instance_id=instance_uuid) raise exception.InstanceNotFound(instance_id=instance_uuid)