diff options
author | Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> | 2015-06-09 02:39:24 +0000 |
---|---|---|
committer | Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> | 2015-06-09 02:57:38 +0000 |
commit | 9b6b70bdf9cdad24d545888b7c775ca76f1da528 (patch) | |
tree | 8c7051161687805b6535e6d94df059f7c0679054 | |
parent | 7330b3f90c4c1a5b066ed6adaebd444c2bdcea61 (diff) | |
download | nova-9b6b70bdf9cdad24d545888b7c775ca76f1da528.tar.gz |
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
-rw-r--r-- | nova/network/security_group/neutron_driver.py | 2 | ||||
-rw-r--r-- | nova/tests/unit/network/security_group/test_neutron_driver.py | 14 |
2 files changed, 16 insertions, 0 deletions
diff --git a/nova/network/security_group/neutron_driver.py b/nova/network/security_group/neutron_driver.py index 24245c431e..8ff5732a2c 100644 --- a/nova/network/security_group/neutron_driver.py +++ b/nova/network/security_group/neutron_driver.py @@ -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"), diff --git a/nova/tests/unit/network/security_group/test_neutron_driver.py b/nova/tests/unit/network/security_group/test_neutron_driver.py index 9f64555f7b..564f846ba6 100644 --- a/nova/tests/unit/network/security_group/test_neutron_driver.py +++ b/nova/tests/unit/network/security_group/test_neutron_driver.py @@ -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' |