Commit b67509f5 authored by Xavier Thompson's avatar Xavier Thompson

testing: Factor snapshot management

parent 6f9e279e
...@@ -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
...@@ -410,23 +411,32 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -410,23 +411,32 @@ class SlapOSInstanceTestCase(unittest.TestCase):
cls.slap._instance_root, cls.computer_partition.getId()) cls.slap._instance_root, cls.computer_partition.getId())
@classmethod @classmethod
def setUpClass(cls): @contextlib.contextmanager
"""Request an instance. def _snapshotManager(cls, snapshot_name):
"""
cls.logger.debug("Starting setUpClass %s", cls)
cls._instance_parameter_dict = cls.getInstanceParameterDict()
snapshot_name = "{}.{}.setUpClass".format(cls.__module__, cls.__name__)
try: try:
cls._setUpClass() yield
except BaseException: except BaseException:
cls.logger.exception("Error during setUpClass")
cls._storeSystemSnapshot(snapshot_name) cls._storeSystemSnapshot(snapshot_name)
cls._cleanup(snapshot_name) cls._cleanup(snapshot_name)
cls.setUp = lambda self: self.fail('Setup Class failed.')
raise raise
else: else:
cls._storeSystemSnapshot(snapshot_name) 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") 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