@@ -107,7 +107,7 @@ def maestro_check_node(node):
107107 else :
108108 if state == "running" :
109109 return "RUNNING"
110- elif state == "done" and result == "pass" :
110+ elif state == "done" and ( result == "pass" or result == "fail" ) :
111111 return "DONE"
112112 else :
113113 return "FAIL"
@@ -135,17 +135,57 @@ def maestro_retrieve_treeid_nodes(baseurl, token, treeid):
135135 return response .json ()
136136
137137
138+ def maestro_node_result (node ):
139+ result = node ["result" ]
140+ if node ["kind" ] == "checkout" :
141+ if (
142+ result == "available"
143+ or result == "closing"
144+ or result == "done"
145+ or result == "pass"
146+ ):
147+ kci_msg_green_nonl ("PASS" )
148+ elif result == None :
149+ kci_msg_green_nonl ("PASS" )
150+ else :
151+ kci_msg_red_nonl ("FAIL" )
152+ else :
153+ if node ["result" ] == "pass" :
154+ kci_msg_green_nonl ("PASS" )
155+ elif node ["result" ] == "fail" :
156+ kci_msg_red_nonl ("FAIL" )
157+ else :
158+ kci_msg_yellow_nonl (node ["result" ])
159+
160+ if node ["kind" ] == "checkout" :
161+ kci_msg_nonl (" branch checkout" )
162+ else :
163+ kci_msg_nonl (f" { node ["kind" ]} : " )
164+
165+ if node ["kind" ] != "checkout" :
166+ kci_msg_nonl (f"{ node ["name" ]} " )
167+
168+ kci_msg (f" - node_id:{ node ["id" ]} ({ node ["updated" ]} )" )
169+
170+
138171def maestro_watch_jobs (baseurl , token , treeid , job_filter , test ):
139172 # we need to add to job_filter "checkout" node
140173 job_filter = list (job_filter )
141174 job_filter .append ("checkout" )
175+ kci_log (f"job_filter: { ", " .join (job_filter )} " )
142176 previous_nodes = None
177+ running = False
178+
179+ job_info = {}
180+ for job in job_filter :
181+ job_info [job ] = {"done" : False , "running" : False }
182+
143183 while True :
144184 inprogress = 0
145185 joblist = job_filter .copy ()
146186 nodes = maestro_retrieve_treeid_nodes (baseurl , token , treeid )
147187 if not nodes :
148- click . secho ("No nodes found. Retrying..." , fg = "yellow " )
188+ kci_warning ("No nodes found. Retrying..." )
149189 time .sleep (5 )
150190 continue
151191 if previous_nodes == nodes :
@@ -154,10 +194,7 @@ def maestro_watch_jobs(baseurl, token, treeid, job_filter, test):
154194 continue
155195
156196 time_local = time .localtime ()
157- click .echo (f"\n Current time: { time .strftime ('%Y-%m-%d %H:%M:%S' , time_local )} " )
158- click .secho (
159- f"Total tree nodes { len (nodes )} found. job_filter: { job_filter } " , fg = "green"
160- )
197+ kci_info (f"\n Current time: { time .strftime ('%Y-%m-%d %H:%M:%S' , time_local )} " )
161198
162199 # Tricky part in watch is that we might have one item in job_filter (job, test),
163200 # but it might spawn multiple nodes with same name
@@ -167,30 +204,29 @@ def maestro_watch_jobs(baseurl, token, treeid, job_filter, test):
167204 if node ["name" ] == test :
168205 test_result = node ["result" ]
169206 if node ["name" ] in job_filter :
170- result = maestro_check_node (node )
171- if result == "DONE" :
207+ status = maestro_check_node (node )
208+ if status == "DONE" :
209+ if job_info [node ["name" ]]["running" ]:
210+ kci_msg ("" )
211+ job_info [node ["name" ]]["running" ] = False
212+ if not job_info [node ["name" ]]["done" ]:
213+ maestro_node_result (node )
214+ job_info [node ["name" ]]["done" ] = True
172215 if isinstance (joblist , list ) and node ["name" ] in joblist :
173216 joblist .remove (node ["name" ])
174- color = "green"
175- elif result == "RUNNING" :
217+ elif status == "RUNNING" :
218+ job_info [ node [ "name" ]][ "running" ] = True
176219 inprogress += 1
177- color = "yellow"
178220 else :
179221 if isinstance (joblist , list ) and node ["name" ] in joblist :
180222 joblist .remove (node ["name" ])
181- color = "red"
182223 # if test is same as job, dont indicate infra-failure if test job fail
183224 if test and test != node ["name" ]:
184225 # if we have a test, and prior job failed, we should indicate that
185226 kci_err (f"Job { node ['name' ]} failed, test can't be executed" )
186227 sys .exit (2 )
187- nodeid = node .get ("id" )
188- click .secho (
189- f"Node: { nodeid } job: { node ['name' ]} State: { node ['state' ]} Result: { node ['result' ]} " ,
190- fg = color ,
191- )
192228 if isinstance (joblist , list ) and len (joblist ) == 0 and inprogress == 0 :
193- click . secho ("All jobs completed" , fg = "green " )
229+ kci_info ("All jobs completed" )
194230 if not test :
195231 return
196232 else :
@@ -202,13 +238,11 @@ def maestro_watch_jobs(baseurl, token, treeid, job_filter, test):
202238 continue
203239
204240 if test_result and test_result == "pass" :
205- click .secho (f"Test { test } passed" , fg = "green" )
206241 sys .exit (0 )
207242 elif test_result :
208- # ignore null, that means result not ready yet
209- kci_err (f"Test { test } failed: { test_result } " )
210243 sys .exit (1 )
211244
212- kci_msg_nonl (f"\r Refresh every 30s..." )
245+ running = True
246+ kci_msg_nonl (f"\r Running job..." )
213247 previous_nodes = nodes
214248 time .sleep (30 )
0 commit comments