Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check whether architecture for TF is supported #2053

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packit_service/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT
from enum import Enum
from typing import List

CONTACTS_URL = "https://packit.dev/#contact"
DOCS_URL = "https://packit.dev/docs"
Expand Down Expand Up @@ -236,3 +237,16 @@ def from_number(number: int):
)

DASHBOARD_JOBS_TESTING_FARM_PATH = "/jobs/testing-farm-runs"

# https://docs.testing-farm.io/general/0.1/test-environment.html#_supported_architectures
PUBLIC_TF_ARCHITECTURE_LIST: List[str] = [
"aarch64",
"x86_64",
]

INTERNAL_TF_ARCHITECTURE_LIST: List[str] = [
"aarch64",
"ppc64le",
"s390x",
"x86_64",
]
37 changes: 37 additions & 0 deletions packit_service/worker/helpers/testing_farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
TESTING_FARM_INSTALLABILITY_TEST_REF,
TESTING_FARM_EXTRA_PARAM_MERGED_SUBTREES,
BASE_RETRY_INTERVAL_IN_MINUTES_FOR_OUTAGES,
PUBLIC_TF_ARCHITECTURE_LIST,
INTERNAL_TF_ARCHITECTURE_LIST,
)
from packit_service.models import (
CoprBuildTargetModel,
Expand Down Expand Up @@ -652,6 +654,37 @@ def distro2compose(self, target: str) -> Optional[str]:

return compose

def _is_supported_architecture(self, target: str):
distro, arch = target.rsplit("-", 1)
supported_architectures = (
INTERNAL_TF_ARCHITECTURE_LIST
if self.job_config.use_internal_tf
else PUBLIC_TF_ARCHITECTURE_LIST
)
if arch not in supported_architectures:
msg = (
f"The architecture {arch} is not in the list of "
f"available architectures:\n{supported_architectures}. "
)
logger.error(msg)
msg += (
"Please, check the targets defined in your test job configuration. If you think"
f" your configuration is correct, get in touch with [us]({CONTACTS_URL})."
)
description = (
f"The architecture {arch} is not available in the "
f"{'internal' if self.job_config.use_internal_tf else 'public'} "
f"Testing Farm infrastructure."
)
self.report_status_to_tests_for_test_target(
state=BaseCommitStatus.error,
description=description,
target=target,
markdown_content=msg,
)
return False
return True

def report_missing_build_chroot(self, chroot: str):
self.report_status_to_tests_for_chroot(
state=BaseCommitStatus.error,
Expand Down Expand Up @@ -794,6 +827,10 @@ def prepare_and_send_tf_request(
"""
logger.info("Preparing testing farm request...")

if not self._is_supported_architecture(test_run.target):
msg = "Not supported architecture."
return TaskResults(success=True, details={"msg": msg})

compose = self.distro2compose(test_run.target)

if not compose:
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/test_testing_farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1629,3 +1629,39 @@ def test_check_if_actor_can_run_job_and_report(jobs, event, should_pass):
event.update({"actor": "actor", "project_url": "url"})

assert TestingFarmHandler.pre_check(package_config, jobs[0], event) == should_pass


@pytest.mark.parametrize(
"target,use_internal_tf,supported",
[
("distro-aarch64", True, True),
("distro-x86_64", True, True),
("distro-aarch64", False, True),
("distro-x86_64", False, True),
("distro-ppc64le", True, True),
("distro-s390x", True, True),
("distro-ppc64le", False, False),
("distro-s390x", False, False),
],
)
def test_is_supported_architecture(target, use_internal_tf, supported):
job_helper = TFJobHelper(
service_config=ServiceConfig.get_service_config(),
package_config=flexmock(jobs=[]),
project=flexmock(),
metadata=flexmock(),
db_trigger=flexmock(),
job_config=JobConfig(
type=JobType.tests,
trigger=JobConfigTriggerType.pull_request,
packages={
"package": CommonPackageConfig(
use_internal_tf=use_internal_tf,
)
},
),
)
if not supported:
flexmock(TFJobHelper).should_receive("report_status_to_tests_for_test_target")

assert job_helper._is_supported_architecture(target) == supported