Add error handling for creating secgroup

If passing invalid value to "create security group" API, Nova passes
it to Neutron and Neutron returns BadRequest response back to Nova.
However, Nova didn't handle the exception.
So this patch adds error handling for the situation.

Change-Id: I11da9ec32b64b5a109d65afe77aa32be71a807a3
Related-Bug: #1460875
This commit is contained in:
Ken'ichi Ohmichi 2015-06-09 02:39:24 +00:00
parent 7330b3f90c
commit 9b6b70bdf9
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'