[Fuego] [PATCH 04/30] plantest_class: rename it and override values in order
Daniel Sangorrin
daniel.sangorrin at toshiba.co.jp
Mon Jun 4 07:17:38 UTC 2018
I replaced plantest_class by test_class because it
is used to describe a test, and not only one that comes
from a testplan.
Then I added logic so that test flags (reboot, rebuild etc)
are overriden according to the next criteria:
commandline flags > per-test flags > default_xxx flags > DEFAULT_DEFAULTS
Signed-off-by: Daniel Sangorrin <daniel.sangorrin at toshiba.co.jp>
---
engine/scripts/ftc | 108 +++++++++++++++++++++++++++++------------------------
1 file changed, 59 insertions(+), 49 deletions(-)
diff --git a/engine/scripts/ftc b/engine/scripts/ftc
index a9c0c4f..449b9cf 100755
--- a/engine/scripts/ftc
+++ b/engine/scripts/ftc
@@ -605,17 +605,28 @@ class board_class:
# FIXTHIS - board_class should have methods to read board and dist file
-class plantest_class:
- def __init__(self, test_dict, defaults):
+class test_class:
+ DEFAULT_DEFAULTS = {
+ 'timeout' : '30m',
+ 'spec' : 'default',
+ 'reboot' : 'false',
+ 'rebuild' : 'false',
+ 'precleanup' : 'true',
+ 'postcleanup' : 'true'
+ }
+ def __init__(self, test_dict, test_flags={}):
+ merged_defaults = dict(self.DEFAULT_DEFAULTS)
+ for key, value in test_flags.iteritems():
+ merged_defaults[key] = value
self.name = str(test_dict["testName"])
self.test_type = self.name.split(".")[0]
self.base_name = self.name.split(".")[1]
- self.spec = str(test_dict.get("spec", defaults['spec']))
- self.timeout = str(test_dict.get("timeout", defaults['timeout']))
- self.reboot = str(test_dict.get("reboot", defaults['reboot']))
- self.rebuild = str(test_dict.get("rebuild", defaults['rebuild']))
- self.precleanup = str(test_dict.get("precleanup", defaults['precleanup']))
- self.postcleanup = str(test_dict.get("postcleanup", defaults['postcleanup']))
+ self.spec = str(test_dict.get("spec", merged_defaults['spec']))
+ self.timeout = str(test_dict.get("timeout", merged_defaults['timeout']))
+ self.reboot = str(test_dict.get("reboot", merged_defaults['reboot']))
+ self.rebuild = str(test_dict.get("rebuild", merged_defaults['rebuild']))
+ self.precleanup = str(test_dict.get("precleanup", merged_defaults['precleanup']))
+ self.postcleanup = str(test_dict.get("postcleanup", merged_defaults['postcleanup']))
class run_class:
@@ -1366,42 +1377,54 @@ def create_batch_job(board, testplan, plan_tests):
sys.exit(1)
-# returns a list of plantest_class instances
-def parse_testplan(testplan, defaults):
+# parse the testplan and returns a list of test_class instances where
+# test flags (timeout, reboot, etc) have been merged in this order
+# commandline flags > per-test flags > default_xxx flags > DEFAULT_DEFAULTS
+def parse_testplan(testplan, test_dict):
abspath = '/fuego-core/engine/overlays/testplans/' + testplan + '.json'
- plan_tests = []
with open(abspath, "r") as f:
plan = json.load(f)
- if 'default_timeout' in plan:
- defaults['timeout'] = plan['default_timeout']
+ plan_tests = []
+ for plan_test_dict in plan['tests']:
+ # set testplan flags
+ test_flags = dict()
+ if 'default_timeout' in plan:
+ test_flags['timeout'] = plan['default_timeout']
- if 'default_spec' in plan:
- defaults['spec'] = plan['default_spec']
+ if 'default_spec' in plan:
+ test_flags['spec'] = plan['default_spec']
- if 'default_reboot' in plan:
- defaults['reboot'] = plan['default_reboot']
+ if 'default_reboot' in plan:
+ test_flags['reboot'] = plan['default_reboot']
- if 'default_rebuild' in plan:
- defaults['rebuild'] = plan['default_rebuild']
+ if 'default_rebuild' in plan:
+ test_flags['rebuild'] = plan['default_rebuild']
- if 'default_precleanup' in plan:
- defaults['precleanup'] = plan['default_precleanup']
+ if 'default_precleanup' in plan:
+ test_flags['precleanup'] = plan['default_precleanup']
- if 'default_postcleanup' in plan:
- defaults['postcleanup'] = plan['default_postcleanup']
+ if 'default_postcleanup' in plan:
+ test_flags['postcleanup'] = plan['default_postcleanup']
+ # override with testplan per-test flags
+ for key, value in plan_test_dict.iteritems():
+ if key == "testName":
+ test_dict[key] = value
+ continue
+ test_flags[key] = value
- for test_dict in plan['tests']:
- # test_dict is a dictionary with values for the test
- test = plantest_class(test_dict, defaults)
+ # test_class overrides flags with those in test_dict and applies
+ # DEFAULT_DEFAULTS for non-specified flags
+ test = test_class(test_dict, test_flags)
plan_tests.append(test)
return plan_tests
def do_add_jobs(conf, options):
+ test_dict = {}
if '-b' in options:
try:
board = options[options.index('-b') + 1]
@@ -1409,7 +1432,7 @@ def do_add_jobs(conf, options):
error_out("Board not provided after -b.")
options.remove('-b')
options.remove(board)
-
+ test_dict["board"] = board
boards = board.split(",")
board_list = get_fuego_boards(conf).keys()
for board in boards:
@@ -1426,8 +1449,10 @@ def do_add_jobs(conf, options):
error_out('Rebuild option not provided after --rebuild')
if rebuild not in ['true', 'false']:
error_out("Invalid rebuild option '%s'" % rebuild)
+ options.remove(rebuild)
+ options.remove('--rebuild')
+ test_dict["rebuild"] = rebuild
- timeout = '30m'
if '-p' in options:
try:
testplan = options[options.index('-p') + 1]
@@ -1442,6 +1467,7 @@ def do_add_jobs(conf, options):
elif '-t' in options:
# FIXTHIS: have add-jobs support wildcards in the test name
test_name, options = get_test_arg("Add-jobs", conf, options)
+ test_dict["testName"] = test_name
if '-s' in options:
try:
spec = options[options.index('-s') + 1]
@@ -1452,42 +1478,26 @@ def do_add_jobs(conf, options):
error_out('Unknown spec %s' % spec)
options.remove('-s')
options.remove(spec)
- else:
- spec = 'default'
+ test_dict["spec"] = spec
+
if '-k' in options:
try:
timeout = options[options.index('-k') + 1]
options.remove('-k')
except IndexError:
error_out('No timeout specified after -k')
-
+ test_dict["timeout"] = timeout
else:
error_out('No testplan or testcase supplied.')
- defaults = {
- 'timeout' : '30m',
- 'spec' : 'default',
- 'reboot' : 'false',
- 'rebuild' : 'false',
- 'precleanup' : 'true',
- 'postcleanup' : 'true'
- }
-
if test_name:
- # FIXTHIS - we could parse more parameters for the job here, from the ftc command line
- # use all defaults, except for the spec
- tp_dict = {"testName": test_name, "timeout": timeout, "spec": spec }
- if rebuild:
- tp_dict["rebuild"] = rebuild
- test = plantest_class(tp_dict, defaults)
+ test = test_class(test_dict)
for board in boards:
create_job(board, test)
else:
- plan_tests = parse_testplan(testplan, defaults)
+ plan_tests = parse_testplan(testplan, test_dict)
for board in boards:
for test in plan_tests:
- if rebuild:
- test.rebuild = rebuild
create_job(board, test)
create_batch_job(board, testplan, plan_tests)
sys.exit(0)
--
2.7.4
More information about the Fuego
mailing list