77import docker
88import requests
99import anybadge
10+ from multiprocessing .pool import Pool
1011from selenium import webdriver
1112from selenium .common .exceptions import ErrorInResponseException ,TimeoutException
1213from jinja2 import Template
@@ -30,11 +31,6 @@ def core_fail(message):
3031 print (message )
3132 sys .exit (1 )
3233
33- # If any of the tests are marked failed do not push the resulting images
34- def mark_fail ():
35- global report_status
36- report_status = 'FAIL'
37-
3834# Remove container forcefully
3935def remove_container (container ):
4036 container .remove (force = 'true' )
@@ -54,6 +50,17 @@ def convert_env(vars):
5450 except Exception as error :
5551 core_fail (str (error ))
5652
53+ # Update global variables from threaded testing process
54+ def update_globals (data ):
55+ for (tests ,containers ,status ) in data :
56+ for test in tests :
57+ report_tests .append (test )
58+ for container in containers :
59+ report_containers .append (container )
60+ if status == 'FAIL' :
61+ global report_status
62+ report_status = 'FAIL'
63+
5764# Set the optional parameters
5865global webauth
5966global webpath
@@ -136,6 +143,9 @@ def create_dir():
136143
137144# Main container test logic
138145def container_test (tag ):
146+ report_tests = []
147+ report_containers = []
148+ report_status = 'PASS'
139149 # Start the container
140150 print ('Starting ' + tag )
141151 container = client .containers .run (image + ':' + tag ,
@@ -160,7 +170,7 @@ def container_test(tag):
160170 elif logsfound == False :
161171 print ('Startup failed for ' + tag )
162172 report_tests .append (['Startup ' + tag ,'FAIL INIT NOT FINISHED' ])
163- mark_fail ()
173+ report_status = 'FAIL'
164174 # Dump package information
165175 print ('Dumping package info for ' + tag )
166176 if base == 'alpine' :
@@ -175,7 +185,7 @@ def container_test(tag):
175185 except Exception as error :
176186 print (error )
177187 report_tests .append (['Dump Versions ' + tag ,'FAIL' ])
178- mark_fail ()
188+ report_status = 'FAIL'
179189 # Screenshot web interface and check connectivity
180190 if screenshot == 'true' :
181191 # Sleep for the user specified amount of time
@@ -219,7 +229,7 @@ def container_test(tag):
219229 except Exception as error :
220230 build_version = 'ERROR'
221231 report_tests .append (['Get Build Version ' + tag ,'FAIL' ])
222- mark_fail ()
232+ report_status = 'FAIL'
223233 # Grab container logs for last time before destruction
224234 logblob = container .logs ().decode ("utf-8" )
225235 # Add the info to the report
@@ -231,7 +241,8 @@ def container_test(tag):
231241 })
232242 #Cleanup
233243 remove_container (container )
234-
244+ # Return info to global update callback
245+ return (report_tests ,report_containers ,report_status )
235246
236247# Render the markdown file for upload
237248def report_render ():
@@ -314,8 +325,9 @@ def report_upload():
314325check_env ()
315326create_dir ()
316327# Run through all the tags
317- for tag in tags :
318- container_test (tag )
328+ pool = Pool ()
329+ r = pool .map_async (container_test , tags , callback = update_globals )
330+ r .wait ()
319331report_render ()
320332badge_render ()
321333report_upload ()
0 commit comments