diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-05-24 05:29:24 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-05-24 05:29:24 +0000 |
| commit | e7bcf0d5ec52fc9aeb932a62121d5a8462f74253 (patch) | |
| tree | 85de224f3ff666531f739d892dbaf5def42ae7c1 | |
| parent | 738a395eba63b51456ce6fa5b959bb9bf032b3d4 (diff) | |
| parent | 65a6264c236a779712694d2379cfe4f9e46e2732 (diff) | |
| download | nova-e7bcf0d5ec52fc9aeb932a62121d5a8462f74253.tar.gz nova-e7bcf0d5ec52fc9aeb932a62121d5a8462f74253.tar.xz nova-e7bcf0d5ec52fc9aeb932a62121d5a8462f74253.zip | |
Merge "Disallow resize if image not available"
| -rw-r--r-- | nova/api/openstack/compute/servers.py | 11 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/test_server_actions.py | 28 |
2 files changed, 39 insertions, 0 deletions
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index cec7cbd60..41c3b92a5 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -1094,6 +1094,17 @@ class Controller(wsgi.Controller): except exception.InstanceInvalidState as state_error: common.raise_http_conflict_for_instance_invalid_state(state_error, 'resize') + except exception.ImageNotAuthorized as image_error: + msg = _("You are not authorized to access the image " + "the instance was started with.") + raise exc.HTTPUnauthorized(explanation=msg) + except exception.ImageNotFound as image_error: + msg = _("Image that the instance was started " + "with could not be found.") + raise exc.HTTPBadRequest(explanation=msg) + except exception.Invalid: + msg = _("Invalid instance image.") + raise exc.HTTPBadRequest(explanation=msg) return webob.Response(status_int=202) diff --git a/nova/tests/api/openstack/compute/test_server_actions.py b/nova/tests/api/openstack/compute/test_server_actions.py index 3b8833dd7..473d3a253 100644 --- a/nova/tests/api/openstack/compute/test_server_actions.py +++ b/nova/tests/api/openstack/compute/test_server_actions.py @@ -630,6 +630,34 @@ class ServerActionsControllerTest(test.TestCase): self.controller._action_resize, req, FAKE_UUID, body) + def test_resize_with_image_exceptions(self): + body = dict(resize=dict(flavorRef="http://localhost/3")) + self.resize_called = 0 + image_id = 'fake_image_id' + + exceptions = [ + (exception.ImageNotAuthorized(image_id=image_id), + webob.exc.HTTPUnauthorized), + (exception.ImageNotFound(image_id=image_id), + webob.exc.HTTPBadRequest), + (exception.Invalid, webob.exc.HTTPBadRequest), + ] + + raised, expected = map(iter, zip(*exceptions)) + + def _fake_resize(obj, context, instance, flavor_id): + self.resize_called += 1 + raise raised.next() + + self.stubs.Set(compute_api.API, 'resize', _fake_resize) + + for call_no in range(len(exceptions)): + req = fakes.HTTPRequest.blank(self.url) + self.assertRaises(expected.next(), + self.controller._action_resize, + req, FAKE_UUID, body) + self.assertEqual(self.resize_called, call_no + 1) + def test_resize_with_too_many_instances(self): body = dict(resize=dict(flavorRef="http://localhost/3")) |
