Merge "Raise 409 when rescuing instance in RESCUE mode"

This commit is contained in:
Jenkins 2012-03-06 03:08:00 +00:00 committed by Gerrit Code Review
commit 9bb2a33590
3 changed files with 25 additions and 1 deletions

View File

@ -17,6 +17,7 @@
import webob
from webob import exc
from nova.api.openstack import common
from nova.api.openstack import extensions as exts
from nova.api.openstack import wsgi
from nova import compute
@ -56,7 +57,12 @@ class RescueController(wsgi.Controller):
password = utils.generate_password(FLAGS.password_length)
instance = self._get_instance(context, id)
self.compute_api.rescue(context, instance, rescue_password=password)
try:
self.compute_api.rescue(context, instance,
rescue_password=password)
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'rescue')
return {'adminPass': password}
@wsgi.action('unrescue')

View File

@ -301,6 +301,8 @@ def wrap_errors(fn):
def wrapped(*args, **kwargs):
try:
return fn(*args, **kwargs)
except webob.exc.HTTPException:
raise
except Exception:
raise webob.exc.HTTPInternalServerError()
return wrapped

View File

@ -17,6 +17,7 @@ import json
import webob
from nova import compute
from nova import exception
from nova import flags
from nova import test
from nova.tests.api.openstack import fakes
@ -68,6 +69,21 @@ class RescueTest(test.TestCase):
resp_json = json.loads(resp.body)
self.assertEqual(FLAGS.password_length, len(resp_json['adminPass']))
def test_rescue_of_rescued_instance(self):
body = dict(rescue=None)
def fake_rescue(*args, **kwargs):
raise exception.InstanceInvalidState('fake message')
self.stubs.Set(compute.api.API, "rescue", fake_rescue)
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)
def test_unrescue(self):
body = dict(unrescue=None)
req = webob.Request.blank('/v2/fake/servers/test_inst/action')