From 82f0c41bda374188482d7a44a65e7dbb7895ee32 Mon Sep 17 00:00:00 2001 From: He Jie Xu Date: Tue, 12 Aug 2014 11:02:46 +0800 Subject: [PATCH] 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 --- nova/api/openstack/compute/contrib/consoles.py | 16 +++++++--------- .../openstack/compute/contrib/test_consoles.py | 6 ++++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/nova/api/openstack/compute/contrib/consoles.py b/nova/api/openstack/compute/contrib/consoles.py index 3d5ed58b6b32..91d3305d41e5 100644 --- a/nova/api/openstack/compute/contrib/consoles.py +++ b/nova/api/openstack/compute/contrib/consoles.py @@ -14,6 +14,7 @@ import webob +from nova.api.openstack import common from nova.api.openstack import extensions from nova.api.openstack import wsgi 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 console_type = body['os-getVNCConsole'].get('type') + instance = common.get_instance(self.compute_api, context, id, + want_objects=True) try: - instance = self.compute_api.get(context, id, want_objects=True) output = self.compute_api.get_vnc_console(context, instance, console_type) - except exception.InstanceNotFound as e: - raise webob.exc.HTTPNotFound(explanation=e.format_message()) except exception.InstanceNotReady as e: raise webob.exc.HTTPConflict( 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 console_type = body['os-getSPICEConsole'].get('type') + instance = common.get_instance(self.compute_api, context, id, + want_objects=True) try: - instance = self.compute_api.get(context, id, want_objects=True) output = self.compute_api.get_spice_console(context, instance, console_type) except exception.ConsoleTypeUnavailable as e: 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: raise webob.exc.HTTPConflict(explanation=e.format_message()) except NotImplementedError: @@ -91,16 +90,15 @@ class ConsolesController(wsgi.Controller): # If type is not supplied or unknown, get_rdp_console below will cope console_type = body['os-getRDPConsole'].get('type') + instance = common.get_instance(self.compute_api, context, id, + want_objects=True) try: - instance = self.compute_api.get(context, id, want_objects=True) output = self.compute_api.get_rdp_console(context, instance, console_type) except exception.ConsoleTypeUnavailable as e: 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: raise webob.exc.HTTPConflict(explanation=e.format_message()) except NotImplementedError: diff --git a/nova/tests/api/openstack/compute/contrib/test_consoles.py b/nova/tests/api/openstack/compute/contrib/test_consoles.py index 9ed7d0f05f30..9fbc813499af 100644 --- a/nova/tests/api/openstack/compute/contrib/test_consoles.py +++ b/nova/tests/api/openstack/compute/contrib/test_consoles.py @@ -88,11 +88,13 @@ def fake_get_rdp_console_not_found(self, _context, instance, _console_type): 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} -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)