diff --git a/rally_openstack/cleanup/resources.py b/rally_openstack/cleanup/resources.py index 6263353d..723b7b8c 100644 --- a/rally_openstack/cleanup/resources.py +++ b/rally_openstack/cleanup/resources.py @@ -466,11 +466,16 @@ class NeutronRouter(NeutronMixin): tenant_resource=True) class NeutronSecurityGroup(NeutronMixin): def list(self): - tenant_sgs = super(NeutronSecurityGroup, self).list() - # NOTE(pirsriva): Filter out "default" security group deletion - # by non-admin role user - return filter(lambda r: r["name"] != "default", - tenant_sgs) + try: + tenant_sgs = super(NeutronSecurityGroup, self).list() + # NOTE(pirsriva): Filter out "default" security group deletion + # by non-admin role user + return filter(lambda r: r["name"] != "default", + tenant_sgs) + except Exception as e: + if getattr(e, "status_code", 400) == 404: + return [] + raise @base.resource("neutron", "quota", order=next(_neutron_order), diff --git a/tests/unit/cleanup/test_resources.py b/tests/unit/cleanup/test_resources.py index 500292fa..ff3bf582 100644 --- a/tests/unit/cleanup/test_resources.py +++ b/tests/unit/cleanup/test_resources.py @@ -576,6 +576,24 @@ class NeutronSecurityGroupTestCase(test.TestCase): neut.user.neutron().list_security_groups.assert_called_once_with( tenant_id=neut.tenant_uuid) + def test_list_with_not_found(self): + + class NotFound(Exception): + status_code = 404 + + neut = resources.NeutronSecurityGroup() + neut.user = mock.MagicMock() + neut._resource = "security_group" + neut.tenant_uuid = "user_tenant" + + neut.user.neutron().list_security_groups.side_effect = NotFound() + + expected_result = [] + self.assertEqual(expected_result, list(neut.list())) + + neut.user.neutron().list_security_groups.assert_called_once_with( + tenant_id=neut.tenant_uuid) + class NeutronQuotaTestCase(test.TestCase):