Commit b67509f5 authored by Xavier Thompson's avatar Xavier Thompson

testing: Factor snapshot management

parent 6f9e279e
Pipeline #28851 failed with stage
in 0 seconds
...@@ -26,12 +26,13 @@ ...@@ -26,12 +26,13 @@
# #
############################################################################## ##############################################################################
import unittest import contextlib
import os
import fnmatch import fnmatch
import glob import glob
import logging import logging
import os
import shutil import shutil
import unittest
import warnings import warnings
from six.moves.urllib.parse import urlparse from six.moves.urllib.parse import urlparse
...@@ -409,6 +410,18 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -409,6 +410,18 @@ class SlapOSInstanceTestCase(unittest.TestCase):
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())
@classmethod
@contextlib.contextmanager
def _snapshotManager(cls, snapshot_name):
try:
yield
except BaseException:
cls._storeSystemSnapshot(snapshot_name)
cls._cleanup(snapshot_name)
raise
else:
cls._storeSystemSnapshot(snapshot_name)
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
"""Request an instance. """Request an instance.
...@@ -417,16 +430,13 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -417,16 +430,13 @@ class SlapOSInstanceTestCase(unittest.TestCase):
cls._instance_parameter_dict = cls.getInstanceParameterDict() cls._instance_parameter_dict = cls.getInstanceParameterDict()
snapshot_name = "{}.{}.setUpClass".format(cls.__module__, cls.__name__) snapshot_name = "{}.{}.setUpClass".format(cls.__module__, cls.__name__)
with cls._snapshotManager(snapshot_name):
try: try:
cls._setUpClass() cls._setUpClass()
except BaseException: except BaseException:
cls.logger.exception("Error during setUpClass") cls.logger.exception("Error during setUpClass")
cls._storeSystemSnapshot(snapshot_name)
cls._cleanup(snapshot_name)
cls.setUp = lambda self: self.fail('Setup Class failed.') cls.setUp = lambda self: self.fail('Setup Class failed.')
raise raise
else:
cls._storeSystemSnapshot(snapshot_name)
cls.logger.debug("setUpClass done") cls.logger.debug("setUpClass done")
@classmethod @classmethod
......
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