From 702fdf2fc1acc32b5ccd9e0830e574c42770ab5d Mon Sep 17 00:00:00 2001 From: Zhou ShaoYu Date: Tue, 5 Feb 2013 14:42:53 +0800 Subject: Fix check instance host for instance action When instance has no host, actions such as get_console_output, start_stop_instance cause HTTP 500 response. Here change to HTTPConflict when action called before host set. Fix LP# 1116012 Change-Id: I6153a03f449d9fad8d0d8fb7295bdea4d2b2c2b1 --- nova/api/openstack/compute/contrib/console_output.py | 2 ++ nova/api/openstack/compute/contrib/server_start_stop.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/console_output.py b/nova/api/openstack/compute/contrib/console_output.py index 953459d38..b734cbd13 100644 --- a/nova/api/openstack/compute/contrib/console_output.py +++ b/nova/api/openstack/compute/contrib/console_output.py @@ -65,6 +65,8 @@ class ConsoleOutputController(wsgi.Controller): length) except exception.NotFound: raise webob.exc.HTTPNotFound(_('Unable to get console')) + except exception.InstanceNotReady as e: + raise webob.exc.HTTPConflict(explanation=unicode(e)) # XML output is not correctly escaped, so remove invalid characters remove_re = re.compile('[\x00-\x08\x0B-\x0C\x0E-\x1F]') diff --git a/nova/api/openstack/compute/contrib/server_start_stop.py b/nova/api/openstack/compute/contrib/server_start_stop.py index 733972083..a13aabb05 100644 --- a/nova/api/openstack/compute/contrib/server_start_stop.py +++ b/nova/api/openstack/compute/contrib/server_start_stop.py @@ -44,7 +44,10 @@ class ServerStartStopActionController(wsgi.Controller): context = req.environ['nova.context'] instance = self._get_instance(context, id) LOG.debug(_('start instance'), instance=instance) - self.compute_api.start(context, instance) + try: + self.compute_api.start(context, instance) + except exception.InstanceNotReady as e: + raise webob.exc.HTTPConflict(explanation=unicode(e)) return webob.Response(status_int=202) @wsgi.action('os-stop') @@ -53,7 +56,10 @@ class ServerStartStopActionController(wsgi.Controller): context = req.environ['nova.context'] instance = self._get_instance(context, id) LOG.debug(_('stop instance'), instance=instance) - self.compute_api.stop(context, instance) + try: + self.compute_api.stop(context, instance) + except exception.InstanceNotReady as e: + raise webob.exc.HTTPConflict(explanation=unicode(e)) return webob.Response(status_int=202) -- cgit