From b6c649c00b337babf51a7d746cfe189c12a8e78a Mon Sep 17 00:00:00 2001 From: Liam Young Date: Thu, 28 Nov 2019 14:59:46 +0000 Subject: [PATCH 1/2] Guard against run_resource_cleanup being unset A test may not call the base class setup so may be missing run_resource_cleanup in which case teardown will fail. Guard against that and default to False. --- zaza/openstack/charm_tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zaza/openstack/charm_tests/test_utils.py b/zaza/openstack/charm_tests/test_utils.py index c800bee..57e6e6c 100644 --- a/zaza/openstack/charm_tests/test_utils.py +++ b/zaza/openstack/charm_tests/test_utils.py @@ -107,7 +107,7 @@ class OpenStackBaseTest(unittest.TestCase): @classmethod def tearDown(cls): """Run teardown for test class.""" - if cls.run_resource_cleanup: + if getattr(cls, 'run_resource_cleanup', False): logging.info('Running resource cleanup') cls.resource_cleanup() From 5e9440dd9715435030fb2f713f789dd1a1b9254c Mon Sep 17 00:00:00 2001 From: Liam Young Date: Thu, 28 Nov 2019 15:17:32 +0000 Subject: [PATCH 2/2] Define run_resource_cleanup in OpenStackBaseTest so all sub-classes inherit it --- zaza/openstack/charm_tests/test_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zaza/openstack/charm_tests/test_utils.py b/zaza/openstack/charm_tests/test_utils.py index 57e6e6c..6d7376f 100644 --- a/zaza/openstack/charm_tests/test_utils.py +++ b/zaza/openstack/charm_tests/test_utils.py @@ -93,6 +93,8 @@ def audit_assertions(action, class OpenStackBaseTest(unittest.TestCase): """Generic helpers for testing OpenStack API charms.""" + run_resource_cleanup = False + @classmethod def resource_cleanup(cls): """Cleanup any resources created during the test run. @@ -107,7 +109,7 @@ class OpenStackBaseTest(unittest.TestCase): @classmethod def tearDown(cls): """Run teardown for test class.""" - if getattr(cls, 'run_resource_cleanup', False): + if cls.run_resource_cleanup: logging.info('Running resource cleanup') cls.resource_cleanup() @@ -124,7 +126,6 @@ class OpenStackBaseTest(unittest.TestCase): cls.lead_unit = model.get_lead_unit_name( cls.application_name, model_name=cls.model_name) - cls.run_resource_cleanup = False logging.debug('Leader unit is {}'.format(cls.lead_unit)) @contextlib.contextmanager