diff --git a/Authors b/Authors index 489122bc2e81..685dee694c24 100644 --- a/Authors +++ b/Authors @@ -138,6 +138,7 @@ Mandell Degerness Mark McClain Mark McLoughlin Mark Washenberger +Martin Packman Maru Newby Masanori Itoh Matt Dietz diff --git a/nova/api/openstack/compute/contrib/security_groups.py b/nova/api/openstack/compute/contrib/security_groups.py index 5e81347ecb54..840813d6840c 100644 --- a/nova/api/openstack/compute/contrib/security_groups.py +++ b/nova/api/openstack/compute/contrib/security_groups.py @@ -385,12 +385,10 @@ class ServerSecurityGroupController(SecurityGroupControllerBase): try: instance = self.compute_api.get(context, server_id) - groups = db.security_group_get_by_instance(context, - instance['id']) - except exception.ApiError, e: - raise webob.exc.HTTPBadRequest(explanation=e.message) - except exception.NotAuthorized, e: - raise webob.exc.HTTPUnauthorized() + except exception.InstanceNotFound as exp: + raise exc.HTTPNotFound(explanation=unicode(exp)) + + groups = db.security_group_get_by_instance(context, instance['id']) result = [self._format_security_group(context, group) for group in groups] diff --git a/nova/tests/api/openstack/compute/contrib/test_security_groups.py b/nova/tests/api/openstack/compute/contrib/test_security_groups.py index 1778068bbe23..9e636de1482b 100644 --- a/nova/tests/api/openstack/compute/contrib/test_security_groups.py +++ b/nova/tests/api/openstack/compute/contrib/test_security_groups.py @@ -285,6 +285,20 @@ class TestSecurityGroups(test.TestCase): self.assertEquals(res_dict, expected) + def test_get_security_group_by_instance_non_existing(self): + self.stubs.Set(nova.db, 'instance_get', return_server_nonexistent) + self.stubs.Set(nova.db, 'instance_get_by_uuid', + return_server_nonexistent) + req = fakes.HTTPRequest.blank('/v2/fake/servers/1/os-security-groups') + self.assertRaises(webob.exc.HTTPNotFound, + self.server_controller.index, req, '1') + + def test_get_security_group_by_instance_invalid_id(self): + req = fakes.HTTPRequest.blank( + '/v2/fake/servers/invalid/os-security-groups') + self.assertRaises(webob.exc.HTTPNotFound, + self.server_controller.index, req, 'invalid') + def test_get_security_group_by_id(self): sg = security_group_template(id=2, rules=[])

AltStyle によって変換されたページ (->オリジナル) /