7
7
import docker
8
8
import requests
9
9
import anybadge
10
+ from multiprocessing .pool import Pool
10
11
from selenium import webdriver
11
12
from selenium .common .exceptions import ErrorInResponseException ,TimeoutException
12
13
from jinja2 import Template
@@ -30,11 +31,6 @@ def core_fail(message):
30
31
print (message )
31
32
sys .exit (1 )
32
33
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
-
38
34
# Remove container forcefully
39
35
def remove_container (container ):
40
36
container .remove (force = 'true' )
@@ -54,6 +50,17 @@ def convert_env(vars):
54
50
except Exception as error :
55
51
core_fail (str (error ))
56
52
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
+
57
64
# Set the optional parameters
58
65
global webauth
59
66
global webpath
@@ -136,6 +143,9 @@ def create_dir():
136
143
137
144
# Main container test logic
138
145
def container_test (tag ):
146
+ report_tests = []
147
+ report_containers = []
148
+ report_status = 'PASS'
139
149
# Start the container
140
150
print ('Starting ' + tag )
141
151
container = client .containers .run (image + ':' + tag ,
@@ -160,7 +170,7 @@ def container_test(tag):
160
170
elif logsfound == False :
161
171
print ('Startup failed for ' + tag )
162
172
report_tests .append (['Startup ' + tag ,'FAIL INIT NOT FINISHED' ])
163
- mark_fail ()
173
+ report_status = 'FAIL'
164
174
# Dump package information
165
175
print ('Dumping package info for ' + tag )
166
176
if base == 'alpine' :
@@ -175,7 +185,7 @@ def container_test(tag):
175
185
except Exception as error :
176
186
print (error )
177
187
report_tests .append (['Dump Versions ' + tag ,'FAIL' ])
178
- mark_fail ()
188
+ report_status = 'FAIL'
179
189
# Screenshot web interface and check connectivity
180
190
if screenshot == 'true' :
181
191
# Sleep for the user specified amount of time
@@ -219,7 +229,7 @@ def container_test(tag):
219
229
except Exception as error :
220
230
build_version = 'ERROR'
221
231
report_tests .append (['Get Build Version ' + tag ,'FAIL' ])
222
- mark_fail ()
232
+ report_status = 'FAIL'
223
233
# Grab container logs for last time before destruction
224
234
logblob = container .logs ().decode ("utf-8" )
225
235
# Add the info to the report
@@ -231,7 +241,8 @@ def container_test(tag):
231
241
})
232
242
#Cleanup
233
243
remove_container (container )
234
-
244
+ # Return info to global update callback
245
+ return (report_tests ,report_containers ,report_status )
235
246
236
247
# Render the markdown file for upload
237
248
def report_render ():
@@ -314,8 +325,9 @@ def report_upload():
314
325
check_env ()
315
326
create_dir ()
316
327
# 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 ()
319
331
report_render ()
320
332
badge_render ()
321
333
report_upload ()
0 commit comments