From b871907e84500fafaa7754affebfe890dd720bb6 Mon Sep 17 00:00:00 2001 From: Frode Nordahl Date: Wed, 27 Nov 2019 08:58:03 +0100 Subject: [PATCH] neutron: Do not run tear down on test failure Fixes #120 --- zaza/openstack/charm_tests/neutron/tests.py | 24 +++++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/zaza/openstack/charm_tests/neutron/tests.py b/zaza/openstack/charm_tests/neutron/tests.py index 7433793..e7d609d 100644 --- a/zaza/openstack/charm_tests/neutron/tests.py +++ b/zaza/openstack/charm_tests/neutron/tests.py @@ -135,17 +135,24 @@ class NeutronNetworkingTest(unittest.TestCase): openstack_utils.get_overcloud_keystone_session()) cls.nova_client = ( openstack_utils.get_nova_session_client(cls.keystone_session)) + # NOTE(fnordahl): in the event of a test failure we do not want to run + # tear down code as it will make debugging a problem virtually + # impossible. To alleviate each test method will set the + # `run_tearDown` instance variable at the end which will let us run + # tear down only when there were no failure. + cls.run_tearDown = False @classmethod def tearDown(cls): """Remove test resources.""" - logging.info('Running teardown') - for server in cls.nova_client.servers.list(): - if server.name.startswith(cls.RESOURCE_PREFIX): - openstack_utils.delete_resource( - cls.nova_client.servers, - server.id, - msg="server") + if cls.run_tearDown: + logging.info('Running teardown') + for server in cls.nova_client.servers.list(): + if server.name.startswith(cls.RESOURCE_PREFIX): + openstack_utils.delete_resource( + cls.nova_client.servers, + server.id, + msg="server") def test_instances_have_networking(self): """Validate North/South and East/West networking.""" @@ -176,6 +183,9 @@ class NeutronNetworkingTest(unittest.TestCase): self.validate_instance_can_reach_router(instance_1, verify) self.validate_instance_can_reach_router(instance_2, verify) + # If we get here, it means the tests passed + self.run_tearDown = True + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1, max=60), reraise=True, stop=tenacity.stop_after_attempt(8)) def validate_instance_can_reach_other(self,