Commit e3183d39 authored by Carlos Ramos Carreño's avatar Carlos Ramos Carreño

Allow not to request instance in a test.

This adds the `request_instance` class variable to
`SlapOSInstanceTestCase`.
If this variable is false, no instance will be requested.

See merge request nexedi/slapos.core!664
parent 9ee8832a
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
# #
############################################################################## ##############################################################################
from __future__ import annotations
import contextlib import contextlib
import fnmatch import fnmatch
import glob import glob
...@@ -54,7 +55,7 @@ from .check_software import checkSoftware ...@@ -54,7 +55,7 @@ from .check_software import checkSoftware
from ..proxy.db_version import DB_VERSION from ..proxy.db_version import DB_VERSION
try: try:
from typing import Iterable, Tuple, Callable, Type, Dict, List, Optional, TypeVar from typing import Callable, ClassVar, Dict, Iterable, List, Optional, Tuple, Type, TypeVar
ManagedResourceType = TypeVar("ManagedResourceType", bound=ManagedResource) ManagedResourceType = TypeVar("ManagedResourceType", bound=ManagedResource)
except ImportError: except ImportError:
pass pass
...@@ -272,6 +273,11 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -272,6 +273,11 @@ class SlapOSInstanceTestCase(unittest.TestCase):
This class is not supposed to be imported directly, but needs to be setup by This class is not supposed to be imported directly, but needs to be setup by
calling makeModuleSetUpAndTestCaseClass. calling makeModuleSetUpAndTestCaseClass.
Attributes:
request_instance: Whether an instance needs to be requested for this test
case.
""" """
# can set this to true to enable debugging utilities # can set this to true to enable debugging utilities
_debug = False _debug = False
...@@ -290,6 +296,8 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -290,6 +296,8 @@ class SlapOSInstanceTestCase(unittest.TestCase):
# skips software rebuild # skips software rebuild
_skip_software_rebuild = False _skip_software_rebuild = False
request_instance: ClassVar[bool] = True
# a logger for messages of the testing framework # a logger for messages of the testing framework
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -402,13 +410,14 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -402,13 +410,14 @@ class SlapOSInstanceTestCase(unittest.TestCase):
getattr(cls, '__partition_reference__', '{}-'.format(cls.__name__))) getattr(cls, '__partition_reference__', '{}-'.format(cls.__name__)))
@classmethod @classmethod
def _setUpClass(cls): def _setUpClass(cls) -> None:
cls.slap.start() cls.slap.start()
# (re)format partitions # (re)format partitions
cls.formatPartitions() cls.formatPartitions()
# request # request
if cls.request_instance:
cls.requestDefaultInstance() cls.requestDefaultInstance()
# slapos node instance # slapos node instance
...@@ -421,11 +430,14 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -421,11 +430,14 @@ class SlapOSInstanceTestCase(unittest.TestCase):
# the path of the instance on the filesystem, for low level inspection # the path of the instance on the filesystem, for low level inspection
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(),
)
# the ipv6 of the instance # the ipv6 of the instance
cls.computer_partition_ipv6_address = cls.getPartitionIPv6( cls.computer_partition_ipv6_address = cls.getPartitionIPv6(
cls.computer_partition.getId()) cls.computer_partition.getId(),
)
@classmethod @classmethod
@contextlib.contextmanager @contextlib.contextmanager
...@@ -569,7 +581,7 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -569,7 +581,7 @@ class SlapOSInstanceTestCase(unittest.TestCase):
except: except:
cls.logger.exception("Error closing resource %s", resource_name) cls.logger.exception("Error closing resource %s", resource_name)
try: try:
if hasattr(cls, '_instance_parameter_dict'): if cls.request_instance and hasattr(cls, '_instance_parameter_dict'):
cls.requestDefaultInstance(state='destroyed') cls.requestDefaultInstance(state='destroyed')
except: except:
cls.logger.exception("Error during request destruction") cls.logger.exception("Error during request destruction")
......
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