Improve error logs for start/stop of locked instance
If someone tries to execute a command on a locked instance, we want them to get the more explicit "Instance <uuid> is locked" message instead of the more generic "Instance <uuid> is in an invalid state for <action>" message. exception.InstanceIsLocked is a subclass of exception.InstanceInvalidState, so we need to check for the more specific case first. Change-Id: I33553e1a534a9aa1394a3927d745196476067c9d
This commit is contained in:
@@ -46,11 +46,11 @@ class ServerStartStopActionController(wsgi.Controller):
|
||||
|
||||
try:
|
||||
self.compute_api.start(context, instance)
|
||||
except (exception.InstanceNotReady, exception.InstanceIsLocked) as e:
|
||||
raise webob.exc.HTTPConflict(explanation=e.format_message())
|
||||
except exception.InstanceInvalidState as state_error:
|
||||
common.raise_http_conflict_for_instance_invalid_state(state_error,
|
||||
'start', id)
|
||||
except (exception.InstanceNotReady, exception.InstanceIsLocked) as e:
|
||||
raise webob.exc.HTTPConflict(explanation=e.format_message())
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@wsgi.action('os-stop')
|
||||
@@ -62,11 +62,11 @@ class ServerStartStopActionController(wsgi.Controller):
|
||||
|
||||
try:
|
||||
self.compute_api.stop(context, instance)
|
||||
except (exception.InstanceNotReady, exception.InstanceIsLocked) as e:
|
||||
raise webob.exc.HTTPConflict(explanation=e.format_message())
|
||||
except exception.InstanceInvalidState as state_error:
|
||||
common.raise_http_conflict_for_instance_invalid_state(state_error,
|
||||
'stop', id)
|
||||
except (exception.InstanceNotReady, exception.InstanceIsLocked) as e:
|
||||
raise webob.exc.HTTPConflict(explanation=e.format_message())
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
|
||||
|
||||
@@ -1096,11 +1096,11 @@ class ServersController(wsgi.Controller):
|
||||
LOG.debug('start instance', instance=instance)
|
||||
try:
|
||||
self.compute_api.start(context, instance)
|
||||
except (exception.InstanceNotReady, exception.InstanceIsLocked) as e:
|
||||
raise webob.exc.HTTPConflict(explanation=e.format_message())
|
||||
except exception.InstanceInvalidState as state_error:
|
||||
common.raise_http_conflict_for_instance_invalid_state(state_error,
|
||||
'start', id)
|
||||
except (exception.InstanceNotReady, exception.InstanceIsLocked) as e:
|
||||
raise webob.exc.HTTPConflict(explanation=e.format_message())
|
||||
|
||||
@wsgi.response(202)
|
||||
@extensions.expected_errors((404, 409))
|
||||
@@ -1113,11 +1113,11 @@ class ServersController(wsgi.Controller):
|
||||
LOG.debug('stop instance', instance=instance)
|
||||
try:
|
||||
self.compute_api.stop(context, instance)
|
||||
except (exception.InstanceNotReady, exception.InstanceIsLocked) as e:
|
||||
raise webob.exc.HTTPConflict(explanation=e.format_message())
|
||||
except exception.InstanceInvalidState as state_error:
|
||||
common.raise_http_conflict_for_instance_invalid_state(state_error,
|
||||
'stop', id)
|
||||
except (exception.InstanceNotReady, exception.InstanceIsLocked) as e:
|
||||
raise webob.exc.HTTPConflict(explanation=e.format_message())
|
||||
|
||||
|
||||
def remove_invalid_options(context, search_options, allowed_search_options):
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
from mox3 import mox
|
||||
import six
|
||||
import webob
|
||||
|
||||
from nova.api.openstack.compute import extension_info
|
||||
@@ -107,8 +108,9 @@ class ServerStartStopTestV21(test.TestCase):
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get)
|
||||
self.stubs.Set(compute_api.API, 'start', fake_start_stop_invalid_state)
|
||||
body = dict(start="")
|
||||
self.assertRaises(webob.exc.HTTPConflict,
|
||||
ex = self.assertRaises(webob.exc.HTTPConflict,
|
||||
self.controller._start_server, self.req, 'test_inst', body)
|
||||
self.assertIn('is locked', six.text_type(ex))
|
||||
|
||||
def test_stop(self):
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get)
|
||||
@@ -143,8 +145,9 @@ class ServerStartStopTestV21(test.TestCase):
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get)
|
||||
self.stubs.Set(compute_api.API, 'stop', fake_start_stop_locked_server)
|
||||
body = dict(stop="")
|
||||
self.assertRaises(webob.exc.HTTPConflict,
|
||||
ex = self.assertRaises(webob.exc.HTTPConflict,
|
||||
self.controller._stop_server, self.req, 'test_inst', body)
|
||||
self.assertIn('is locked', six.text_type(ex))
|
||||
|
||||
def test_stop_invalid_state(self):
|
||||
self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get)
|
||||
|
||||
Reference in New Issue
Block a user