diff --git a/nova/network/security_group/neutron_driver.py b/nova/network/security_group/neutron_driver.py index 24245c431e70..8ff5732a2c05 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 9f64555f7bc7..564f846ba6a7 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'