diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-06-19 05:50:55 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-06-19 05:50:55 +0000 |
| commit | 6e6ffc2e4eff90e07f03049452979773e67a6a1c (patch) | |
| tree | 3b52ccaf2c782d896e7f489d14108f73cfb4c4f2 | |
| parent | 169112c15394425bf633d004f1feb6aaf43cb08d (diff) | |
| parent | 984435b1edc9ab0ec3d33e809babd04884e96ff1 (diff) | |
| download | nova-6e6ffc2e4eff90e07f03049452979773e67a6a1c.tar.gz nova-6e6ffc2e4eff90e07f03049452979773e67a6a1c.tar.xz nova-6e6ffc2e4eff90e07f03049452979773e67a6a1c.zip | |
Merge "Handle missing server when getting security groups"
| -rw-r--r-- | Authors | 1 | ||||
| -rw-r--r-- | nova/api/openstack/compute/contrib/security_groups.py | 10 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_security_groups.py | 14 |
3 files changed, 19 insertions, 6 deletions
@@ -139,6 +139,7 @@ Mandell Degerness <mdegerne@gmail.com> Mark McClain <mark.mcclain@dreamhost.com> Mark McLoughlin <markmc@redhat.com> Mark Washenberger <mark.washenberger@rackspace.com> +Martin Packman <martin.packman@canonical.com> Maru Newby <mnewby@internap.com> Masanori Itoh <itoumsn@nttdata.co.jp> Matt Dietz <matt.dietz@rackspace.com> diff --git a/nova/api/openstack/compute/contrib/security_groups.py b/nova/api/openstack/compute/contrib/security_groups.py index 5e81347ec..840813d68 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 1778068bb..9e636de14 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=[]) |
