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

testnode: pass arguments as environment variables

SLAPOS_TEST_LOG_DIRECTORY and SLAPOS_TEST_SHARED_PART_LIST have been
introduced recently, they are passed to runTestSuite using the usual
way of running runTestSuite once with --help to inspect supported
arguments and passing the argument only if runTestSuite supports them,
but these arguments are not necessarily heavy to compute and are always
known (unlike for example firefox path which is only known if seleniumrunner
extra software was installed), so simplify all this by passing the
parameters are environment variables.
parent cb2a7c63
......@@ -620,6 +620,7 @@ shared = true
def test_distributor_url_obfuscated_in_logs(self):
test_node = self.getTestNode()
del test_node.suiteLog
runner = test_type_registry['UnitTest'](test_node)
node_test_suite = test_node.getNodeTestSuite('foo')
......@@ -635,7 +636,8 @@ shared = true
""".format(temp_file.name))
os.chmod(path, 0o700)
with mock.patch.object(logger, '_log') as http_logger,\
with test_node.suiteLog(node_test_suite),\
mock.patch.object(logger, '_log') as http_logger,\
mock.patch.object(logging.getLogger(), '_log') as root_logger,\
mock.patch.object(logging.getLogger(), 'isEnabledFor', return_value=True):
runner.runTestSuite(node_test_suite, "https://user:secret@example.com/portal_distributions")
......@@ -676,7 +678,8 @@ shared = true
call_parameter_list.append(args)
test_node = self.getTestNode()
with mock.patch.object(test_node.process_manager, 'spawn', side_effect=spawn):
del test_node.suiteLog
with mock.patch.object(test_node.process_manager, 'spawn', side_effect=spawn) as spawn_mock:
runner = test_type_registry[my_test_type](test_node)
# Create and initialise/regenerate a nodetestsuite
node_test_suite = test_node.getNodeTestSuite('foo')
......@@ -695,9 +698,16 @@ shared = true
'--test_suite_title', 'Foo-Test',
]
def checkRunTestSuiteParameters():
runner.runTestSuite(node_test_suite, "http://foo.bar")
with test_node.suiteLog(node_test_suite) as suite_log:
runner.runTestSuite(node_test_suite, "http://foo.bar")
self.assertEqual(list(call_parameter_list.pop()), expected_parameter_list)
self.assertFalse(call_parameter_list)
self.assertEqual(
spawn_mock.call_args[-1]['SLAPOS_TEST_SHARED_PART_LIST'],
"/not/exists:/not/exists_either:%s/shared" % node_test_suite.working_directory)
self.assertEqual(
spawn_mock.call_args[-1]['SLAPOS_TEST_LOG_DIRECTORY'],
os.path.join(test_node.config['log_directory'], suite_log))
checkRunTestSuiteParameters()
......
......@@ -150,6 +150,12 @@ class UnitTestRunner(object):
software_list = [soft + md5digest(x) for x in config['software_list']]
PATH = os.getenv('PATH', '')
PATH = ':'.join(x + '/bin' for x in software_list) + (PATH and ':' + PATH)
SLAPOS_TEST_SHARED_PART_LIST = os.pathsep.join(
self._getSlapOSControler(
node_test_suite.working_directory,
True
).shared_part_list)
SLAPOS_TEST_LOG_DIRECTORY = node_test_suite.log_folder_path
supported_parameter_set = set(self.testnode.process_manager
.getSupportedParameterList(run_test_suite_path))
def path(name, compat): # BBB
......@@ -163,12 +169,8 @@ class UnitTestRunner(object):
('--node_quantity', lambda: config['node_quantity']),
('--xvfb_bin', lambda: path('xvfb', 'xserver/bin/Xvfb')),
('--project_title', lambda: node_test_suite.project_title),
('--shared_part_list', lambda: os.pathsep.join(
self._getSlapOSControler(
node_test_suite.working_directory,
True
).shared_part_list)),
('--log_directory', lambda: node_test_suite.log_folder_path),
('--shared_part_list', lambda: SLAPOS_TEST_SHARED_PART_LIST),
('--log_directory', lambda: SLAPOS_TEST_LOG_DIRECTORY),
):
if option in supported_parameter_set:
invocation_list += option, value()
......@@ -195,6 +197,8 @@ class UnitTestRunner(object):
return s.replace(portal_url.encode('utf-8'), b'$DISTRIBUTOR_URL')
self.testnode.process_manager.spawn(*invocation_list, PATH=PATH,
SLAPOS_TEST_SHARED_PART_LIST=SLAPOS_TEST_SHARED_PART_LIST,
SLAPOS_TEST_LOG_DIRECTORY=SLAPOS_TEST_LOG_DIRECTORY,
cwd=node_test_suite.test_suite_directory,
log_prefix='runTestSuite',
output_replacers=(hide_distributor_url,),
......
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