[Fuego] [PATCH 24/30] run-test: support dynamic variables

Daniel Sangorrin daniel.sangorrin at toshiba.co.jp
Mon Jun 4 07:17:58 UTC 2018


A spec is created and saved in the logdir folder. This is
good not only for dynamic variables but also for static specs
because we can easily package the logdir folder with all
the important data.

Signed-off-by: Daniel Sangorrin <daniel.sangorrin at toshiba.co.jp>
---
 engine/scripts/ftc | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/engine/scripts/ftc b/engine/scripts/ftc
index 7da4f27..bfdc3d4 100755
--- a/engine/scripts/ftc
+++ b/engine/scripts/ftc
@@ -3164,6 +3164,18 @@ def do_run_test(conf, options):
     else:
         error_out("Run-test command requires a test name")
 
+    if '--dynamic-vars' in options:
+        try:
+            import ast
+            dyn_vars_str = options[options.index('--dynamic-vars') + 1]
+            dyn_vars = ast.literal_eval(dyn_vars_str)
+        except IndexError:
+            error_out('Dynamic vars not provided after --dynamic-vars.')
+        options.remove(dyn_vars_str)
+        options.remove('--dynamic-vars')
+    else:
+        dyn_vars = None
+
     if '-s' in options:
         try:
             spec_name = options[options.index('-s') + 1]
@@ -3171,7 +3183,8 @@ def do_run_test(conf, options):
             error_out('Testspec not provided after -s.')
         spec_list = get_specs(conf, test_name)
         if spec_name not in spec_list:
-            error_out('Unknown spec %s' % spec_name)
+            if not dyn_vars:
+                error_out('Unknown spec %s' % spec_name)
         options.remove(spec_name)
         options.remove('-s')
     else:
@@ -3369,6 +3382,38 @@ def do_run_test(conf, options):
     build_data.timestamp = timestamp
     os.environ["BUILD_TIMESTAMP"] = build_data.timestamp
 
+    # create a folder for this run
+    run_dir = job_dir + "/builds/" + build_data.build_number
+    if not os.path.isdir(run_dir):
+        if fuego_caller == "jenkins":
+            error_out("Jenkins did not create run folder " + run_dir)
+        os.mkdir(run_dir)
+
+    # prepare a per-run spec.json file
+    specpath = '%s/engine/tests/%s/spec.json' % (conf.FUEGO_CORE, test_name)
+    with open(specpath) as f:
+        try:
+            test_spec_data = json.load(f)
+        except:
+            error_out("Error parsing spec file %s" % specpath)
+
+    for key in test_spec_data['specs'].keys():
+        if key != spec_name:
+            del test_spec_data['specs'][key]
+
+    if dyn_vars:
+        if spec_name not in test_spec_data['specs']:
+            test_spec_data['specs'][spec_name] = dyn_vars
+        else:
+            for key in dyn_vars.keys():
+                test_spec_data['specs'][spec_name][key] = dyn_vars[key]
+
+    # FIXTHIS: use a more pythonic way
+    os.system("mkdir -p " + build_data.test_logdir)
+
+    with open(build_data.test_logdir + '/spec.json', 'w+') as spec_file:
+        json.dump(test_spec_data, spec_file)
+
     # create log file
     console_log_filename = "consolelog.txt"
     log_filename = run_dir + os.sep + console_log_filename
-- 
2.7.4




More information about the Fuego mailing list