Commit 7ea66035 authored by Julien Muchembled's avatar Julien Muchembled

erp5.util.testnode: make --frontend_url/node_quantity optional for runUnitTest

The recently added --frontend_url parameter breaks all existing runUnitTest
scripts that don't accept it, and because this option is irrelevant for many
of them, we don't want to force everyone to update their test suites.

Similarly, parallelizing tests is not worth the effort for some test suites,
and currently, their runUnitTest scripts contain ugly lines like:

    parser.add_argument('--node_quantity', help='ignored', type=int)

These 2 parameters are now passed to runUnitTest only if it supports them,
like it is already the case for --firefox_bin and --xvfb_bin.
parent 5e149355
...@@ -15,6 +15,7 @@ from erp5.util.testnode.SlapOSControler import createFolder ...@@ -15,6 +15,7 @@ from erp5.util.testnode.SlapOSControler import createFolder
from erp5.util.taskdistribution import TaskDistributor from erp5.util.taskdistribution import TaskDistributor
from erp5.util.taskdistribution import TaskDistributionTool from erp5.util.taskdistribution import TaskDistributionTool
from erp5.util.taskdistribution import TestResultProxy from erp5.util.taskdistribution import TestResultProxy
import argparse
import os import os
import shutil import shutil
import subprocess import subprocess
...@@ -473,87 +474,57 @@ shared = true ...@@ -473,87 +474,57 @@ shared = true
test_node.checkOldTestSuite(test_suite_data) test_node.checkOldTestSuite(test_suite_data)
self.assertEquals(['foo'], os.listdir(self.working_directory)) self.assertEquals(['foo'], os.listdir(self.working_directory))
def test_08_getSupportedParamaterSet(self):
original_spawn = ProcessManager.spawn
try:
def get_help(self, *args, **kw):
return {'stdout': """My Program
--foo foo
--bar bar"""}
ProcessManager.spawn = get_help
process_manager = ProcessManager(log=None)
parameter_list = ['--foo', '--baz']
expected_suported_parameter_set = set(['--foo'])
supported_parameter_set = process_manager.getSupportedParameterSet(
"dummy_program_path", parameter_list)
self.assertEquals(expected_suported_parameter_set, supported_parameter_set)
finally:
ProcessManager.spawn = original_spawn
def test_09_runTestSuite(self, my_test_type='UnitTest'): def test_09_runTestSuite(self, my_test_type='UnitTest'):
""" """
Check parameters passed to runTestSuite Check parameters passed to runTestSuite
Also make sure that --firefox_bin and --xvfb_bin are passed when needed Also make sure that optional parameters are passed when needed
""" """
original_getSupportedParameter = ProcessManager.getSupportedParameterSet call_parameter_list = []
original_spawn = ProcessManager.spawn parser = argparse.ArgumentParser()
try: parser.add_argument('--foo', type=int)
# Create a file parser.add_argument('--hello_world', help='Hello world!')
def _createPath(path_to_create, end_path): def spawn(*args, **kw):
os.makedirs(path_to_create) if args[1] == '--help':
return os.close(os.open(os.path.join(path_to_create, return {'stdout': parser.format_help()}
end_path),os.O_CREAT)) call_parameter_list.append(args)
def get_parameters(self, *args, **kw):
call_parameter_list.append({'args': [x for x in args], 'kw':kw})
def patch_getSupportedParameterSet(self, run_test_suite_path, parameter_list,):
if '--firefox_bin' and '--xvfb_bin' in parameter_list:
return set(['--firefox_bin','--xvfb_bin'])
else:
return []
test_node = self.getTestNode() test_node = self.getTestNode()
test_node.process_manager.spawn = spawn
RunnerClass = self.returnGoodClassRunner(my_test_type) RunnerClass = self.returnGoodClassRunner(my_test_type)
runner = RunnerClass(test_node) runner = self.returnGoodClassRunner(my_test_type)(test_node)
slapos_controler = runner._getSlapOSControler(self.working_directory) slapos_controler = runner._getSlapOSControler(self.working_directory)
# Create and initialise/regenerate a nodetestsuite # Create and initialise/regenerate a nodetestsuite
node_test_suite = test_node.getNodeTestSuite('foo') node_test_suite = test_node.getNodeTestSuite('foo')
self.updateNodeTestSuiteData(node_test_suite) self.updateNodeTestSuiteData(node_test_suite)
node_test_suite.revision_list = ('dummy', (0, '')), node_test_suite.revision_list = ('dummy', (0, '')),
# Path to the dummy runable
run_test_suite_path = _createPath(
os.path.join(slapos_controler.instance_root,'a/bin'),'runTestSuite')
def checkRunTestSuiteParameters(additional_parameter_list=None): path = slapos_controler.instance_root + '/a/bin/runTestSuite'
ProcessManager.getSupportedParameterSet = patch_getSupportedParameterSet os.makedirs(os.path.dirname(path))
ProcessManager.spawn = get_parameters os.close(os.open(path, os.O_CREAT))
RunnerClass = self.returnGoodClassRunner(my_test_type)
runner = RunnerClass(test_node) expected_parameter_list = [path,
runner.runTestSuite(node_test_suite,"http://foo.bar") '--master_url', 'http://foo.bar',
expected_parameter_list = ['%s/a/bin/runTestSuite' '--revision', 'dummy=0-',
%(slapos_controler.instance_root), '--test_suite', 'Foo', '--test_suite', 'Foo',
'--revision', 'dummy=0-', '--test_suite_title', 'Foo-Test', '--test_suite_title', 'Foo-Test',
'--node_quantity', 3, '--master_url', 'http://foo.bar', ]
'--frontend_url', 'http://frontend/'] def checkRunTestSuiteParameters():
if additional_parameter_list: runner.runTestSuite(node_test_suite, "http://foo.bar")
expected_parameter_list.extend(additional_parameter_list) self.assertEqual(list(call_parameter_list.pop()), expected_parameter_list)
self.assertEqual(call_parameter_list[0]['args'], expected_parameter_list) self.assertFalse(call_parameter_list)
call_parameter_list = []
checkRunTestSuiteParameters() checkRunTestSuiteParameters()
_createPath(os.path.join(test_node.config['slapos_directory'], 'soft/a/parts/firefox'),'firefox-slapos')
_createPath(os.path.join(test_node.config['slapos_directory'], 'soft/a/parts/xserver/bin'),'Xvfb') parts = slapos_controler.instance_root + '/a/software_release/parts/'
call_parameter_list = [] for option in (
checkRunTestSuiteParameters(additional_parameter_list=['--firefox_bin', ('--firefox_bin', parts + 'firefox/firefox-slapos'),
'%s/soft/a/parts/firefox/firefox-slapos' ('--frontend_url', 'http://frontend/'),
%(test_node.config['slapos_directory']), ('--node_quantity', 3),
'--xvfb_bin', ('--xvfb_bin', parts + 'xserver/bin/Xvfb'),
'%s/soft/a/parts/xserver/bin/Xvfb' ):
%(test_node.config['slapos_directory'])]) parser.add_argument(option[0])
finally: expected_parameter_list += option
ProcessManager.getSupportedParameterSet = original_getSupportedParameter checkRunTestSuiteParameters()
ProcessManager.spawn = original_spawn
def test_10_prepareSlapOS(self, my_test_type='UnitTest'): def test_10_prepareSlapOS(self, my_test_type='UnitTest'):
test_node = self.getTestNode() test_node = self.getTestNode()
......
...@@ -183,10 +183,9 @@ class ProcessManager(object): ...@@ -183,10 +183,9 @@ class ProcessManager(object):
raise SubprocessError(result) raise SubprocessError(result)
return result return result
def getSupportedParameterSet(self, program_path ,parameter_list): def getSupportedParameterList(self, program_path):
help_string = self.spawn(*[program_path,'--help'])['stdout'] return re.findall('^ (--\w+)',
help_words = set(help_string.split()) self.spawn(program_path, '--help')['stdout'], re.M)
return help_words.intersection(set(parameter_list))
def killall(self, name): def killall(self, name):
""" """
......
...@@ -132,37 +132,32 @@ class UnitTestRunner(): ...@@ -132,37 +132,32 @@ class UnitTestRunner():
def runTestSuite(self, node_test_suite, portal_url, log=None): def runTestSuite(self, node_test_suite, portal_url, log=None):
config = self.testnode.config config = self.testnode.config
parameter_list = []
slapos_controler = self._getSlapOSControler(self.testnode.working_directory) slapos_controler = self._getSlapOSControler(self.testnode.working_directory)
run_test_suite_path_list = sorted(glob.glob("%s/*/bin/runTestSuite" % \ run_test_suite_path_list = sorted(glob.glob("%s/*/bin/runTestSuite" % \
slapos_controler.instance_root)) slapos_controler.instance_root))
if not len(run_test_suite_path_list): if not len(run_test_suite_path_list):
raise ValueError('No runTestSuite provided in installed partitions.') raise ValueError('No runTestSuite provided in installed partitions.')
run_test_suite_path = run_test_suite_path_list[0] run_test_suite_path = run_test_suite_path_list[0]
run_test_suite_revision = node_test_suite.revision
# Deal with Shebang size limitation # Deal with Shebang size limitation
invocation_list = dealShebang(run_test_suite_path) invocation_list = dealShebang(run_test_suite_path)
invocation_list.extend([run_test_suite_path, invocation_list += (run_test_suite_path,
'--test_suite', node_test_suite.test_suite,
'--revision', node_test_suite.revision,
'--test_suite_title', node_test_suite.test_suite_title,
'--node_quantity', config['node_quantity'],
'--master_url', portal_url, '--master_url', portal_url,
'--frontend_url', config['frontend_url']]) '--revision', node_test_suite.revision,
firefox_bin_list = glob.glob("%s/soft/*/parts/firefox/firefox-slapos" % \ '--test_suite', node_test_suite.test_suite,
config["slapos_directory"]) '--test_suite_title', node_test_suite.test_suite_title)
if len(firefox_bin_list): supported_parameter_set = set(self.testnode.process_manager
parameter_list.append('--firefox_bin') .getSupportedParameterList(run_test_suite_path))
xvfb_bin_list = glob.glob("%s/soft/*/parts/xserver/bin/Xvfb" % \ parts = os.path.dirname(os.path.dirname(run_test_suite_path))
config["slapos_directory"]) parts += '/software_release/parts/'
if len(xvfb_bin_list): for option in (
parameter_list.append('--xvfb_bin') ('--firefox_bin', parts + 'firefox/firefox-slapos'),
supported_paramater_set = self.testnode.process_manager.getSupportedParameterSet( ('--frontend_url', config['frontend_url']),
run_test_suite_path, parameter_list) ('--node_quantity', config['node_quantity']),
if '--firefox_bin' in supported_paramater_set: ('--xvfb_bin', parts + 'xserver/bin/Xvfb'),
invocation_list.extend(["--firefox_bin", firefox_bin_list[0]]) ):
if '--xvfb_bin' in supported_paramater_set: if option[0] in supported_parameter_set:
invocation_list.extend(["--xvfb_bin", xvfb_bin_list[0]]) invocation_list += option
# TODO : include testnode correction ( b111682f14890bf ) # TODO : include testnode correction ( b111682f14890bf )
if hasattr(node_test_suite,'additional_bt5_repository_id'): if hasattr(node_test_suite,'additional_bt5_repository_id'):
additional_bt5_path = os.path.join( additional_bt5_path = os.path.join(
......
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