From 0df72bf47c88a69a20010255e60bd18a43e4d23c Mon Sep 17 00:00:00 2001 From: Frode Nordahl Date: Fri, 3 Jul 2020 08:04:09 +0200 Subject: [PATCH] Make shared resource cleanup method class instance method At present the shared resource cleanup method is a class method. This will prohibit descendents of the class to influence whether cleanup should be run. Remove the @classmethod decorator so that it will make its descisions based on class instance variables set by the descendent. --- zaza/openstack/charm_tests/test_utils.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/zaza/openstack/charm_tests/test_utils.py b/zaza/openstack/charm_tests/test_utils.py index 4b4e1d0..6abb381 100644 --- a/zaza/openstack/charm_tests/test_utils.py +++ b/zaza/openstack/charm_tests/test_utils.py @@ -100,8 +100,7 @@ class BaseCharmTest(unittest.TestCase): run_resource_cleanup = False - @classmethod - def resource_cleanup(cls): + def resource_cleanup(self): """Cleanup any resources created during the test run. Override this method with a method which removes any resources @@ -111,12 +110,13 @@ class BaseCharmTest(unittest.TestCase): """ pass - @classmethod - def tearDown(cls): + # this must be a class instance method otherwise descentents will not be + # able to influence if cleanup should be run. + def tearDown(self): """Run teardown for test class.""" - if cls.run_resource_cleanup: + if self.run_resource_cleanup: logging.info('Running resource cleanup') - cls.resource_cleanup() + self.resource_cleanup() @classmethod def setUpClass(cls, application_name=None, model_alias=None): @@ -440,6 +440,7 @@ class OpenStackBaseTest(BaseCharmTest): cls.nova_client = ( openstack_utils.get_nova_session_client(cls.keystone_session)) + def launch_guest(self, guest_name, userdata=None): """Launch two guests to use in tests.