2626from lxml import etree
2727from markdown2 import markdown
2828from pymysql .err import IntegrityError
29- from sqlalchemy import and_ , func
29+ from sqlalchemy import and_ , func , select
3030from sqlalchemy .sql import label
3131from sqlalchemy .sql .functions import count
3232from werkzeug .utils import secure_filename
@@ -1188,8 +1188,10 @@ def create_instance(compute, project, zone, test, reportURL) -> Dict:
11881188 if test .platform == TestPlatform .linux :
11891189 image_response = compute .images ().getFromFamily (project = config .get ('LINUX_INSTANCE_PROJECT_NAME' , '' ),
11901190 family = config .get ('LINUX_INSTANCE_FAMILY_NAME' , '' )).execute ()
1191- startup_script = open (os .path .join (config .get ('INSTALL_FOLDER' , '' ), 'install' , 'ci-vm' ,
1192- 'ci-linux' , 'startup-script.sh' ), 'r' ).read ()
1191+ with open (os .path .join (
1192+ config .get ('INSTALL_FOLDER' , '' ), 'install' , 'ci-vm' ,
1193+ 'ci-linux' , 'startup-script.sh' ), 'r' ) as f :
1194+ startup_script = f .read ()
11931195 metadata_items = [
11941196 {'key' : 'startup-script' , 'value' : startup_script },
11951197 {'key' : 'reportURL' , 'value' : reportURL },
@@ -1198,12 +1200,18 @@ def create_instance(compute, project, zone, test, reportURL) -> Dict:
11981200 elif test .platform == TestPlatform .windows :
11991201 image_response = compute .images ().getFromFamily (project = config .get ('WINDOWS_INSTANCE_PROJECT_NAME' , '' ),
12001202 family = config .get ('WINDOWS_INSTANCE_FAMILY_NAME' , '' )).execute ()
1201- startup_script = open (os .path .join (config .get ('INSTALL_FOLDER' , '' ), 'install' , 'ci-vm' ,
1202- 'ci-windows' , 'startup-script.ps1' ), 'r' ).read ()
1203- service_account = open (os .path .join (config .get ('INSTALL_FOLDER' , '' ),
1204- config .get ('SERVICE_ACCOUNT_FILE' , '' )), 'r' ).read ()
1205- rclone_conf = open (os .path .join (config .get ('INSTALL_FOLDER' , '' ), 'install' , 'ci-vm' ,
1206- 'ci-windows' , 'rclone.conf' ), 'r' ).read ()
1203+ with open (os .path .join (
1204+ config .get ('INSTALL_FOLDER' , '' ), 'install' , 'ci-vm' ,
1205+ 'ci-windows' , 'startup-script.ps1' ), 'r' ) as f :
1206+ startup_script = f .read ()
1207+ with open (os .path .join (
1208+ config .get ('INSTALL_FOLDER' , '' ),
1209+ config .get ('SERVICE_ACCOUNT_FILE' , '' )), 'r' ) as f :
1210+ service_account = f .read ()
1211+ with open (os .path .join (
1212+ config .get ('INSTALL_FOLDER' , '' ), 'install' , 'ci-vm' ,
1213+ 'ci-windows' , 'rclone.conf' ), 'r' ) as f :
1214+ rclone_conf = f .read ()
12071215 metadata_items = [
12081216 {'key' : 'windows-startup-script-ps1' , 'value' : startup_script },
12091217 {'key' : 'service_account' , 'value' : service_account },
@@ -2431,13 +2439,15 @@ def progress_type_request(log, test, test_id, request) -> bool:
24312439 TestResult .test_id == test .id ,
24322440 TestResult .exit_code != TestResult .expected_rc
24332441 )).scalar ()
2434- results_zero_rc = g . db . query (RegressionTest .id ).filter (
2442+ results_zero_rc = select (RegressionTest .id ).filter (
24352443 RegressionTest .expected_rc == 0
2436- ). subquery ()
2444+ )
24372445 results = g .db .query (count (TestResultFile .got )).filter (
24382446 and_ (
24392447 TestResultFile .test_id == test .id ,
2440- TestResultFile .regression_test_id .in_ (results_zero_rc ),
2448+ TestResultFile .regression_test_id .in_ (
2449+ results_zero_rc .select ()
2450+ ),
24412451 TestResultFile .got .isnot (None )
24422452 )
24432453 ).scalar ()
@@ -2509,17 +2519,17 @@ def update_final_status():
25092519 total_time = 0
25102520
25112521 if current_average is None :
2512- platform_tests = g . db . query (Test .id ).filter (Test .platform == test .platform ). subquery ( )
2513- finished_tests = g . db . query (TestProgress .test_id ).filter (
2522+ platform_tests = select (Test .id ).filter (Test .platform == test .platform )
2523+ finished_tests = select (TestProgress .test_id ).filter (
25142524 and_ (
25152525 TestProgress .status .in_ ([TestStatus .canceled , TestStatus .completed ]),
2516- TestProgress .test_id .in_ (platform_tests )
2526+ TestProgress .test_id .in_ (platform_tests . select () )
25172527 )
2518- ). subquery ()
2528+ )
25192529 in_progress_statuses = [TestStatus .preparation , TestStatus .completed , TestStatus .canceled ]
25202530 finished_tests_progress = g .db .query (TestProgress ).filter (
25212531 and_ (
2522- TestProgress .test_id .in_ (finished_tests ),
2532+ TestProgress .test_id .in_ (finished_tests . select () ),
25232533 TestProgress .status .in_ (in_progress_statuses )
25242534 )
25252535 ).subquery ()
0 commit comments