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
rendered = $${buildout:directory}/bin/$${:_buildout_section_name_}
template = inline:
#!/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
context =
key slapparameter_dict slap-configuration:configuration
[switch-softwaretype]
default = $${:cdn-test}
......
from __future__ import print_function
import argparse
import os
import glob
from time import gmtime, strftime, time, sleep
from erp5.util import taskdistribution
from erp5.util.testsuite import format_command
class DummyTestResult:
......@@ -10,8 +11,9 @@ class DummyTestResult:
class DummyTestResultLine:
def stop(self, duration, stdout='', **kw):
print('stop: %s' % (kw,))
print('stop:')
print('\n' + stdout)
print('stop: %s' % (kw,))
print('Ran in %.3fs' % duration)
done = 0
......@@ -30,8 +32,6 @@ class DummyTestResult:
print("start: %s" % (test_result_line.name,))
return test_result_line
test_list = ['dummy']
def main():
parser = argparse.ArgumentParser(description='Run a test suite.')
......@@ -45,9 +45,19 @@ def main():
help='Number of CPUs to use for the VM')
parser.add_argument('--master_url',
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()
test_list = [args.image_reference]
test_title = args.test_suite_title or args.test_suite
if args.master_url:
tool = taskdistribution.TaskDistributionTool(args.master_url)
......@@ -65,15 +75,76 @@ def main():
test_result_line = test_result.start()
if not test_result_line:
break
test = test_result_line.name
cmd = ['parsed', 'in-vm-test', 'output', test]
status_dict = {'command': format_command(*cmd)}
status_dict['stderr'] = 'Standard error'
status_dict['stdout'] = 'Standard output'
status_dict = {'command': 'file not found'}
# find test result, wait 10h
sleep_time = 10
try_amount = (3600 * 10) / sleep_time
try_num = 1
result_path = None
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()
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