Merge "Fix 500 when deleting a not existing ec2 security group"
This commit is contained in:
commit
614ffbb91c
|
@ -130,18 +130,21 @@ class SecurityGroupAPI(security_group_base.SecurityGroupBase):
|
|||
id = neutronv20.find_resourceid_by_name_or_id(
|
||||
neutron, 'security_group', name, context.project_id)
|
||||
group = neutron.show_security_group(id).get('security_group')
|
||||
return self._convert_to_nova_security_group_format(group)
|
||||
except n_exc.NeutronClientNoUniqueMatch as e:
|
||||
raise exception.NoUniqueMatch(six.text_type(e))
|
||||
except n_exc.NeutronClientException as e:
|
||||
exc_info = sys.exc_info()
|
||||
if e.status_code == 404:
|
||||
LOG.debug("Neutron security group %s not found", name)
|
||||
self.raise_not_found(six.text_type(e))
|
||||
raise exception.SecurityGroupNotFound(six.text_type(e))
|
||||
else:
|
||||
LOG.error(_LE("Neutron Error: %s"), e)
|
||||
raise exc_info[0], exc_info[1], exc_info[2]
|
||||
|
||||
return self._convert_to_nova_security_group_format(group)
|
||||
except TypeError as e:
|
||||
LOG.error(_LE("Neutron Error: %s"), e)
|
||||
msg = _("Invalid security group name: %(name)s.") % {"name": name}
|
||||
raise exception.SecurityGroupNotFound(six.text_type(msg))
|
||||
|
||||
def list(self, context, names=None, ids=None, project=None,
|
||||
search_opts=None):
|
||||
|
|
|
@ -73,6 +73,27 @@ class TestNeutronDriver(test.NoDBTestCase):
|
|||
del expected_sg['security_group']['tenant_id']
|
||||
self.assertEqual(expected_sg['security_group'], observed_sg)
|
||||
|
||||
def test_get_with_invalid_name(self):
|
||||
sg_name = 'invalid_name'
|
||||
expected_sg_id = '85cc3048-abc3-43cc-89b3-377341426ac5'
|
||||
list_security_groups = {'security_groups':
|
||||
[{'name': sg_name,
|
||||
'id': expected_sg_id,
|
||||
'tenant_id': self.context.tenant,
|
||||
'description': 'server',
|
||||
'rules': []}
|
||||
]}
|
||||
self.moxed_client.list_security_groups(name=sg_name, fields='id',
|
||||
tenant_id=self.context.tenant).AndReturn(list_security_groups)
|
||||
|
||||
self.moxed_client.show_security_group(expected_sg_id).AndRaise(
|
||||
TypeError)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
sg_api = neutron_driver.SecurityGroupAPI()
|
||||
self.assertRaises(exception.SecurityGroupNotFound,
|
||||
sg_api.get, self.context, name=sg_name)
|
||||
|
||||
def test_create_security_group_exceed_quota(self):
|
||||
name = 'test-security-group'
|
||||
description = 'test-security-group'
|
||||
|
|
Loading…
Reference in New Issue