Merge "Add error handling for creating secgroup"

This commit is contained in:
Jenkins 2015-06-15 18:01:20 +00:00 committed by Gerrit Code Review
commit 5c4c50360e
2 changed files with 16 additions and 0 deletions

View File

@ -52,6 +52,8 @@ class SecurityGroupAPI(security_group_base.SecurityGroupBase):
try:
security_group = neutron.create_security_group(
body).get('security_group')
except n_exc.BadRequest as e:
raise exception.Invalid(six.text_type(e))
except n_exc.NeutronClientException as e:
exc_info = sys.exc_info()
LOG.exception(_LE("Neutron Error creating security group %s"),

View File

@ -96,6 +96,20 @@ class TestNeutronDriver(test.NoDBTestCase):
self.assertRaises(exception.SecurityGroupNotFound,
sg_api.get, self.context, name=sg_name)
def test_create_security_group_with_bad_request(self):
name = 'test-security-group'
description = None
body = {'security_group': {'name': name,
'description': description}}
message = "Invalid input. Reason: 'None' is not a valid string."
self.moxed_client.create_security_group(
body).AndRaise(n_exc.BadRequest(message=message))
self.mox.ReplayAll()
sg_api = neutron_driver.SecurityGroupAPI()
self.assertRaises(exception.Invalid,
sg_api.create_security_group, self.context, name,
description)
def test_create_security_group_exceed_quota(self):
name = 'test-security-group'
description = 'test-security-group'