From e4ee31047d51e27884c7157039efe9822ffc3e0b Mon Sep 17 00:00:00 2001 From: chenhb Date: Thu, 28 Feb 2019 11:20:48 +0800 Subject: [PATCH] Fix the cleanup issue of NeutronTrunk Catch the exception in list(),otherwise break if neutron trunk is not found. Change-Id: Ied7d26c8e2d674601b2a5d83c5b9b5f7d60d3436 --- rally_openstack/cleanup/resources.py | 9 ++++++++- tests/unit/cleanup/test_resources.py | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/rally_openstack/cleanup/resources.py b/rally_openstack/cleanup/resources.py index 6ba5a483..7112183b 100644 --- a/rally_openstack/cleanup/resources.py +++ b/rally_openstack/cleanup/resources.py @@ -390,7 +390,14 @@ class NeutronFloatingIP(NeutronMixin): tenant_resource=True) class NeutronTrunk(NeutronMixin): # Trunks must be deleted before the parent/subports are deleted - pass + + def list(self): + try: + return super(NeutronTrunk, self).list() + except Exception as e: + if getattr(e, "status_code", 400) == 404: + return [] + raise @base.resource("neutron", "port", order=next(_neutron_order), diff --git a/tests/unit/cleanup/test_resources.py b/tests/unit/cleanup/test_resources.py index 42d5b15f..320bf2aa 100644 --- a/tests/unit/cleanup/test_resources.py +++ b/tests/unit/cleanup/test_resources.py @@ -422,6 +422,31 @@ class NeutronFloatingIPTestCase(test.TestCase): tenant_id="foo") +class NeutronTrunkTestcase(test.TestCase): + + def test_list(self): + user = mock.MagicMock() + trunk = resources.NeutronTrunk(user=user) + user.neutron().list_trunks.return_value = { + "trunks": ["trunk"]} + self.assertEqual(["trunk"], trunk.list()) + user.neutron().list_trunks.assert_called_once_with( + tenant_id=None) + + def test_list_with_not_found(self): + + class NotFound(Exception): + status_code = 404 + + user = mock.MagicMock() + trunk = resources.NeutronTrunk(user=user) + user.neutron().list_trunks.side_effect = NotFound() + + self.assertEqual([], trunk.list()) + user.neutron().list_trunks.assert_called_once_with( + tenant_id=None) + + class NeutronPortTestCase(test.TestCase): def test_delete(self):