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
......@@ -410,23 +411,32 @@ class SlapOSInstanceTestCase(unittest.TestCase):
cls.slap._instance_root, cls.computer_partition.getId())
@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__)
@contextlib.contextmanager
def _snapshotManager(cls, snapshot_name):
try:
cls._setUpClass()
yield
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)
@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__)
with cls._snapshotManager(snapshot_name):
try:
cls._setUpClass()
except BaseException:
cls.logger.exception("Error during setUpClass")
cls.setUp = lambda self: self.fail('Setup Class failed.')
raise
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