[Fuego] [PATCH 1/2] testplans: execute tests in order

Daniel Sangorrin daniel.sangorrin at toshiba.co.jp
Fri Nov 9 08:27:19 UTC 2018


Before this patch, a batch job was triggering all of the jobs
in a testplan in parallel. For that reason, execution order
of the jobs could not be guaranteed.

This patch creates a "linked chain" of jobs where the batch job just
triggers the first job in the testplan, and then the first job
triggers the second one in turn.

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

diff --git a/engine/scripts/ftc b/engine/scripts/ftc
index 6dc3d6d..6f605db 100755
--- a/engine/scripts/ftc
+++ b/engine/scripts/ftc
@@ -1291,7 +1291,7 @@ def link_key(item):
         return "zzz+"+key
 
 
-def create_job(board, test):
+def create_job(board, test, next_job=None):
     flot_link = '<flotile.FlotPublisher plugin="flot at 1.0-SNAPSHOT"/>'
 
     # prepare links for the descriptionsetter plugin
@@ -1400,13 +1400,34 @@ ftc run-test -b $NODE_NAME -t {testdir} -s {testspec} \\
       <descriptionForFailed>{fail_links}</descriptionForFailed>
       <setForMatrix>false</setForMatrix>
     </hudson.plugins.descriptionsetter.DescriptionSetterPublisher>
-    </publishers>
-    <buildWrappers/>
-</project>
 """.format(board=board, reboot=test.reboot, rebuild=test.rebuild,
         precleanup=test.precleanup, postcleanup=test.postcleanup,
         testdir=test.name, testspec=test.spec, timeout=test.timeout,
         flot_link=flot_link, success_links=success_links, fail_links=fail_links))
+
+    if next_job is None:
+        fd.write("""    </publishers>
+    <buildWrappers/>
+</project>
+""")
+    else:
+        # [Note] To trigger the next job only if this job is succesful use
+        # <name>SUCCESS</name>
+        # <ordinal>0</ordinal>
+        # <color>BLUE</color>
+        fd.write("""    <hudson.tasks.BuildTrigger>
+      <childProjects>{next_job}</childProjects>
+      <threshold>
+        <name>FAILURE</name>
+        <ordinal>2</ordinal>
+        <color>RED</color>
+        <completeBuild>true</completeBuild>
+      </threshold>
+    </hudson.tasks.BuildTrigger>
+    </publishers>
+    <buildWrappers/>
+</project>
+""".format(next_job=next_job))
     fd.close()
 
     job_name = board + "." + test.spec + "." + test.name
@@ -1421,9 +1442,8 @@ ftc run-test -b $NODE_NAME -t {testdir} -s {testspec} \\
         sys.exit(1)
 
 
-def create_batch_job(board, testplan, plan_tests):
+def create_batch_job(board_name, testplan, next_job):
     tmp = "/tmp/fuego_tmp_batch"
-    job_list = [board+'.'+test.spec+'.'+test.name for test in plan_tests]
 
     fd = open(tmp, "w+")
     fd.write("""<?xml version='1.0' encoding='UTF-8'?>
@@ -1433,7 +1453,7 @@ def create_batch_job(board, testplan, plan_tests):
   <keepDependencies>false</keepDependencies>
   <properties/>
   <scm class="hudson.scm.NullSCM"/>
-  <assignedNode>{board}</assignedNode>
+  <assignedNode>{board_name}</assignedNode>
   <canRoam>false</canRoam>
   <disabled>false</disabled>
   <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
@@ -1443,7 +1463,7 @@ def create_batch_job(board, testplan, plan_tests):
   <builders/>
   <publishers>
     <hudson.tasks.BuildTrigger>
-      <childProjects>{alljobs}</childProjects>
+      <childProjects>{next_job}</childProjects>
       <threshold>
         <name>SUCCESS</name>
         <ordinal>0</ordinal>
@@ -1454,13 +1474,13 @@ def create_batch_job(board, testplan, plan_tests):
   </publishers>
   <buildWrappers/>
 </project>
-""".format(board=board, alljobs=','.join(job_list)))
+""".format(board_name=board_name, next_job=next_job))
 
     fd.close()
 
     print("Creating batch job ")
     try:
-        job_name = board+'.'+testplan+'.batch'
+        job_name = board_name+'.'+testplan+'.batch'
         subprocess.call('java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080/fuego create-job ' +
              job_name + '< ' + tmp, shell=True)
         os.unlink(tmp)
@@ -1628,9 +1648,16 @@ def do_add_jobs(conf, options):
     else:
         plan_tests = parse_testplan(testplan, test_dict)
         for board_name in board_names:
-            for test in plan_tests:
-                create_job(board_name, test)
-            create_batch_job(board_name, testplan, plan_tests)
+            for index, test in enumerate(plan_tests):
+                if index == len(plan_tests)-1:
+                    next_job = None
+                else:
+                    next_test = plan_tests[index + 1]
+                    next_job = board_name + "." + next_test.spec + "." + next_test.name
+                create_job(board_name, test, next_job)
+            next_test =  plan_tests[0]
+            next_job = board_name + "." + next_test.spec + "." + next_test.name
+            create_batch_job(board_name, testplan, next_job)
     sys.exit(0)
 
 
-- 
2.7.4



More information about the Fuego mailing list