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