Commit de3b25b3 authored by Łukasz Nowak's avatar Łukasz Nowak

First version of working runTestSuite

parent dd0cb4fe
...@@ -8,8 +8,10 @@ recipe = slapos.recipe.template:jinja2 ...@@ -8,8 +8,10 @@ recipe = slapos.recipe.template:jinja2
rendered = $${buildout:directory}/bin/$${:_buildout_section_name_} rendered = $${buildout:directory}/bin/$${:_buildout_section_name_}
template = inline: template = inline:
#!/bin/sh #!/bin/sh
exec ${buildout:bin-directory}/${runTestSuite_py:interpreter} ${:_profile_base_location_}/$${:_buildout_section_name_}.py "$@" exec ${buildout:bin-directory}/${runTestSuite_py:interpreter} ${:_profile_base_location_}/$${:_buildout_section_name_}.py --partition_path $${buildout:directory} --image_reference "{{ slapparameter_dict.get('image-to-test-url') }}" "$@"
mode = 0755 mode = 0755
context =
key slapparameter_dict slap-configuration:configuration
[switch-softwaretype] [switch-softwaretype]
default = $${:cdn-test} default = $${:cdn-test}
......
from __future__ import print_function from __future__ import print_function
import argparse import argparse
import os
import glob
from time import gmtime, strftime, time, sleep from time import gmtime, strftime, time, sleep
from erp5.util import taskdistribution from erp5.util import taskdistribution
from erp5.util.testsuite import format_command
class DummyTestResult: class DummyTestResult:
...@@ -10,8 +11,9 @@ class DummyTestResult: ...@@ -10,8 +11,9 @@ class DummyTestResult:
class DummyTestResultLine: class DummyTestResultLine:
def stop(self, duration, stdout='', **kw): def stop(self, duration, stdout='', **kw):
print('stop: %s' % (kw,)) print('stop:')
print('\n' + stdout) print('\n' + stdout)
print('stop: %s' % (kw,))
print('Ran in %.3fs' % duration) print('Ran in %.3fs' % duration)
done = 0 done = 0
...@@ -30,8 +32,6 @@ class DummyTestResult: ...@@ -30,8 +32,6 @@ class DummyTestResult:
print("start: %s" % (test_result_line.name,)) print("start: %s" % (test_result_line.name,))
return test_result_line return test_result_line
test_list = ['dummy']
def main(): def main():
parser = argparse.ArgumentParser(description='Run a test suite.') parser = argparse.ArgumentParser(description='Run a test suite.')
...@@ -45,9 +45,19 @@ def main(): ...@@ -45,9 +45,19 @@ def main():
help='Number of CPUs to use for the VM') help='Number of CPUs to use for the VM')
parser.add_argument('--master_url', parser.add_argument('--master_url',
help='The Url of Master controlling test suites') help='The Url of Master controlling test suites')
# SlapOS and ERP5TestNode specific
parser.add_argument(
'--partition_path',
help="Path of a partition",
default=os.path.abspath(os.getcwd()))
parser.add_argument(
'--image_reference',
help="Reference of tested image",
default="missing"
)
args = parser.parse_args() args = parser.parse_args()
test_list = [args.image_reference]
test_title = args.test_suite_title or args.test_suite test_title = args.test_suite_title or args.test_suite
if args.master_url: if args.master_url:
tool = taskdistribution.TaskDistributionTool(args.master_url) tool = taskdistribution.TaskDistributionTool(args.master_url)
...@@ -65,15 +75,76 @@ def main(): ...@@ -65,15 +75,76 @@ def main():
test_result_line = test_result.start() test_result_line = test_result.start()
if not test_result_line: if not test_result_line:
break break
test = test_result_line.name status_dict = {'command': 'file not found'}
cmd = ['parsed', 'in-vm-test', 'output', test]
status_dict = {'command': format_command(*cmd)}
status_dict['stderr'] = 'Standard error'
status_dict['stdout'] = 'Standard output'
# find test result, wait 10h
sleep_time = 10
try_amount = (3600 * 10) / sleep_time
try_num = 1
result_path = None
start = time() start = time()
sleep(2) while 1:
result_list = glob.glob(
os.path.join(
args.partition_path,
'..',
'*',
'srv',
'public',
'test-script-result',
))
if len(result_list) > 0:
result_path = result_list[0]
break
if try_num > try_amount:
break
sleep(10)
if result_path is None:
status_dict['stdout'] = 'Test timed out and no result found.'
status_dict.update(
test_count=0,
skip_count=0,
failure_count=0,
error_count=0
)
else:
oldest_result = min(
(os.path.join(dirname, filename)
for dirname, dirnames, filenames in os.walk(result_path)
for filename in filenames
),
key=lambda fn: os.stat(fn).st_mtime)
if oldest_result is None:
status_dict['stdout'] = 'Test finished but no result found.'
status_dict.update(
test_count=1,
skip_count=0,
failure_count=0,
error_count=1
)
else:
oldest_result = os.path.abspath(oldest_result)
status_dict['command'] = oldest_result
result = open(oldest_result).read()
if 'FATAL: all hosts have already failed -- aborting' in result:
# failed
status_dict.update(
test_count=1,
skip_count=0,
failure_count=1,
error_count=0
)
elif "\"msg\": \"[u'Build successful, connect to:', u'" in result:
# success
status_dict.update(
test_count=1,
skip_count=0,
failure_count=0,
error_count=0
)
pass
status_dict['stdout'] = result
end = time() end = time()
test_result_line.stop( test_result_line.stop(
......
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