diff options
author | Chris Yeoh <cyeoh@au1.ibm.com> | 2014-06-26 16:34:57 +0930 |
---|---|---|
committer | Chris Yeoh <cyeoh@au1.ibm.com> | 2014-06-26 17:15:54 +0930 |
commit | e06cd36bf8145b3b75ae866d323f231a1ab59c95 (patch) | |
tree | 6bb23d766e0e58d5ffb51178ac8eba5e490f4434 /nova | |
parent | 383caeb88901d862d43881f277898d48b9a83a53 (diff) | |
download | nova-e06cd36bf8145b3b75ae866d323f231a1ab59c95.tar.gz |
Fix exception raised when a requested console type is disabled
The get_{vnc/rdp/spice}_console calls should raise
ConsoleTypeUnavailable not ConsoleTypeInvalid when the
corresponding console is disabled (rather than supplying an
invalid subtype).
Also removes exception handling of ConsoleTypeInvalid from the
os-remote-consoles V3 API plugin as the schema validation ensures
the input passed to nova internals is valid.
Change-Id: Ia444775ff6ec1d869d810bc689914efb8cd233a4
Diffstat (limited to 'nova')
-rw-r--r-- | nova/api/openstack/compute/plugins/v3/remote_consoles.py | 6 | ||||
-rw-r--r-- | nova/compute/manager.py | 6 | ||||
-rw-r--r-- | nova/tests/compute/test_compute.py | 33 |
3 files changed, 36 insertions, 9 deletions
diff --git a/nova/api/openstack/compute/plugins/v3/remote_consoles.py b/nova/api/openstack/compute/plugins/v3/remote_consoles.py index d57c3a8434..7d8310f38c 100644 --- a/nova/api/openstack/compute/plugins/v3/remote_consoles.py +++ b/nova/api/openstack/compute/plugins/v3/remote_consoles.py @@ -50,8 +50,6 @@ class RemoteConsolesController(wsgi.Controller): output = self.compute_api.get_vnc_console(context, instance, console_type) - except exception.ConsoleTypeInvalid as e: - raise webob.exc.HTTPBadRequest(explanation=e.format_message()) except exception.ConsoleTypeUnavailable as e: raise webob.exc.HTTPBadRequest(explanation=e.format_message()) except exception.InstanceNotFound as e: @@ -81,8 +79,6 @@ class RemoteConsolesController(wsgi.Controller): output = self.compute_api.get_spice_console(context, instance, console_type) - except exception.ConsoleTypeInvalid as e: - raise webob.exc.HTTPBadRequest(explanation=e.format_message()) except exception.ConsoleTypeUnavailable as e: raise webob.exc.HTTPBadRequest(explanation=e.format_message()) except exception.InstanceNotFound as e: @@ -115,8 +111,6 @@ class RemoteConsolesController(wsgi.Controller): output = self.compute_api.get_rdp_console(context, instance, console_type) - except exception.ConsoleTypeInvalid as e: - raise webob.exc.HTTPBadRequest(explanation=e.format_message()) except exception.ConsoleTypeUnavailable as e: raise webob.exc.HTTPBadRequest(explanation=e.format_message()) except exception.InstanceNotFound as e: diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 3fd0316310..c1120bb266 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -4035,7 +4035,7 @@ class ComputeManager(manager.Manager): token = str(uuid.uuid4()) if not CONF.vnc_enabled: - raise exception.ConsoleTypeInvalid(console_type=console_type) + raise exception.ConsoleTypeUnavailable(console_type=console_type) if console_type == 'novnc': # For essex, novncproxy_base_url must include the full path @@ -4073,7 +4073,7 @@ class ComputeManager(manager.Manager): token = str(uuid.uuid4()) if not CONF.spice.enabled: - raise exception.ConsoleTypeInvalid(console_type=console_type) + raise exception.ConsoleTypeUnavailable(console_type=console_type) if console_type == 'spice-html5': # For essex, spicehtml5proxy_base_url must include the full path @@ -4111,7 +4111,7 @@ class ComputeManager(manager.Manager): token = str(uuid.uuid4()) if not CONF.rdp.enabled: - raise exception.ConsoleTypeInvalid(console_type=console_type) + raise exception.ConsoleTypeUnavailable(console_type=console_type) if console_type == 'rdp-html5': access_url = '%s?token=%s' % (CONF.rdp.html5_proxy_base_url, diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 81db6ef1d1..f5abd6b8dc 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -3274,6 +3274,39 @@ class ComputeTestCase(BaseTestCase): self.compute.get_rdp_console, self.context, 'rdp-html5', instance=instance) + def test_vnc_console_disabled(self): + self.flags(vnc_enabled=False) + instance = self._create_fake_instance_obj( + params={'vm_state': vm_states.BUILDING}) + + self.compute = utils.ExceptionHelper(self.compute) + + self.assertRaises(exception.ConsoleTypeUnavailable, + self.compute.get_vnc_console, self.context, 'novnc', + instance=instance) + + def test_spice_console_disabled(self): + self.flags(enabled=False, group='spice') + instance = self._create_fake_instance_obj( + params={'vm_state': vm_states.BUILDING}) + + self.compute = utils.ExceptionHelper(self.compute) + + self.assertRaises(exception.ConsoleTypeUnavailable, + self.compute.get_spice_console, self.context, 'spice-html5', + instance=instance) + + def test_rdp_console_disabled(self): + self.flags(enabled=False, group='rdp') + instance = self._create_fake_instance_obj( + params={'vm_state': vm_states.BUILDING}) + + self.compute = utils.ExceptionHelper(self.compute) + + self.assertRaises(exception.ConsoleTypeUnavailable, + self.compute.get_rdp_console, self.context, 'rdp-html5', + instance=instance) + def test_diagnostics(self): # Make sure we can get diagnostics for an instance. expected_diagnostic = {'cpu0_time': 17300000000, |