Commit 9a7d24ae authored by Łukasz Nowak's avatar Łukasz Nowak

testing/testcase: Simplify setUpClass override

Some advanced tests setting up clusters need to being able to come in half of
the setup process to do some actions on the cluster in order to have its setup
finished, thus allow to override extracted _setUpClass and separated
waitForInstance, so that those actions can be executed.
parent cf39b7f0
...@@ -368,14 +368,23 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -368,14 +368,23 @@ class SlapOSInstanceTestCase(unittest.TestCase):
# Unittest methods # Unittest methods
@classmethod @classmethod
def setUpClass(cls): def waitForInstance(cls):
"""Request an instance. # waitForInstance does not tolerate any error but with instances,
""" # promises sometimes fail on first run, because services did not
cls._instance_parameter_dict = cls.getInstanceParameterDict() # have time to start.
snapshot_name = "{}.{}.setUpClass".format(cls.__module__, cls.__name__) # To make debug usable, we tolerate instance_max_retry-1 errors and
# only debug the last.
if cls._debug and cls.instance_max_retry:
try: try:
cls.logger.debug("Starting setUpClass %s", cls) cls.slap.waitForInstance(max_retry=cls.instance_max_retry - 1)
except SlapOSNodeCommandError:
cls.slap.waitForInstance(debug=True)
else:
cls.slap.waitForInstance(
max_retry=cls.instance_max_retry, debug=cls._debug)
@classmethod
def _setUpClass(cls):
cls.slap.start() cls.slap.start()
cls.logger.debug( cls.logger.debug(
"Formatting to remove old partitions XXX should not be needed because we delete ..." "Formatting to remove old partitions XXX should not be needed because we delete ..."
...@@ -391,20 +400,7 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -391,20 +400,7 @@ class SlapOSInstanceTestCase(unittest.TestCase):
# slapos node instance # slapos node instance
cls.logger.debug("Waiting for instance") cls.logger.debug("Waiting for instance")
# waitForInstance does not tolerate any error but with instances, cls.waitForInstance()
# promises sometimes fail on first run, because services did not
# have time to start.
# To make debug usable, we tolerate instance_max_retry-1 errors and
# only debug the last.
if cls._debug and cls.instance_max_retry:
try:
cls.slap.waitForInstance(max_retry=cls.instance_max_retry - 1)
except SlapOSNodeCommandError:
cls.slap.waitForInstance(debug=True)
else:
cls.slap.waitForInstance(
max_retry=cls.instance_max_retry, debug=cls._debug)
# expose some class attributes so that tests can use them: # expose some class attributes so that tests can use them:
# the main ComputerPartition instance, to use getInstanceParameterDict # the main ComputerPartition instance, to use getInstanceParameterDict
cls.computer_partition = cls.requestDefaultInstance() cls.computer_partition = cls.requestDefaultInstance()
...@@ -412,7 +408,17 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -412,7 +408,17 @@ class SlapOSInstanceTestCase(unittest.TestCase):
# the path of the instance on the filesystem, for low level inspection # the path of the instance on the filesystem, for low level inspection
cls.computer_partition_root_path = os.path.join( cls.computer_partition_root_path = os.path.join(
cls.slap._instance_root, cls.computer_partition.getId()) cls.slap._instance_root, cls.computer_partition.getId())
cls.logger.debug("setUpClass done")
@classmethod
def setUpClass(cls):
"""Request an instance.
"""
cls.logger.debug("Starting setUpClass %s", cls)
cls._instance_parameter_dict = cls.getInstanceParameterDict()
snapshot_name = "{}.{}.setUpClass".format(cls.__module__, cls.__name__)
try:
cls._setUpClass()
except BaseException: except BaseException:
cls.logger.exception("Error during setUpClass") cls.logger.exception("Error during setUpClass")
cls._storeSystemSnapshot(snapshot_name) cls._storeSystemSnapshot(snapshot_name)
...@@ -421,6 +427,7 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -421,6 +427,7 @@ class SlapOSInstanceTestCase(unittest.TestCase):
raise raise
else: else:
cls._storeSystemSnapshot(snapshot_name) cls._storeSystemSnapshot(snapshot_name)
cls.logger.debug("setUpClass done")
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment