Commit 2138e2ce authored by Jérome Perrin's avatar Jérome Perrin

testing/testcase: cleanups

Fix long lines, incorrect type annotations and adjust a bit to make mypy
happy.
parent fea3bd23
...@@ -37,7 +37,7 @@ from six.moves.urllib.parse import urlparse ...@@ -37,7 +37,7 @@ from six.moves.urllib.parse import urlparse
try: try:
import subprocess32 as subprocess import subprocess32 as subprocess
except ImportError: except ImportError:
import subprocess import subprocess # type: ignore
subprocess # pyflakes subprocess # pyflakes
from .utils import getPortFromPath from .utils import getPortFromPath
...@@ -49,7 +49,7 @@ from ..grid.utils import md5digest ...@@ -49,7 +49,7 @@ from ..grid.utils import md5digest
from ..util import mkdir_p from ..util import mkdir_p
try: try:
from typing import Iterable, Tuple, Callable, Type from typing import Iterable, Tuple, Callable, Type, Dict, List, Optional
except ImportError: except ImportError:
pass pass
...@@ -63,9 +63,9 @@ def makeModuleSetUpAndTestCaseClass( ...@@ -63,9 +63,9 @@ def makeModuleSetUpAndTestCaseClass(
verbose=bool(int(os.environ.get('SLAPOS_TEST_VERBOSE', 0))), verbose=bool(int(os.environ.get('SLAPOS_TEST_VERBOSE', 0))),
shared_part_list=os.environ.get('SLAPOS_TEST_SHARED_PART_LIST', shared_part_list=os.environ.get('SLAPOS_TEST_SHARED_PART_LIST',
'').split(os.pathsep), '').split(os.pathsep),
snapshot_directory=os.environ.get('SLAPOS_TEST_LOG_DIRECTORY') snapshot_directory=os.environ.get('SLAPOS_TEST_LOG_DIRECTORY'),
): ):
# type: (str, str, str, str, bool, bool, List[str]) -> Tuple[Callable[[], None], Type[SlapOSInstanceTestCase]] # type: (str, str, str, str, bool, bool, Iterable[str], Optional[str]) -> Tuple[Callable[[], None], Type[SlapOSInstanceTestCase]]
"""Create a setup module function and a testcase for testing `software_url`. """Create a setup module function and a testcase for testing `software_url`.
This function returns a tuple of two arguments: This function returns a tuple of two arguments:
...@@ -124,7 +124,6 @@ def makeModuleSetUpAndTestCaseClass( ...@@ -124,7 +124,6 @@ def makeModuleSetUpAndTestCaseClass(
if not snapshot_directory: if not snapshot_directory:
snapshot_directory = os.path.join(base_directory, "snapshots") snapshot_directory = os.path.join(base_directory, "snapshots")
cls = type( cls = type(
'SlapOSInstanceTestCase for {}'.format(software_url), 'SlapOSInstanceTestCase for {}'.format(software_url),
(SlapOSInstanceTestCase,), { (SlapOSInstanceTestCase,), {
...@@ -139,7 +138,9 @@ def makeModuleSetUpAndTestCaseClass( ...@@ -139,7 +138,9 @@ def makeModuleSetUpAndTestCaseClass(
'_test_file_snapshot_directory': snapshot_directory '_test_file_snapshot_directory': snapshot_directory
}) })
class SlapOSInstanceTestCase_(cls, SlapOSInstanceTestCase): class SlapOSInstanceTestCase_(
cls, # type: ignore # https://github.com/python/mypy/issues/2813
SlapOSInstanceTestCase):
# useless intermediate class so that editors provide completion anyway. # useless intermediate class so that editors provide completion anyway.
pass pass
...@@ -204,10 +205,10 @@ def checkSoftware(slap, software_url): ...@@ -204,10 +205,10 @@ def checkSoftware(slap, software_url):
'.*slapos.*.signature')): '.*slapos.*.signature')):
with open(signature_file) as f: with open(signature_file) as f:
signature_content = f.read() signature_content = f.read()
if software_hash in signature_content: if software_hash in signature_content:
error_list.append( error_list.append(
"Software hash present in signature {}\n{}\n".format( "Software hash present in signature {}\n{}\n".format(
signature_file, signature_content)) signature_file, signature_content))
if error_list: if error_list:
raise RuntimeError('\n'.join(error_list)) raise RuntimeError('\n'.join(error_list))
...@@ -403,7 +404,8 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -403,7 +404,8 @@ class SlapOSInstanceTestCase(unittest.TestCase):
""" """
cls._cleanup("{}.{}.tearDownClass".format(cls.__module__, cls.__name__)) cls._cleanup("{}.{}.tearDownClass".format(cls.__module__, cls.__name__))
if not cls._debug: if not cls._debug:
cls.logger.debug("cleaning up slapos log files in %s", cls.slap._log_directory) cls.logger.debug(
"cleaning up slapos log files in %s", cls.slap._log_directory)
for log_file in glob.glob(os.path.join(cls.slap._log_directory, '*')): for log_file in glob.glob(os.path.join(cls.slap._log_directory, '*')):
os.unlink(log_file) os.unlink(log_file)
...@@ -524,11 +526,12 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -524,11 +526,12 @@ class SlapOSInstanceTestCase(unittest.TestCase):
"{}._cleanup leaked_partitions".format(snapshot_name)) "{}._cleanup leaked_partitions".format(snapshot_name))
for cp in leaked_partitions: for cp in leaked_partitions:
try: try:
# XXX is this really the reference ?
partition_reference = cp.getInstanceParameterDict()['instance_title']
cls.slap.request( cls.slap.request(
software_release=cp.getSoftwareRelease().getURI(), software_release=cp.getSoftwareRelease().getURI(),
# software_type=cp.getType(), # TODO # software_type=cp.getType(), # TODO
# XXX is this really the reference ? partition_reference=partition_reference,
partition_reference=cp.getInstanceParameterDict()['instance_title'],
state="destroyed") state="destroyed")
except: except:
cls.logger.exception( cls.logger.exception(
...@@ -549,10 +552,14 @@ class SlapOSInstanceTestCase(unittest.TestCase): ...@@ -549,10 +552,14 @@ class SlapOSInstanceTestCase(unittest.TestCase):
cls.logger.exception("Error during stop") cls.logger.exception("Error during stop")
cls._storeSystemSnapshot("{}._cleanup stop".format(snapshot_name)) cls._storeSystemSnapshot("{}._cleanup stop".format(snapshot_name))
leaked_supervisor_configs = glob.glob( leaked_supervisor_configs = glob.glob(
os.path.join(cls.slap.instance_directory, 'etc', 'supervisord.conf.d', '*.conf')) os.path.join(
cls.slap.instance_directory, 'etc', 'supervisord.conf.d', '*.conf'))
if leaked_supervisor_configs: if leaked_supervisor_configs:
[os.unlink(config) for config in leaked_supervisor_configs] for config in leaked_supervisor_configs:
raise AssertionError("Test leaked supervisor configurations: %s" % leaked_supervisor_configs) os.unlink(config)
raise AssertionError(
"Test leaked supervisor configurations: %s" %
leaked_supervisor_configs)
@classmethod @classmethod
def requestDefaultInstance(cls, state='started'): def requestDefaultInstance(cls, state='started'):
......
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