@@ -1244,8 +1244,76 @@ def progress_type_request(log, test, test_id, request) -> bool:
1244
1244
commit .value = test .commit
1245
1245
g .db .commit ()
1246
1246
1247
+ # Post status update
1248
+ state = Status .PENDING
1249
+ target_url = url_for ('test.by_id' , test_id = test .id , _external = True )
1250
+ context = f"CI - { test .platform .value } "
1251
+
1252
+ if status == TestStatus .canceled :
1253
+ state = Status .ERROR
1254
+ message = 'Tests aborted due to an error; please check'
1255
+
1256
+ elif status == TestStatus .completed :
1257
+ # Determine if success or failure
1258
+ # It fails if any of these happen:
1259
+ # - A crash (unexpected exit code)
1260
+ # - A not None value on the "got" of a TestResultFile (
1261
+ # meaning the hashes do not match)
1262
+ crashes = g .db .query (count (TestResult .exit_code )).filter (
1263
+ and_ (
1264
+ TestResult .test_id == test .id ,
1265
+ TestResult .exit_code != TestResult .expected_rc
1266
+ )).scalar ()
1267
+ results_zero_rc = g .db .query (RegressionTest .id ).filter (
1268
+ RegressionTest .expected_rc == 0
1269
+ ).subquery ()
1270
+ results = g .db .query (count (TestResultFile .got )).filter (
1271
+ and_ (
1272
+ TestResultFile .test_id == test .id ,
1273
+ TestResultFile .regression_test_id .in_ (results_zero_rc ),
1274
+ TestResultFile .got .isnot (None )
1275
+ )
1276
+ ).scalar ()
1277
+ log .debug (f'[Test: { test .id } ] Test completed: { crashes } crashes, { results } results' )
1278
+ if crashes > 0 or results > 0 :
1279
+ state = Status .FAILURE
1280
+ message = 'Not all tests completed successfully, please check'
1281
+
1282
+ else :
1283
+ state = Status .SUCCESS
1284
+ message = 'Tests completed'
1285
+ if test .test_type == TestType .pull_request :
1286
+ comment_pr (test .id , state , test .pr_nr , test .platform .name )
1287
+ update_build_badge (state , test )
1288
+
1289
+ else :
1290
+ message = progress .message
1291
+
1292
+ gh_commit = repository .get_commit (test .commit )
1293
+ try :
1294
+ gh_commit .create_status (state = state , description = message , context = context , target_url = target_url )
1295
+ except GithubException as a :
1296
+ log .error (f'Got an exception while posting to GitHub! Message: { a .data } ' )
1297
+
1298
+ if status in [TestStatus .completed , TestStatus .canceled ]:
1299
+ # Delete the current instance
1300
+ from run import config
1301
+ compute = get_compute_service_object ()
1302
+ zone = config .get ('ZONE' , '' )
1303
+ project = config .get ('PROJECT_NAME' , '' )
1304
+ vm_name = f"{ test .platform .value } -{ test .id } "
1305
+ operation = delete_instance (compute , project , zone , vm_name )
1306
+ wait_for_operation (compute , project , zone , operation ['name' ])
1307
+
1247
1308
# If status is complete, remove the GCP Instance entry
1248
1309
if status in [TestStatus .completed , TestStatus .canceled ]:
1310
+ gcp_instance = GcpInstance .query .filter (GcpInstance .test_id == test_id ).first ()
1311
+
1312
+ if gcp_instance is not None :
1313
+ log .debug (f"Removing GCP Instance entry: { gcp_instance } " )
1314
+ g .db .delete (gcp_instance )
1315
+ g .db .commit ()
1316
+
1249
1317
log .debug (f"[Test: { test_id } ] Test { status } " )
1250
1318
var_average = 'average_time_' + test .platform .value
1251
1319
current_average = GeneralData .query .filter (GeneralData .key == var_average ).first ()
@@ -1307,74 +1375,6 @@ def progress_type_request(log, test, test_id, request) -> bool:
1307
1375
g .db .commit ()
1308
1376
log .info (f'average time updated to { str (current_average .value )} ' )
1309
1377
1310
- gcp_instance = GcpInstance .query .filter (GcpInstance .test_id == test_id ).first ()
1311
-
1312
- if gcp_instance is not None :
1313
- log .debug (f"Removing GCP Instance entry: { gcp_instance } " )
1314
- g .db .delete (gcp_instance )
1315
- g .db .commit ()
1316
-
1317
- # Post status update
1318
- state = Status .PENDING
1319
- target_url = url_for ('test.by_id' , test_id = test .id , _external = True )
1320
- context = f"CI - { test .platform .value } "
1321
-
1322
- if status == TestStatus .canceled :
1323
- state = Status .ERROR
1324
- message = 'Tests aborted due to an error; please check'
1325
-
1326
- elif status == TestStatus .completed :
1327
- # Determine if success or failure
1328
- # It fails if any of these happen:
1329
- # - A crash (unexpected exit code)
1330
- # - A not None value on the "got" of a TestResultFile (
1331
- # meaning the hashes do not match)
1332
- crashes = g .db .query (count (TestResult .exit_code )).filter (
1333
- and_ (
1334
- TestResult .test_id == test .id ,
1335
- TestResult .exit_code != TestResult .expected_rc
1336
- )).scalar ()
1337
- results_zero_rc = g .db .query (RegressionTest .id ).filter (
1338
- RegressionTest .expected_rc == 0
1339
- ).subquery ()
1340
- results = g .db .query (count (TestResultFile .got )).filter (
1341
- and_ (
1342
- TestResultFile .test_id == test .id ,
1343
- TestResultFile .regression_test_id .in_ (results_zero_rc ),
1344
- TestResultFile .got .isnot (None )
1345
- )
1346
- ).scalar ()
1347
- log .debug (f'[Test: { test .id } ] Test completed: { crashes } crashes, { results } results' )
1348
- if crashes > 0 or results > 0 :
1349
- state = Status .FAILURE
1350
- message = 'Not all tests completed successfully, please check'
1351
-
1352
- else :
1353
- state = Status .SUCCESS
1354
- message = 'Tests completed'
1355
- if test .test_type == TestType .pull_request :
1356
- comment_pr (test .id , state , test .pr_nr , test .platform .name )
1357
- update_build_badge (state , test )
1358
-
1359
- else :
1360
- message = progress .message
1361
-
1362
- gh_commit = repository .get_commit (test .commit )
1363
- try :
1364
- gh_commit .create_status (state = state , description = message , context = context , target_url = target_url )
1365
- except GithubException as a :
1366
- log .error (f'Got an exception while posting to GitHub! Message: { a .data } ' )
1367
-
1368
- if status in [TestStatus .completed , TestStatus .canceled ]:
1369
- # Delete the current instance
1370
- from run import config
1371
- compute = get_compute_service_object ()
1372
- zone = config .get ('ZONE' , '' )
1373
- project = config .get ('PROJECT_NAME' , '' )
1374
- vm_name = f"{ test .platform .value } -{ test .id } "
1375
- operation = delete_instance (compute , project , zone , vm_name )
1376
- wait_for_operation (compute , project , zone , operation ['name' ])
1377
-
1378
1378
return True
1379
1379
1380
1380
0 commit comments