Skip to content

Commit

Permalink
Fix unrescue in invalid state
Browse files Browse the repository at this point in the history
Fixes bug 965667

Unrescue did not check for InstanceInvalidState exception and return the
appropriate error.

Change-Id: I3ca2c1dae09bd149086bfe67e2233c8359d5c8f8
  • Loading branch information
Johannes Erdfelt committed Mar 26, 2012
1 parent 3433fd6 commit 575ad8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nova/api/openstack/compute/contrib/rescue.py
Expand Up @@ -72,7 +72,11 @@ def _unrescue(self, req, id, body):
context = req.environ["nova.context"]
authorize(context)
instance = self._get_instance(context, id)
self.compute_api.unrescue(context, instance)
try:
self.compute_api.unrescue(context, instance)
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'unrescue')
return webob.Response(status_int=202)


Expand Down
15 changes: 15 additions & 0 deletions nova/tests/api/openstack/compute/contrib/test_rescue.py
Expand Up @@ -93,3 +93,18 @@ def test_unrescue(self):

resp = req.get_response(fakes.wsgi_app())
self.assertEqual(resp.status_int, 202)

def test_unrescue_of_active_instance(self):
body = dict(unrescue=None)

def fake_unrescue(*args, **kwargs):
raise exception.InstanceInvalidState('fake message')

self.stubs.Set(compute.api.API, "unrescue", fake_unrescue)
req = webob.Request.blank('/v2/fake/servers/test_inst/action')
req.method = "POST"
req.body = json.dumps(body)
req.headers["content-type"] = "application/json"

resp = req.get_response(fakes.wsgi_app())
self.assertEqual(resp.status_int, 409)

0 comments on commit 575ad8f

Please sign in to comment.