Skip to content

Commit 2c11fe9

Browse files
Allow disabling of internal TF (#3044)
Allow disabling of internal TF Reviewed-by: gemini-code-assist[bot] Reviewed-by: Nikola Forró
2 parents 0f935be + 1561764 commit 2c11fe9

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-0
lines changed

packit_service/constants.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ def from_number(number: int):
252252
"via `{packit_comment_command_prefix} test` comment.*",
253253
)
254254

255+
INTERNAL_TF_TEMPORARILY_DISABLED = (
256+
"Testing in internal Testing Farm is temporarily disabled",
257+
"Testing in internal Testing Farm via Packit is temporarily disabled due to an internal issue. "
258+
"For more details, see pinned messages in #team-packit Slack channel and reach out there for "
259+
"any questions.",
260+
)
261+
255262
INTERNAL_TF_BUILDS_AND_TESTS_NOT_ALLOWED = (
256263
"{actor} can't run tests (and builds) internally",
257264
"*As a project maintainer, you can trigger the build and test jobs manually "

packit_service/worker/checker/testing_farm.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
# SPDX-License-Identifier: MIT
33

44
import logging
5+
import os
56
from typing import Optional
67

78
from packit_service.constants import (
89
DOCS_TESTING_FARM,
910
INTERNAL_TF_BUILDS_AND_TESTS_NOT_ALLOWED,
11+
INTERNAL_TF_TEMPORARILY_DISABLED,
1012
INTERNAL_TF_TESTS_NOT_ALLOWED,
1113
KojiTaskState,
1214
)
@@ -27,6 +29,28 @@
2729
logger = logging.getLogger(__name__)
2830

2931

32+
class IsInternalTFEnabled(Checker, GetTestingFarmJobHelperMixin):
33+
"""Checks if internal Testing Farm is enabled at the service level.
34+
35+
Internal TF may be temporarily disabled due to service issues.
36+
Set DISABLE_INTERNAL_TF=true to disable internal TF and report a message to users.
37+
38+
By default (env var not set), internal TF is enabled.
39+
"""
40+
41+
def pre_check(self) -> bool:
42+
internal_tf_disabled = os.getenv("DISABLE_INTERNAL_TF", "false").lower() == "true"
43+
44+
if self.job_config.use_internal_tf and internal_tf_disabled:
45+
self.testing_farm_job_helper.report_status_to_tests(
46+
description=INTERNAL_TF_TEMPORARILY_DISABLED[0],
47+
state=BaseCommitStatus.neutral,
48+
markdown_content=INTERNAL_TF_TEMPORARILY_DISABLED[1],
49+
)
50+
return False
51+
return True
52+
53+
3054
class IsJobConfigTriggerMatching(Checker, GetTestingFarmJobHelperMixin):
3155
def pre_check(self) -> bool:
3256
return self.testing_farm_job_helper.is_job_config_trigger_matching(

packit_service/worker/handlers/testing_farm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
IsEventForJob,
5757
IsEventOk,
5858
IsIdentifierFromCommentMatching,
59+
IsInternalTFEnabled,
5960
IsJobConfigTriggerMatching,
6061
IsLabelFromCommentMatching,
6162
IsUpstreamTest,
@@ -150,6 +151,7 @@ def get_checkers() -> tuple[type[Checker], ...]:
150151
CanActorRunJob,
151152
IsIdentifierFromCommentMatching,
152153
IsLabelFromCommentMatching,
154+
IsInternalTFEnabled,
153155
)
154156

155157
def _get_or_create_group(

tests/unit/test_checkers.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright Contributors to the Packit project.
22
# SPDX-License-Identifier: MIT
33

4+
import os
5+
46
import pytest
57
from flexmock import flexmock
68
from ogr import PagureService
@@ -52,6 +54,7 @@
5254
from packit_service.worker.checker.testing_farm import (
5355
IsDownstreamTest,
5456
IsIdentifierFromCommentMatching,
57+
IsInternalTFEnabled,
5558
IsLabelFromCommentMatching,
5659
IsUpstreamTest,
5760
)
@@ -1398,3 +1401,76 @@ def test_is_downstream_test(test_run_data, should_pass):
13981401
checker = IsDownstreamTest(package_config, job_config, event)
13991402

14001403
assert checker.pre_check() == should_pass
1404+
1405+
1406+
@pytest.mark.parametrize(
1407+
"use_internal_tf, env_var_value, should_pass",
1408+
(
1409+
pytest.param(
1410+
True,
1411+
"false",
1412+
True,
1413+
id="Internal TF job, env var set to false - should pass",
1414+
),
1415+
pytest.param(
1416+
True,
1417+
"true",
1418+
False,
1419+
id="Internal TF job, env var set to true - should be blocked",
1420+
),
1421+
pytest.param(
1422+
False,
1423+
"true",
1424+
True,
1425+
id="Public TF job, env var set to true - should pass",
1426+
),
1427+
),
1428+
)
1429+
def test_is_internal_tf_enabled(use_internal_tf, env_var_value, should_pass):
1430+
"""
1431+
Test that IsInternalTFEnabled checker correctly blocks internal TF jobs
1432+
when DISABLE_INTERNAL_TF env var is set to true.
1433+
"""
1434+
flexmock(os).should_receive("getenv").with_args("DISABLE_INTERNAL_TF", "false").and_return(
1435+
env_var_value
1436+
)
1437+
1438+
package_config = flexmock(jobs=[])
1439+
job_config = flexmock(
1440+
type=JobType.tests,
1441+
trigger=JobConfigTriggerType.pull_request,
1442+
use_internal_tf=use_internal_tf,
1443+
)
1444+
1445+
event = {
1446+
"event_type": github.pr.Action.event_type(),
1447+
}
1448+
1449+
git_project = flexmock(
1450+
namespace="packit",
1451+
repo="ogr",
1452+
)
1453+
flexmock(ConfigFromEventMixin).should_receive("project").and_return(git_project)
1454+
1455+
db_project_object = flexmock(
1456+
job_config_trigger_type=JobConfigTriggerType.pull_request,
1457+
pr_id=1,
1458+
)
1459+
flexmock(EventData).should_receive("db_project_event").and_return(
1460+
flexmock().should_receive("get_project_event_object").and_return(db_project_object).mock(),
1461+
)
1462+
1463+
if not should_pass:
1464+
mock_helper = flexmock()
1465+
mock_helper.should_receive("report_status_to_tests").once()
1466+
flexmock(IsInternalTFEnabled).should_receive("testing_farm_job_helper").and_return(
1467+
mock_helper
1468+
)
1469+
1470+
checker = IsInternalTFEnabled(
1471+
package_config=package_config,
1472+
job_config=job_config,
1473+
event=event,
1474+
)
1475+
1476+
assert checker.pre_check() == should_pass

0 commit comments

Comments
 (0)