15
15
session = boto3 .session .Session ()
16
16
17
17
# Global Vars
18
+ global report_status
18
19
global report_tests
19
20
global report_containers
20
- global report_status
21
21
report_tests = []
22
22
report_containers = []
23
23
report_status = 'PASS'
@@ -31,10 +31,6 @@ def core_fail(message):
31
31
print (message )
32
32
sys .exit (1 )
33
33
34
- # Remove container forcefully
35
- def remove_container (container ):
36
- container .remove (force = 'true' )
37
-
38
34
# Convert env input to dictionary
39
35
def convert_env (vars ):
40
36
global dockerenv
@@ -52,13 +48,13 @@ def convert_env(vars):
52
48
53
49
# Update global variables from threaded testing process
54
50
def update_globals (data ):
51
+ global report_status
55
52
for (tests ,containers ,status ) in data :
56
53
for test in tests :
57
54
report_tests .append (test )
58
55
for container in containers :
59
56
report_containers .append (container )
60
57
if status == 'FAIL' :
61
- global report_status
62
58
report_status = 'FAIL'
63
59
64
60
# Set the optional parameters
@@ -143,9 +139,22 @@ def create_dir():
143
139
144
140
# Main container test logic
145
141
def container_test (tag ):
142
+ # Vars for the threaded process
146
143
report_tests = []
147
144
report_containers = []
148
145
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 )
149
158
# Start the container
150
159
print ('Starting ' + tag )
151
160
container = client .containers .run (image + ':' + tag ,
@@ -162,15 +171,31 @@ def container_test(tag):
162
171
break
163
172
time .sleep (1 )
164
173
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
167
190
if logsfound == True :
168
191
print ('Startup completed for ' + tag )
169
192
report_tests .append (['Startup ' + tag ,'PASS' ])
170
193
elif logsfound == False :
171
194
print ('Startup failed for ' + tag )
172
195
report_tests .append (['Startup ' + tag ,'FAIL INIT NOT FINISHED' ])
173
196
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 )
174
199
# Dump package information
175
200
print ('Dumping package info for ' + tag )
176
201
if base == 'alpine' :
@@ -183,9 +208,12 @@ def container_test(tag):
183
208
report_tests .append (['Dump Versions ' + tag ,'PASS' ])
184
209
print ('Got Package info for ' + tag )
185
210
except Exception as error :
186
- print (error )
211
+ packages = 'ERROR'
212
+ print (str (error ))
187
213
report_tests .append (['Dump Versions ' + tag ,'FAIL' ])
188
214
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 )
189
217
# Screenshot web interface and check connectivity
190
218
if screenshot == 'true' :
191
219
# Sleep for the user specified amount of time
@@ -222,26 +250,8 @@ def container_test(tag):
222
250
report_tests .append (['Screenshot ' + tag ,'FAIL TIMEOUT' ])
223
251
except WebDriverException as error :
224
252
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 )
245
255
return (report_tests ,report_containers ,report_status )
246
256
247
257
# Render the markdown file for upload
@@ -261,7 +271,7 @@ def report_render():
261
271
with open (outdir + 'report.md' , 'w' ) as f :
262
272
f .write (markdown )
263
273
264
- # Render the markdown file for upload
274
+ # Render the badge file for upload
265
275
def badge_render ():
266
276
try :
267
277
badge = anybadge .Badge ('CI' , report_status , thresholds = {'PASS' : 'green' , 'FAIL' : 'red' })
0 commit comments