Skip to content

Commit f39081b

Browse files
authored
Exclude running some tests for specific packages (#163)
* Exclude running some tests for specific packages * Cache test mapping * Take platforms into account * Adjust alts to send skipped tests for display * Refactor test steps execution * Minor corrections
1 parent 1675bbb commit f39081b

File tree

6 files changed

+82
-10
lines changed

6 files changed

+82
-10
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@ For testing purposes, you can add the `--reload` argument to the scheduler launc
6161

6262
Both Celery worker and scheduler REST API services need YAML-based configs to function. Config examples are provided in the `configs` folder.
6363

64+
During the task execution some tests may be skipped if it specified in a particular `.json` file which can be found here: https://git.almalinux.org/almalinux/alts-exclusions/src/branch/main/skipped_tests.json
65+
66+
Example of a file content:
67+
```
68+
{
69+
"almalinux-8": {
70+
"libxml2": ["run_package_integrity_tests"],
71+
"curl": ["run_package_integrity_tests"],
72+
"bzip2": ["run_package_integrity_tests"]
73+
},
74+
"almalinux-9": {
75+
"libxml2": ["run_package_integrity_tests"],
76+
"curl": ["run_package_integrity_tests"]
77+
},
78+
"ubuntu-24.04": {
79+
"bzip2": ["run_package_integrity_tests"]
80+
}
81+
}
82+
```
6483

6584
Filling options in the config file
6685
--

alts/scheduler/scheduling.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import time
55
import urllib.parse
66
import uuid
7-
from typing import List
7+
from typing import List, Optional
8+
from cachetools import TTLCache
89

910
import requests
1011

@@ -28,6 +29,10 @@ def __init__(
2829
self.__graceful_terminate = graceful_terminate
2930
self.__celery = celery_app
3031
self.__get_result_timeout = get_result_timeout
32+
self.__cached_config = TTLCache(
33+
maxsize=CONFIG.excluded_tests_cache_size,
34+
ttl=CONFIG.excluded_tests_cache_update_interval,
35+
)
3136
self.logger = logging.getLogger(__file__)
3237

3338
def get_available_test_tasks(self) -> List[dict]:
@@ -49,6 +54,18 @@ def get_available_test_tasks(self) -> List[dict]:
4954
self.logger.exception('Cannot get available test tasks:')
5055
return response_as_json
5156

57+
def get_excluded_packages(self, distro: str) -> Optional[dict]:
58+
if 'excluded_packages' not in self.__cached_config:
59+
uri = f'{CONFIG.excluded_tests_url}'
60+
try:
61+
response = requests.get(uri, timeout=10)
62+
response.raise_for_status()
63+
self.__cached_config['excluded_packages'] = response.json()
64+
except requests.RequestException:
65+
return {}
66+
pkgs = self.__cached_config.get('excluded_packages', {})
67+
return pkgs.get(distro, {})
68+
5269
def schedule_test_task(self, payload: TaskRequestPayload):
5370
"""
5471
Schedules new tasks in Test System.
@@ -128,9 +145,13 @@ def schedule_test_task(self, payload: TaskRequestPayload):
128145
task_params['task_id'] = task_id
129146
task_params['runner_type'] = runner_type
130147
task_params['repositories'] = repositories
148+
distro = f"{task_params['dist_name']}-{task_params['dist_version']}"
131149
try:
132150
run_tests.apply_async(
133-
(task_params,),
151+
(
152+
task_params,
153+
self.get_excluded_packages(distro),
154+
),
134155
task_id=task_id,
135156
queue=queue_name,
136157
)

alts/shared/constants.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
'DEFAULT_SSH_AUTH_METHODS',
1616
'X32_ARCHITECTURES',
1717
'X64_ARCHITECTURES',
18+
'TESTS_MAPPING',
1819
]
1920

2021

@@ -67,3 +68,10 @@
6768
'hostbased',
6869
'publickey',
6970
]
71+
72+
TESTS_MAPPING = {
73+
'run_system_info_commands': 'system_info',
74+
'install_package': 'install_package',
75+
'run_package_integrity_tests': 'package_integrity_tests',
76+
'uninstall_package': 'uninstall_package',
77+
}

alts/shared/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,6 @@ class SchedulerConfig(CeleryConfig):
389389
working_directory: str = '/srv/alts/scheduler'
390390
jwt_secret: str
391391
hashing_algorithm: str = 'HS256'
392+
excluded_tests_url: str = 'https://git.almalinux.org/almalinux/alts-exclusions/raw/branch/main/skipped_tests.json'
393+
excluded_tests_cache_size: str = 1
394+
excluded_tests_cache_update_interval: int = 600

alts/worker/tasks.py

Lines changed: 28 additions & 8 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,7 +24,7 @@
2524
from urllib3 import Retry
2625
from urllib3.exceptions import TimeoutError
2726

28-
from alts.shared.constants import API_VERSION, DEFAULT_REQUEST_TIMEOUT
27+
from alts.shared.constants import API_VERSION, DEFAULT_REQUEST_TIMEOUT, TESTS_MAPPING
2928
from alts.shared.exceptions import (
3029
InstallPackageError,
3130
PackageIntegrityTestsError,
@@ -95,21 +94,24 @@ class RetryableTask(AbortableTask):
9594

9695

9796
@celery_app.task(bind=True, base=RetryableTask)
98-
def run_tests(self, task_params: dict):
97+
def run_tests(self, task_params: dict, tests_to_skip: dict):
9998
"""
10099
Executes a package test in a specified environment.
101100
102101
Parameters
103102
----------
104103
task_params : dict
105104
Task parameters.
105+
tests_to_skip : dict
106+
Tests mapping.
106107
107108
Returns
108109
-------
109110
dict
110111
Result summary of a test execution.
111112
"""
112113
aborted = False
114+
summary = defaultdict(dict)
113115

114116
def is_success(stage_data_: dict):
115117
tap_result = are_tap_tests_success(stage_data_.get('stdout', ''))
@@ -120,6 +122,12 @@ def is_success(stage_data_: dict):
120122
return False
121123
return stage_data_['exit_code'] == 0
122124

125+
def should_skip_test(package, test_name, skipped_tests_map):
126+
for pkg_pattern, tests in skipped_tests_map.items():
127+
if package.startswith(pkg_pattern) and test_name in tests:
128+
return True
129+
return False
130+
123131
def set_artifacts_when_stage_has_unexpected_exception(
124132
_artifacts: dict,
125133
error_message: str,
@@ -179,9 +187,19 @@ def set_artifacts_when_stage_has_unexpected_exception(
179187
# Wait a bit to not spawn all environments at once when
180188
# a lot of tasks are coming to the machine
181189
time.sleep(random.randint(5, 10))
190+
summary['skipped_tests'] = []
191+
192+
def run_or_skip(test_name, func, *args, **kwargs):
193+
if should_skip_test(package_name, test_name, tests_to_skip):
194+
summary['skipped_tests'].append(TESTS_MAPPING[test_name])
195+
else:
196+
func(*args, **kwargs)
197+
182198
runner.setup()
183199
runner.run_system_info_commands()
184-
runner.install_package(
200+
run_or_skip(
201+
"install_package",
202+
runner.install_package,
185203
package_name,
186204
package_version=package_version,
187205
package_epoch=package_epoch,
@@ -191,13 +209,16 @@ def set_artifacts_when_stage_has_unexpected_exception(
191209
semi_verbose=True,
192210
)
193211
if CONFIG.enable_integrity_tests:
194-
runner.run_package_integrity_tests(package_name, package_version)
195-
runner.run_third_party_tests(
212+
run_or_skip("run_package_integrity_tests", runner.run_package_integrity_tests, package_name,
213+
package_version)
214+
run_or_skip(
215+
"run_third_party_tests",
216+
runner.run_third_party_tests,
196217
package_name,
197218
package_version=package_version,
198219
package_epoch=package_epoch,
199220
)
200-
runner.uninstall_package(package_name)
221+
run_or_skip("uninstall_package", runner.uninstall_package, package_name)
201222
except VMImageNotFound as exc:
202223
logging.exception('Cannot find VM image: %s', exc)
203224
except WorkDirPreparationError:
@@ -238,7 +259,6 @@ def set_artifacts_when_stage_has_unexpected_exception(
238259
)
239260
finally:
240261
runner.teardown()
241-
summary = defaultdict(dict)
242262
if aborted:
243263
summary['revoked'] = True
244264
else:

requirements/scheduler.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ databases[sqlite]==0.8.0
55
fastapi==0.115.0
66
pyjwt==2.9.0
77
uvicorn==0.30.6
8+
cachetools==6.1.0

0 commit comments

Comments
 (0)