Skip to content

Commit 3f77b17

Browse files
committed
Exclude running some tests for specific packages
1 parent 7f8182f commit 3f77b17

File tree

2 files changed

+73
-20
lines changed

2 files changed

+73
-20
lines changed

alts/shared/utils/file_utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import hashlib
22

3+
import requests
4+
35

46
def get_hasher(checksum_type):
57
"""
@@ -56,3 +58,25 @@ def feed_hasher(_fd):
5658
file_path.seek(0)
5759
feed_hasher(file_path)
5860
return hasher.hexdigest()
61+
62+
63+
def file_url_exists(url):
64+
65+
"""
66+
Check if a file exists at the specified URL using a HEAD request.
67+
68+
Parameters
69+
----------
70+
url : str
71+
The URL to check.
72+
73+
Returns
74+
-------
75+
bool
76+
True if the file exists, False otherwise.
77+
"""
78+
try:
79+
response = requests.head(url)
80+
return response.status_code == 200
81+
except requests.RequestException as e:
82+
return False

alts/worker/tasks.py

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# created: 2021-04-13
44

55
"""AlmaLinux Test System package testing tasks running."""
6-
76
import logging
87
import traceback
98
import random
@@ -25,6 +24,7 @@
2524
from urllib3 import Retry
2625
from urllib3.exceptions import TimeoutError
2726

27+
from alts.shared.utils.file_utils import file_url_exists
2828
from alts.shared.constants import API_VERSION, DEFAULT_REQUEST_TIMEOUT
2929
from alts.shared.exceptions import (
3030
InstallPackageError,
@@ -120,6 +120,12 @@ def is_success(stage_data_: dict):
120120
return False
121121
return stage_data_['exit_code'] == 0
122122

123+
def should_skip_test(package, test_name, skipped_tests_map):
124+
for pkg_pattern, tests in skipped_tests_map.items():
125+
if package.startswith(pkg_pattern) and test_name in tests:
126+
return True
127+
return False
128+
123129
def set_artifacts_when_stage_has_unexpected_exception(
124130
_artifacts: dict,
125131
error_message: str,
@@ -175,29 +181,52 @@ def set_artifacts_when_stage_has_unexpected_exception(
175181
module_name = task_params.get('module_name')
176182
module_stream = task_params.get('module_stream')
177183
module_version = task_params.get('module_version')
184+
185+
def get_excluded_packages():
186+
uri = 'https://git.almalinux.org/almalinux/alts-exclusions/raw/branch/main/skipped_tests.json'
187+
try:
188+
response = requests.get(uri)
189+
response.raise_for_status()
190+
return response.json()
191+
except requests.RequestException:
192+
return {}
193+
178194
try:
179195
# Wait a bit to not spawn all environments at once when
180196
# a lot of tasks are coming to the machine
181197
time.sleep(random.randint(5, 10))
182-
runner.setup()
183-
runner.run_system_info_commands()
184-
runner.install_package(
185-
package_name,
186-
package_version=package_version,
187-
package_epoch=package_epoch,
188-
module_name=module_name,
189-
module_stream=module_stream,
190-
module_version=module_version,
191-
semi_verbose=True,
192-
)
193-
if CONFIG.enable_integrity_tests:
194-
runner.run_package_integrity_tests(package_name, package_version)
195-
runner.run_third_party_tests(
196-
package_name,
197-
package_version=package_version,
198-
package_epoch=package_epoch,
199-
)
200-
runner.uninstall_package(package_name)
198+
199+
test_steps = [
200+
("setup", runner.setup, [], {}),
201+
("run_system_info_commands", runner.run_system_info_commands, [], {}),
202+
("install_package", runner.install_package, [
203+
package_name
204+
], {
205+
"package_version": package_version,
206+
"package_epoch": package_epoch,
207+
"module_name": module_name,
208+
"module_stream": module_stream,
209+
"module_version": module_version,
210+
"semi_verbose": True,
211+
}),
212+
("run_package_integrity_tests", runner.run_package_integrity_tests, [
213+
package_name, package_version
214+
], {}),
215+
("run_third_party_tests", runner.run_third_party_tests, [
216+
package_name
217+
], {
218+
"package_version": package_version,
219+
"package_epoch": package_epoch,
220+
}),
221+
("uninstall_package", runner.uninstall_package, [package_name], {})
222+
]
223+
packages_to_skip = get_excluded_packages()
224+
for test_name, func, args, kwargs in test_steps:
225+
if test_name == "run_package_integrity_tests" and not CONFIG.enable_integrity_tests:
226+
continue
227+
if should_skip_test(package_name, test_name, packages_to_skip):
228+
continue
229+
func(*args, **kwargs)
201230
except VMImageNotFound as exc:
202231
logging.exception('Cannot find VM image: %s', exc)
203232
except WorkDirPreparationError:

0 commit comments

Comments
 (0)