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): test_node = self.getTestNode()
call_parameter_list.append({'args': [x for x in args], 'kw':kw}) test_node.process_manager.spawn = spawn
RunnerClass = self.returnGoodClassRunner(my_test_type)
runner = self.returnGoodClassRunner(my_test_type)(test_node)
slapos_controler = runner._getSlapOSControler(self.working_directory)
# Create and initialise/regenerate a nodetestsuite
node_test_suite = test_node.getNodeTestSuite('foo')
self.updateNodeTestSuiteData(node_test_suite)
node_test_suite.revision_list = ('dummy', (0, '')),
def patch_getSupportedParameterSet(self, run_test_suite_path, parameter_list,): path = slapos_controler.instance_root + '/a/bin/runTestSuite'
if '--firefox_bin' and '--xvfb_bin' in parameter_list: os.makedirs(os.path.dirname(path))
return set(['--firefox_bin','--xvfb_bin']) os.close(os.open(path, os.O_CREAT))
else:
return []
test_node = self.getTestNode() expected_parameter_list = [path,
RunnerClass = self.returnGoodClassRunner(my_test_type) '--master_url', 'http://foo.bar',
runner = RunnerClass(test_node) '--revision', 'dummy=0-',
slapos_controler = runner._getSlapOSControler(self.working_directory) '--test_suite', 'Foo',
# Create and initialise/regenerate a nodetestsuite '--test_suite_title', 'Foo-Test',
node_test_suite = test_node.getNodeTestSuite('foo') ]
self.updateNodeTestSuiteData(node_test_suite) def checkRunTestSuiteParameters():
node_test_suite.revision_list = ('dummy', (0, '')), runner.runTestSuite(node_test_suite, "http://foo.bar")
# Path to the dummy runable self.assertEqual(list(call_parameter_list.pop()), expected_parameter_list)
run_test_suite_path = _createPath( self.assertFalse(call_parameter_list)
os.path.join(slapos_controler.instance_root,'a/bin'),'runTestSuite')
def checkRunTestSuiteParameters(additional_parameter_list=None): checkRunTestSuiteParameters()
ProcessManager.getSupportedParameterSet = patch_getSupportedParameterSet
ProcessManager.spawn = get_parameters
RunnerClass = self.returnGoodClassRunner(my_test_type)
runner = RunnerClass(test_node)
runner.runTestSuite(node_test_suite,"http://foo.bar")
expected_parameter_list = ['%s/a/bin/runTestSuite'
%(slapos_controler.instance_root), '--test_suite', 'Foo',
'--revision', 'dummy=0-', '--test_suite_title', 'Foo-Test',
'--node_quantity', 3, '--master_url', 'http://foo.bar',
'--frontend_url', 'http://frontend/']
if additional_parameter_list:
expected_parameter_list.extend(additional_parameter_list)
self.assertEqual(call_parameter_list[0]['args'], expected_parameter_list)
call_parameter_list = [] parts = slapos_controler.instance_root + '/a/software_release/parts/'
for option in (
('--firefox_bin', parts + 'firefox/firefox-slapos'),
('--frontend_url', 'http://frontend/'),
('--node_quantity', 3),
('--xvfb_bin', parts + 'xserver/bin/Xvfb'),
):
parser.add_argument(option[0])
expected_parameter_list += option
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')
call_parameter_list = []
checkRunTestSuiteParameters(additional_parameter_list=['--firefox_bin',
'%s/soft/a/parts/firefox/firefox-slapos'
%(test_node.config['slapos_directory']),
'--xvfb_bin',
'%s/soft/a/parts/xserver/bin/Xvfb'
%(test_node.config['slapos_directory'])])
finally:
ProcessManager.getSupportedParameterSet = original_getSupportedParameter
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, '--master_url', portal_url,
'--revision', node_test_suite.revision, '--revision', node_test_suite.revision,
'--test_suite_title', node_test_suite.test_suite_title, '--test_suite', node_test_suite.test_suite,
'--node_quantity', config['node_quantity'], '--test_suite_title', node_test_suite.test_suite_title)
'--master_url', portal_url, supported_parameter_set = set(self.testnode.process_manager
'--frontend_url', config['frontend_url']]) .getSupportedParameterList(run_test_suite_path))
firefox_bin_list = glob.glob("%s/soft/*/parts/firefox/firefox-slapos" % \ parts = os.path.dirname(os.path.dirname(run_test_suite_path))
config["slapos_directory"]) parts += '/software_release/parts/'
if len(firefox_bin_list): for option in (
parameter_list.append('--firefox_bin') ('--firefox_bin', parts + 'firefox/firefox-slapos'),
xvfb_bin_list = glob.glob("%s/soft/*/parts/xserver/bin/Xvfb" % \ ('--frontend_url', config['frontend_url']),
config["slapos_directory"]) ('--node_quantity', config['node_quantity']),
if len(xvfb_bin_list): ('--xvfb_bin', parts + 'xserver/bin/Xvfb'),
parameter_list.append('--xvfb_bin') ):
supported_paramater_set = self.testnode.process_manager.getSupportedParameterSet( if option[0] in supported_parameter_set:
run_test_suite_path, parameter_list) invocation_list += option
if '--firefox_bin' in supported_paramater_set:
invocation_list.extend(["--firefox_bin", firefox_bin_list[0]])
if '--xvfb_bin' in supported_paramater_set:
invocation_list.extend(["--xvfb_bin", xvfb_bin_list[0]])
# 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