1515session = boto3 .session .Session ()
1616
1717# Global Vars
18+ global report_status
1819global report_tests
1920global report_containers
20- global report_status
2121report_tests = []
2222report_containers = []
2323report_status = 'PASS'
@@ -31,10 +31,6 @@ def core_fail(message):
3131 print (message )
3232 sys .exit (1 )
3333
34- # Remove container forcefully
35- def remove_container (container ):
36- container .remove (force = 'true' )
37-
3834# Convert env input to dictionary
3935def convert_env (vars ):
4036 global dockerenv
@@ -52,13 +48,13 @@ def convert_env(vars):
5248
5349# Update global variables from threaded testing process
5450def update_globals (data ):
51+ global report_status
5552 for (tests ,containers ,status ) in data :
5653 for test in tests :
5754 report_tests .append (test )
5855 for container in containers :
5956 report_containers .append (container )
6057 if status == 'FAIL' :
61- global report_status
6258 report_status = 'FAIL'
6359
6460# Set the optional parameters
@@ -143,9 +139,22 @@ def create_dir():
143139
144140# Main container test logic
145141def container_test (tag ):
142+ # Vars for the threaded process
146143 report_tests = []
147144 report_containers = []
148145 report_status = 'PASS'
146+ # End the test with as much info as we have
147+ def endtest (container ,report_tests ,report_containers ,report_status ,tag ,build_version ,packages ):
148+ logblob = container .logs ().decode ("utf-8" )
149+ container .remove (force = 'true' )
150+ # Add the info to the report
151+ report_containers .append ({
152+ "tag" :tag ,
153+ "logs" :logblob ,
154+ "sysinfo" :packages ,
155+ "build_version" :build_version
156+ })
157+ return (report_tests ,report_containers ,report_status )
149158 # Start the container
150159 print ('Starting ' + tag )
151160 container = client .containers .run (image + ':' + tag ,
@@ -162,15 +171,31 @@ def container_test(tag):
162171 break
163172 time .sleep (1 )
164173 except Exception as error :
165- print (error )
166- remove_container (container )
174+ print ('Startup failed for ' + tag )
175+ report_tests .append (['Startup ' + tag ,'FAIL INIT NOT FINISHED' ])
176+ report_status = 'FAIL'
177+ (report_tests ,report_containers ,report_status ) = endtest (container ,report_tests ,report_containers ,report_status ,tag ,'ERROR' ,'ERROR' )
178+ return (report_tests ,report_containers ,report_status )
179+ # Grab build version
180+ try :
181+ build_version = container .attrs ["Config" ]["Labels" ]["build_version" ]
182+ report_tests .append (['Get Build Version ' + tag ,'PASS' ])
183+ except Exception as error :
184+ build_version = 'ERROR'
185+ report_tests .append (['Get Build Version ' + tag ,'FAIL' ])
186+ report_status = 'FAIL'
187+ (report_tests ,report_containers ,report_status ) = endtest (container ,report_tests ,report_containers ,report_status ,tag ,build_version ,'ERROR' )
188+ return (report_tests ,report_containers ,report_status )
189+ # Check if the startup marker was found in the logs during the 2 minute spinup
167190 if logsfound == True :
168191 print ('Startup completed for ' + tag )
169192 report_tests .append (['Startup ' + tag ,'PASS' ])
170193 elif logsfound == False :
171194 print ('Startup failed for ' + tag )
172195 report_tests .append (['Startup ' + tag ,'FAIL INIT NOT FINISHED' ])
173196 report_status = 'FAIL'
197+ (report_tests ,report_containers ,report_status ) = endtest (container ,report_tests ,report_containers ,report_status ,tag ,build_version ,'ERROR' )
198+ return (report_tests ,report_containers ,report_status )
174199 # Dump package information
175200 print ('Dumping package info for ' + tag )
176201 if base == 'alpine' :
@@ -183,9 +208,12 @@ def container_test(tag):
183208 report_tests .append (['Dump Versions ' + tag ,'PASS' ])
184209 print ('Got Package info for ' + tag )
185210 except Exception as error :
186- print (error )
211+ packages = 'ERROR'
212+ print (str (error ))
187213 report_tests .append (['Dump Versions ' + tag ,'FAIL' ])
188214 report_status = 'FAIL'
215+ (report_tests ,report_containers ,report_status ) = endtest (container ,report_tests ,report_containers ,report_status ,tag ,build_version ,packages )
216+ return (report_tests ,report_containers ,report_status )
189217 # Screenshot web interface and check connectivity
190218 if screenshot == 'true' :
191219 # Sleep for the user specified amount of time
@@ -222,26 +250,8 @@ def container_test(tag):
222250 report_tests .append (['Screenshot ' + tag ,'FAIL TIMEOUT' ])
223251 except WebDriverException as error :
224252 report_tests .append (['Screenshot ' + tag ,'FAIL UNKNOWN' ])
225- # Grab build version
226- try :
227- build_version = container .attrs ["Config" ]["Labels" ]["build_version" ]
228- report_tests .append (['Get Build Version ' + tag ,'PASS' ])
229- except Exception as error :
230- build_version = 'ERROR'
231- report_tests .append (['Get Build Version ' + tag ,'FAIL' ])
232- report_status = 'FAIL'
233- # Grab container logs for last time before destruction
234- logblob = container .logs ().decode ("utf-8" )
235- # Add the info to the report
236- report_containers .append ({
237- "tag" :tag ,
238- "logs" :logblob ,
239- "sysinfo" :packages ,
240- "build_version" :build_version
241- })
242- #Cleanup
243- remove_container (container )
244- # Return info to global update callback
253+ # If all info is present end test
254+ (report_tests ,report_containers ,report_status ) = endtest (container ,report_tests ,report_containers ,report_status ,tag ,build_version ,packages )
245255 return (report_tests ,report_containers ,report_status )
246256
247257# Render the markdown file for upload
@@ -261,7 +271,7 @@ def report_render():
261271 with open (outdir + 'report.md' , 'w' ) as f :
262272 f .write (markdown )
263273
264- # Render the markdown file for upload
274+ # Render the badge file for upload
265275def badge_render ():
266276 try :
267277 badge = anybadge .Badge ('CI' , report_status , thresholds = {'PASS' : 'green' , 'FAIL' : 'red' })
0 commit comments