Commit b83ce7f7 authored by Jérome Perrin's avatar Jérome Perrin

Fixes for testing/testcase

The main part is to address the supervisor path too long we sometimes have with theia or slaprunner tests.

Some minor fixes are also included

See merge request nexedi/slapos.core!242
parents 200122dd ea500a46
......@@ -65,7 +65,7 @@ def getSupervisorRPC(socket):
yield s.supervisor
def _getSupervisordSocketPath(instance_root):
return os.path.join(instance_root, 'supervisord.socket')
return os.path.join(instance_root, 'sv.sock')
def _getSupervisordConfigurationFilePath(instance_root):
return os.path.join(instance_root, 'etc', 'supervisord.conf')
......
......@@ -63,6 +63,7 @@ from .slap import slap
from ..util import dumps, rmtree
from ..grid.svcbackend import getSupervisorRPC
from ..grid.svcbackend import _getSupervisordSocketPath
@zope.interface.implementer(IException)
......@@ -355,7 +356,7 @@ class StandaloneSlapOS(object):
# https://github.com/torvalds/linux/blob/3848ec5/net/unix/af_unix.c#L234-L238
# Supervisord socket name contains the pid number, which is why we add
# .xxxxxxx in this check.
if len(os.path.join(base_directory, 'supervisord.socket.xxxxxxx')) > 108:
if len(os.path.join(base_directory, 'sv.sock.xxxxxxx')) > 108:
raise PathTooDeepError(
'working directory ( {base_directory} ) is too deep'.format(
**locals()))
......@@ -400,7 +401,7 @@ class StandaloneSlapOS(object):
self._instance_pid = os.path.join(run_directory, 'slapos-node-instance.pid')
self._report_pid = os.path.join(run_directory, 'slapos-node-report.pid')
self._supervisor_socket = os.path.join(run_directory, 'supervisord.sock')
self._supervisor_socket = os.path.join(run_directory, 'sv.sock')
SupervisorConfigWriter(self).writeConfig(self._supervisor_config)
SlapOSConfigWriter(self).writeConfig(self._slapos_config)
......@@ -454,9 +455,7 @@ class StandaloneSlapOS(object):
This should be used as a context manager.
"""
return getSupervisorRPC(
# this socket path is not configurable.
os.path.join(self._instance_root, "supervisord.socket"))
return getSupervisorRPC(_getSupervisordSocketPath(self._instance_root))
def format(
self,
......
......@@ -33,6 +33,7 @@ import re
import glob
import logging
import shutil
import warnings
from six.moves.urllib.parse import urlparse
try:
......@@ -112,6 +113,23 @@ def makeModuleSetUpAndTestCaseClass(
base_directory = os.path.realpath(
os.environ.get(
'SLAPOS_TEST_WORKING_DIR', os.path.join(os.getcwd(), '.slapos')))
software_id = urlparse(software_url).path.split('/')[-2]
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - {} - %(name)s - %(levelname)s - %(message)s'.format(software_id),
filename=os.path.join(snapshot_directory or base_directory, 'testcase.log'),
)
logger = logging.getLogger()
console_handler = logging.StreamHandler()
console_handler.setLevel(
logging.DEBUG if (verbose or debug) else logging.WARNING)
logger.addHandler(console_handler)
if debug:
unittest.installHandler()
# TODO: fail if already running ?
try:
slap = StandaloneSlapOS(
......@@ -124,15 +142,13 @@ def makeModuleSetUpAndTestCaseClass(
'base directory ( {} ) is too deep, try setting '
'SLAPOS_TEST_WORKING_DIR to a shallow enough directory'.format(
base_directory))
if not snapshot_directory:
snapshot_directory = os.path.join(base_directory, "snapshots")
cls = type(
'SlapOSInstanceTestCase for {}'.format(software_url),
(SlapOSInstanceTestCase,), {
'slap': slap,
'getSoftwareURL': classmethod(lambda _cls: software_url),
'software_id': urlparse(software_url).path.split('/')[-2],
'software_id': software_id,
'_debug': debug,
'_verbose': verbose,
'_ipv4_address': ipv4_address,
......@@ -149,10 +165,6 @@ def makeModuleSetUpAndTestCaseClass(
def setUpModule():
# type: () -> None
if debug:
unittest.installHandler()
logging.basicConfig(
level=logging.DEBUG if (verbose or debug) else logging.WARNING)
installSoftwareUrlList(cls, [software_url], debug=debug)
return setUpModule, SlapOSInstanceTestCase_
......@@ -362,7 +374,9 @@ def installSoftwareUrlList(cls, software_url_list, max_retry=10, debug=False):
cls.slap.waitForSoftware(max_retry=max_retry, debug=debug)
_storeSoftwareSnapshot('setupModule')
for software_url in software_url_list:
cls.logger.debug("Checking software %s", software_url)
checkSoftware(cls.slap, software_url)
cls.logger.debug("Done checking software %s", software_url)
except BaseException as e:
if not debug:
cls.logger.exception("Error building software, removing")
......@@ -376,7 +390,7 @@ def installSoftwareUrlList(cls, software_url_list, max_retry=10, debug=False):
cls.logger.exception("Error removing software")
_storeSoftwareSnapshot('setupModule removing software')
cls._cleanup('setupModule')
raise e
raise
class SlapOSInstanceTestCase(unittest.TestCase):
......@@ -589,6 +603,9 @@ class SlapOSInstanceTestCase(unittest.TestCase):
The path are made relative to slapos root directory and
we keep the same directory structure.
"""
if not cls._test_file_snapshot_directory:
warnings.warn("No snapshot directory configured, skipping snapshot")
return
# we cannot use os.path.commonpath on python2, so implement something similar
common_path = os.path.commonprefix((source_file_name, cls._base_directory))
if not os.path.isdir(common_path):
......@@ -612,10 +629,8 @@ class SlapOSInstanceTestCase(unittest.TestCase):
with open(destination, 'w') as f:
f.write('broken symink to {}\n'.format(os.readlink(source_file_name)))
elif os.path.isfile(source_file_name):
cls.logger.debug("copy %s as %s", source_file_name, destination)
shutil.copy(source_file_name, destination)
elif os.path.isdir(source_file_name):
cls.logger.debug("copy directory %s as %s", source_file_name, destination)
# we copy symlinks as symlinks, so that this does not fail when
# we copy a directory containing broken symlinks.
shutil.copytree(source_file_name, destination, symlinks=True)
......
......@@ -151,7 +151,7 @@ class BasicMixin(object):
if getattr(self, 'master_url', None) is None:
self.master_url = 'http://127.0.0.1:80/'
self.computer_id = 'computer'
self.supervisord_socket = os.path.join(self._tempdir, 'supervisord.sock')
self.supervisord_socket = os.path.join(self._tempdir, 'sv.sock')
self.supervisord_configuration_path = os.path.join(self._tempdir,
'supervisord')
self.usage_report_periodicity = 1
......@@ -227,7 +227,7 @@ class BasicMixin(object):
def assertInstanceDirectoryListEqual(self, instance_list):
instance_list.append('etc')
instance_list.append('var')
instance_list.append('supervisord.socket')
instance_list.append('sv.sock')
six.assertCountEqual(self, os.listdir(self.instance_root), instance_list)
def tearDown(self):
......
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