[Fuego] [PATCH 17/30] run-test: fix job dir and build number creation

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


This makes it possible to run a job from jenkins or
the command line and keep the nextbuildnumber synchronized.

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

diff --git a/engine/scripts/ftc b/engine/scripts/ftc
index 6a8fbdb..142c31b 100755
--- a/engine/scripts/ftc
+++ b/engine/scripts/ftc
@@ -3257,15 +3257,7 @@ def do_run_test(conf, options):
 
     print "Running test '%s' on board '%s' using spec '%s'" % (test_name, board_name, spec_name)
 
-    # check if there's a Jenkins job that matches this request
-    # Job names have the syntax: <board>.<spec>.<test_name>
     job_name = "%s.%s.%s" % (board_name, spec_name, test_name)
-    job_dir = conf.JENKINS_HOME+"/jobs/"+job_name
-    if not os.path.isfile(job_dir+"/config.xml"):
-        print "Warning: no matching Jenkins job found.  Not populating Jenkins build directory"
-        job_dir = None
-
-    #pvar("job_dir")
 
     print "!!! >>> Ready to run test! <<< !!!"
 
@@ -3318,6 +3310,16 @@ def do_run_test(conf, options):
         fuego_caller = "ftc"
         os.environ["FUEGO_CALLER"] = "ftc"
 
+    # check if there is a jenkins job that matches ours.
+    # Example: /var/lib/jenkins/jobs/bbb.default.Benchmark.iperf3/builds/2/
+    job_dir = conf.JENKINS_HOME + "/jobs/" + build_data.job_name
+    if not os.path.isdir(job_dir):
+        if fuego_caller == "jenkins":
+            error_out("Jenkins did not create jobs folder " + job_dir)
+        print "No matching Jenkins job found."
+        os.mkdir(job_dir)
+        os.mkdir(job_dir + "/builds/")
+
     # export other vars (that Jenkins would export)
     # FIXTHIS: do_run_test: variables have changed (e.g. TESTSPEC, ..)
     os.environ["TESTPLAN"] = build_data.testplan_name
@@ -3340,25 +3342,25 @@ def do_run_test(conf, options):
     timestamp = time.strftime("%FT%T%z")
     build_data.timestamp = timestamp
 
-    if job_dir:
-        build_number = find_next_build_number(job_dir)
-        pvar("build_number")
+    # set build_data.build_number depending on the situation
+    if fuego_caller == "jenkins":
+        build_data.build_number = os.environ["BUILD_NUMBER"]
+    else:
         filename = job_dir + "/nextBuildNumber"
-        next_build_number = str(int(build_number)+1)
-        # update nextBuildNumber
+        if not os.path.isfile(filename):
+            print "First time we run this job"
+            build_data.build_number = "1"
+        else:
+            build_data.build_number = find_next_build_number(job_dir)
+        next_build_number = str(int(build_data.build_number)+1)
         try:
+            print "Updating nextBuildNumber: " + filename
             fd = open(filename, "w+")
             fd.write(next_build_number+'\n')
             fd.close()
         except:
-            print "Error: problem writing to file %s" % filename
-    else:
-        logs_dir = conf.FUEGO_RW + "/logs/%s" % test_name
-        if not os.path.isdir(logs_dir):
-             os.mkdir(logs_dir)
-        build_number = find_next_build_number_by_log_scan(logs_dir)
-
-    build_data.build_number = build_number
+            error_out("Problem writing to nextBuildNumber: %s" % filename)
+    dprint("build number: " + build_data.build_number)
 
     os.environ["EXECUTOR_NUMBER"] = "0"
     os.environ["BUILD_ID"] = build_data.build_number
-- 
2.7.4




More information about the Fuego mailing list