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):
# Unittest methods
@classmethod
def setUpClass(cls):
"""Request an instance.
"""
cls._instance_parameter_dict = cls.getInstanceParameterDict()
snapshot_name = "{}.{}.setUpClass".format(cls.__module__, cls.__name__)
def waitForInstance(cls):
# waitForInstance does not tolerate any error but with instances,
# 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.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.logger.debug(
"Formatting to remove old partitions XXX should not be needed because we delete ..."
......@@ -391,20 +400,7 @@ class SlapOSInstanceTestCase(unittest.TestCase):
# slapos node instance
cls.logger.debug("Waiting for instance")
# waitForInstance does not tolerate any error but with instances,
# 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)
cls.waitForInstance()
# expose some class attributes so that tests can use them:
# the main ComputerPartition instance, to use getInstanceParameterDict
cls.computer_partition = cls.requestDefaultInstance()
......@@ -412,7 +408,17 @@ class SlapOSInstanceTestCase(unittest.TestCase):
# the path of the instance on the filesystem, for low level inspection
cls.computer_partition_root_path = os.path.join(
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:
cls.logger.exception("Error during setUpClass")
cls._storeSystemSnapshot(snapshot_name)
......@@ -421,6 +427,7 @@ class SlapOSInstanceTestCase(unittest.TestCase):
raise
else:
cls._storeSystemSnapshot(snapshot_name)
cls.logger.debug("setUpClass done")
@classmethod
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