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.
This commit is contained in:
Frode Nordahl
2020-07-03 08:04:09 +02:00
parent 2538e1023c
commit 0df72bf47c

View File

@@ -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.