Skip to content

Commit d74226e

Browse files
authored
Merge branch 'master' into feature/issue-1072-negative-runtime
2 parents 3f90041 + 8e4f6f8 commit d74226e

16 files changed

Lines changed: 117 additions & 80 deletions

File tree

exceptions.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33

44

55
class QueuedSampleNotFoundException(Exception):
6-
"""Custom exception handler for queued sample not found."""
6+
"""Raised when a queued sample cannot be found by the given ID."""
77

8-
def __init__(self, message: str) -> None:
9-
Exception.__init__(self)
8+
def __init__(self, message="Queued sample not found."):
9+
# By providing a default, all existing raise sites that call
10+
# this exception without arguments will still work, and new
11+
# calls can optionally provide a custom message.
12+
super().__init__(message)
1013
self.message = message
1114

1215

mod_auth/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def generate_hash(password: str) -> str:
7777
:rtype : str
7878
"""
7979
# Go for increased strength no matter what
80-
return pwd_context.encrypt(password, category='admin')
80+
return pwd_context.hash(password, category='admin')
8181

8282
@staticmethod
8383
def create_random_password(length=16) -> str:

mod_ci/controllers.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from lxml import etree
2727
from markdown2 import markdown
2828
from pymysql.err import IntegrityError
29-
from sqlalchemy import and_, func
29+
from sqlalchemy import and_, func, select
3030
from sqlalchemy.sql import label
3131
from sqlalchemy.sql.functions import count
3232
from 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()

mod_customized/controllers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from flask import Blueprint, g, redirect, request, url_for
66
from github import Auth, Github, GithubException
7-
from sqlalchemy import and_
7+
from sqlalchemy import and_, select
88

99
from decorators import template_renderer
1010
from mod_auth.controllers import (check_access_rights,
@@ -81,7 +81,7 @@ def index():
8181
elif username is not None:
8282
g.log.error('GitHub token not configured, cannot fetch commits')
8383

84-
populated_categories = g.db.query(regressionTestLinkTable.c.category_id).subquery()
84+
populated_categories = select(regressionTestLinkTable.c.category_id)
8585
categories = Category.query.filter(Category.id.in_(populated_categories)).order_by(Category.name.asc()).all()
8686

8787
tests = Test.query.filter(and_(TestFork.user_id == g.user.id, TestFork.test_id == Test.id)).order_by(

mod_health/controllers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44
import subprocess
5-
from datetime import datetime
5+
from datetime import datetime, timezone
66
from typing import Any, Dict, Optional, Tuple
77

88
from flask import Blueprint, current_app, jsonify
@@ -79,7 +79,7 @@ def health_check() -> Tuple[Any, int]:
7979

8080
checks: Dict[str, Any] = {
8181
'status': 'healthy' if all_healthy else 'unhealthy',
82-
'timestamp': datetime.utcnow().isoformat() + 'Z',
82+
'timestamp': datetime.now(timezone.utc).isoformat(),
8383
'checks': check_results
8484
}
8585

@@ -99,7 +99,7 @@ def liveness_check() -> Tuple[Any, int]:
9999
"""
100100
return jsonify({
101101
'status': 'alive',
102-
'timestamp': datetime.utcnow().isoformat() + 'Z'
102+
'timestamp': datetime.now(timezone.utc).isoformat()
103103
}), 200
104104

105105

@@ -172,7 +172,7 @@ def version_check() -> Tuple[Any, int]:
172172
git_info = get_git_info()
173173

174174
response = {
175-
'timestamp': datetime.utcnow().isoformat() + 'Z',
175+
'timestamp': datetime.now(timezone.utc).isoformat(),
176176
'git': git_info,
177177
}
178178

mod_sample/controllers.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Any, Dict
66

77
from flask import Blueprint, g, redirect, request, url_for
8+
from sqlalchemy import select
89

910
from decorators import template_renderer
1011
from exceptions import SampleNotFoundException
@@ -66,14 +67,14 @@ def display_sample_info(sample) -> Dict[str, Any]:
6667

6768
if len(regression_tests) > 0:
6869
if test_commit is not None:
69-
sq = g.db.query(RegressionTest.id).filter(RegressionTest.sample_id == sample.id).subquery()
70+
sq = select(RegressionTest.id).filter(RegressionTest.sample_id == sample.id)
7071
exit_code = g.db.query(TestResult.exit_code).filter(and_(
7172
TestResult.exit_code != TestResult.expected_rc,
72-
and_(TestResult.test_id == test_commit.id, TestResult.regression_test_id.in_(sq))
73+
and_(TestResult.test_id == test_commit.id, TestResult.regression_test_id.in_(sq.select()))
7374
)).first()
7475
not_null = g.db.query(TestResultFile.got).filter(and_(
7576
TestResultFile.got.isnot(None),
76-
and_(TestResultFile.test_id == test_commit.id, TestResultFile.regression_test_id.in_(sq))
77+
and_(TestResultFile.test_id == test_commit.id, TestResultFile.regression_test_id.in_(sq.select()))
7778
)).first()
7879

7980
if exit_code is None and not_null is None:
@@ -82,17 +83,17 @@ def display_sample_info(sample) -> Dict[str, Any]:
8283
status = 'Fail'
8384

8485
if test_release is not None:
85-
sq = g.db.query(RegressionTest.id).filter(
86-
RegressionTest.sample_id == sample.id).subquery()
86+
sq = select(RegressionTest.id).filter(
87+
RegressionTest.sample_id == sample.id)
8788
exit_code = g.db.query(TestResult.exit_code).filter(
8889
and_(
8990
TestResult.exit_code != TestResult.expected_rc,
90-
and_(TestResult.test_id == test_release.id, TestResult.regression_test_id.in_(sq))
91+
and_(TestResult.test_id == test_release.id, TestResult.regression_test_id.in_(sq.select()))
9192
)
9293
).first()
9394
not_null = g.db.query(TestResultFile.got).filter(and_(
9495
TestResultFile.got.isnot(None),
95-
and_(TestResultFile.test_id == test_release.id, TestResultFile.regression_test_id.in_(sq))
96+
and_(TestResultFile.test_id == test_release.id, TestResultFile.regression_test_id.in_(sq.select()))
9697
)).first()
9798

9899
if exit_code is None and not_null is None:

mod_sample/media_info_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ def generate_media_xml(sample) -> MediaInfoFetcher:
210210

211211
media_folder = os.path.join(config.get('SAMPLE_REPOSITORY', ''), 'TestFiles')
212212
media_info_path = os.path.join(media_folder, 'media', sample.sha + '.xml')
213-
output_handle = open(media_info_path, 'w')
214213
media_path = os.path.join(media_folder, sample.filename)
215-
process = subprocess.Popen(['mediainfo', '--Output=XML', media_path], stdout=output_handle)
216-
process.wait()
214+
with open(media_info_path, 'w') as output_handle:
215+
process = subprocess.Popen(['mediainfo', '--Output=XML', media_path], stdout=output_handle)
216+
process.wait()
217217
if os.path.isfile(media_info_path):
218218
# Load media info, and replace full pathname
219219
tree = etree.parse(media_info_path)

mod_test/controllers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from flask import (Blueprint, Response, abort, g, jsonify, redirect, request,
77
url_for)
8-
from sqlalchemy import and_
8+
from sqlalchemy import and_, select
99

1010
from decorators import template_renderer
1111
from exceptions import TestNotFoundException
@@ -60,7 +60,7 @@ def get_test_results(test) -> List[Dict[str, Any]]:
6060
:param test: The test to retrieve the data for.
6161
:type test: Test
6262
"""
63-
populated_categories = g.db.query(regressionTestLinkTable.c.category_id).subquery()
63+
populated_categories = select(regressionTestLinkTable.c.category_id)
6464
categories = Category.query.filter(Category.id.in_(populated_categories)).order_by(Category.name.asc()).all()
6565
results = [{
6666
'category': category,

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ WTForms==3.2.1
2020
MarkupSafe==3.0.3
2121
jinja2==3.1.6
2222
itsdangerous==2.2.0
23-
google-api-python-client==2.192.0
24-
google-cloud-storage==3.9.0
23+
google-api-python-client==2.193.0
24+
google-cloud-storage==3.10.0
2525
cffi==2.0.0
2626
PyGithub==2.8.1
2727
blinker==1.9.0

templates/regression/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ <h5>Regression tests</h5>
216216

217217
$(document).ready(function(){
218218
const urlParams = new URLSearchParams(window.location.search);
219-
const hash = urlParams.get("category");
220-
if(hash === "") hash = "1";
219+
let hash = urlParams.get("category");
220+
if(!hash || hash === "") hash = "1";
221221
$("#category").find("option").each(function(idx, elm){
222222
if($(elm).val() === hash){
223223
$(elm).attr("selected",true);

0 commit comments

Comments
 (0)