diff options
author | Jenkins <jenkins@review.openstack.org> | 2013-06-11 10:36:48 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-06-11 10:36:48 +0000 |
commit | 685228d96b7d40f537cf6144014234e24e8cd7fd (patch) | |
tree | 5df98ad72b97f9ae8f6212535d3787654b0c4962 | |
parent | 6c79b752b620a5859d3becb483df9bffcef275d3 (diff) | |
parent | bc0a05dd4aa5e1eb104efd63fda7bbe939bc7cbe (diff) | |
download | nova-685228d96b7d40f537cf6144014234e24e8cd7fd.tar.gz nova-685228d96b7d40f537cf6144014234e24e8cd7fd.tar.xz nova-685228d96b7d40f537cf6144014234e24e8cd7fd.zip |
Merge "Handle security group quota exceeded gracefully"
-rw-r--r-- | nova/api/openstack/compute/contrib/security_groups.py | 18 | ||||
-rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_security_groups.py | 4 |
2 files changed, 15 insertions, 7 deletions
diff --git a/nova/api/openstack/compute/contrib/security_groups.py b/nova/api/openstack/compute/contrib/security_groups.py index 041eb0dc5..40b085be1 100644 --- a/nova/api/openstack/compute/contrib/security_groups.py +++ b/nova/api/openstack/compute/contrib/security_groups.py @@ -289,8 +289,12 @@ class SecurityGroupController(SecurityGroupControllerBase): self.security_group_api.validate_property(group_description, 'description', None) - group_ref = self.security_group_api.create_security_group( - context, group_name, group_description) + try: + group_ref = self.security_group_api.create_security_group( + context, group_name, group_description) + except exception.SecurityGroupLimitExceeded as err: + raise exc.HTTPRequestEntityTooLarge( + explanation=err.format_message()) return {'security_group': self._format_security_group(context, group_ref)} @@ -356,9 +360,13 @@ class SecurityGroupRulesController(SecurityGroupControllerBase): msg = _("Bad prefix for network in cidr %s") % new_rule['cidr'] raise exc.HTTPBadRequest(explanation=msg) - security_group_rule = ( - self.security_group_api.create_security_group_rule( - context, security_group, new_rule)) + try: + security_group_rule = ( + self.security_group_api.create_security_group_rule( + context, security_group, new_rule)) + except exception.SecurityGroupLimitExceeded as err: + raise exc.HTTPRequestEntityTooLarge( + explanation=err.format_message()) return {"security_group_rule": self._format_security_group_rule( context, 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 1406ed97a..6bd220198 100644 --- a/nova/tests/api/openstack/compute/contrib/test_security_groups.py +++ b/nova/tests/api/openstack/compute/contrib/test_security_groups.py @@ -273,7 +273,7 @@ class TestSecurityGroups(test.TestCase): self.assertEqual(res_dict['security_group']['name'], name) sg = security_group_template() - self.assertRaises(exception.SecurityGroupLimitExceeded, + self.assertRaises(webob.exc.HTTPRequestEntityTooLarge, self.controller.create, req, {'security_group': sg}) @@ -1139,7 +1139,7 @@ class TestSecurityGroupRules(test.TestCase): 'ip_protocol': 'tcp', 'from_port': '121', 'to_port': '121', 'parent_group_id': self.sg2['id'], 'group_id': self.sg1['id'] } - self.assertRaises(exception.SecurityGroupLimitExceeded, + self.assertRaises(webob.exc.HTTPRequestEntityTooLarge, self.controller.create, req, {'security_group_rule': rule}) |