diff --git a/packit_service/worker/helpers/testing_farm.py b/packit_service/worker/helpers/testing_farm.py index 590da91a2..a23fb9fed 100644 --- a/packit_service/worker/helpers/testing_farm.py +++ b/packit_service/worker/helpers/testing_farm.py @@ -10,8 +10,8 @@ from ogr.abstract import GitProject, PullRequest from ogr.utils import RequestResponse from packit.config import JobConfig, PackageConfig -from packit.exceptions import PackitConfigException, PackitException -from packit.utils import commands, nested_get +from packit.exceptions import PackitConfigException +from packit.utils import nested_get from packit.utils.koji_helper import KojiHelper from packit_service.config import Deployment, ServiceConfig @@ -1525,49 +1525,15 @@ def prepare_and_send_tf_request( ) def _payload_installability(self, distro: str, compose: str) -> dict: git_repo = "https://github.com/fedora-ci/installability-pipeline.git" - git_ref = ( - commands.run_command(["git", "ls-remote", git_repo, "HEAD"], output=True) - .stdout.strip() - .split()[0] - ) - - if distro == "fedora-rawhide": - # profile names are in "fedora-N" format - # extract current rawhide version number from its candidate tag - if not (candidate_tag := self.koji_helper.get_candidate_tag("rawhide")): - raise PackitException(f"Failed to get test profile for {distro}") - profile = re.sub(r"f(\d+)(-.*)?", r"fedora-\1", candidate_tag) - else: - profile = distro - - # installability test requires a Koji build - # (it should be guaranteed by the `HasEventSuccessfulScratchBuild` checker) - assert self.koji_build - - return { - "test": { - "tmt": { - "url": git_repo, - "ref": git_ref, - }, - }, - "environments": [ - { - "arch": "x86_64", - "os": {"compose": compose}, - "variables": { - "PROFILE_NAME": profile, - "TASK_ID": self.koji_build.task_id, - }, - }, - ], - "notification": { - "webhook": { - "url": f"{self.api_url}/testing-farm/results", - "token": self.service_config.testing_farm_secret, - }, + git_ref = "master" + payload = self._get_tf_base_payload(distro, compose, with_artifacts=False) + payload["test"] = { + "tmt": { + "url": git_repo, + "ref": git_ref, }, } + return payload @implements_fedora_ci_test( "rpminspect", @@ -1578,7 +1544,7 @@ def _payload_rpminspect(self, distro: str, compose: str) -> dict: git_ref = "master" # rpminspect defines its own container in the tmt plan file, # hence `compose=None` - payload = self._get_tf_base_payload(distro, None) + payload = self._get_tf_base_payload(distro, None, with_artifacts=False) payload["test"] = { "tmt": { "url": git_repo, @@ -1596,7 +1562,7 @@ def _payload_rpmlint(self, distro: str, compose: str) -> dict: git_ref = "main" # rpmlint defines its own container in the tmt plan file, # hence `compose=None` - payload = self._get_tf_base_payload(distro, None) + payload = self._get_tf_base_payload(distro, None, with_artifacts=False) payload["test"] = { "tmt": { "url": git_repo, @@ -1617,7 +1583,7 @@ def _get_fedora_ci_payload(self, distro: str, plan: str) -> dict: git_repo = "https://forge.fedoraproject.org/ci/shared-tests" git_ref = "main" if self.service_config.deployment == Deployment.prod else "stg" # All tests in ci/shared-tests define their own provision hence `compose=None` - payload = self._get_tf_base_payload(distro, None) + payload = self._get_tf_base_payload(distro, None, with_artifacts=False) payload["test"] = { "tmt": { "url": git_repo, @@ -1655,7 +1621,9 @@ def _payload_custom(self, distro: str, compose: str) -> dict: } return payload - def _get_tf_base_payload(self, distro: str, compose: Optional[str]) -> dict: + def _get_tf_base_payload( + self, distro: str, compose: Optional[str], with_artifacts: bool = True + ) -> dict: """ Common payload for all fedora-ci testing-farm jobs. @@ -1689,7 +1657,7 @@ def _get_tf_base_payload(self, distro: str, compose: Optional[str]) -> dict: "arch": "x86_64", **os_params, "variables": variables, - "artifacts": artifacts, + "artifacts": (with_artifacts and artifacts) or [], "tmt": { "context": context, }, diff --git a/tests/integration/test_listen_to_fedmsg.py b/tests/integration/test_listen_to_fedmsg.py index 7574cd7e5..5c8371418 100644 --- a/tests/integration/test_listen_to_fedmsg.py +++ b/tests/integration/test_listen_to_fedmsg.py @@ -26,6 +26,7 @@ from packit.config.requirements import LabelRequirementsConfig, RequirementsConfig from packit.copr_helper import CoprHelper from packit.local_project import LocalProject, LocalProjectBuilder +from packit.utils import commands from packit.utils.koji_helper import KojiHelper import packit_service.service.urls as urls @@ -65,7 +66,6 @@ from packit_service.worker.helpers.testing_farm import ( TestingFarmClient, TestingFarmJobHelper, - commands, ) from packit_service.worker.jobs import SteveJobs from packit_service.worker.monitoring import Pushgateway @@ -2677,72 +2677,58 @@ def test_koji_build_end_downstream( koji_build_pr_downstream.should_receive("set_build_logs_urls") koji_build_pr_downstream.should_receive("set_web_url") - installability_repo = "https://github.com/fedora-ci/installability-pipeline.git" - installability_hash = "f6cd4a50476d9c8ffa36472c5ab2d2c8aad6cee1" - - flexmock(commands).should_receive("run_command").with_args( - ["git", "ls-remote", installability_repo, "HEAD"], output=True - ).and_return(flexmock(stdout=f"{installability_hash}\tHEAD")) + def _common_payload(*, with_compose: bool, with_artifact: bool): + _payload = { + "environments": [ + { + "arch": "x86_64", + "variables": { + "KOJI_TASK_ID": "1", + }, + "artifacts": [], + "tmt": { + "context": { + "distro": distro, + "arch": "x86_64", + "trigger": "commit", + "initiator": "fedora-ci", + "dist-git-branch": "rawhide", + **extra_context, + }, + }, + }, + ], + "notification": { + "webhook": { + "url": "https://stg.packit.dev/api/testing-farm/results", + "token": "secret token", + }, + }, + } + assert isinstance(_payload["environments"], list) # narrow type + if with_artifact: + _payload["environments"][0]["artifacts"] = [ + { + "id": "1", + "type": "fedora-koji-build", + } + ] + if with_compose: + _payload["environments"][0]["os"] = {"compose": compose} + return _payload + installability_repo = "https://github.com/fedora-ci/installability-pipeline.git" payload_installability = { "test": { "tmt": { "url": installability_repo, - "ref": installability_hash, - }, - }, - "environments": [ - { - "arch": "x86_64", - "os": {"compose": compose}, - "variables": { - "PROFILE_NAME": profile, - "TASK_ID": "1", - }, - }, - ], - "notification": { - "webhook": { - "url": "https://stg.packit.dev/api/testing-farm/results", - "token": "secret token", + "ref": "master", }, }, + **_common_payload(with_compose=True, with_artifact=False), } rpminspect_repo = "https://github.com/fedora-ci/rpminspect-pipeline.git" - common_payload_no_compose = { - "environments": [ - { - "arch": "x86_64", - "variables": { - "KOJI_TASK_ID": "1", - }, - "artifacts": [ - { - "id": "1", - "type": "fedora-koji-build", - }, - ], - "tmt": { - "context": { - "distro": distro, - "arch": "x86_64", - "trigger": "commit", - "initiator": "fedora-ci", - "dist-git-branch": "rawhide", - **extra_context, - }, - }, - }, - ], - "notification": { - "webhook": { - "url": "https://stg.packit.dev/api/testing-farm/results", - "token": "secret token", - }, - }, - } - payload_rpminspect = { "test": { "tmt": { @@ -2750,7 +2736,7 @@ def test_koji_build_end_downstream( "ref": "master", }, }, - **common_payload_no_compose, + **_common_payload(with_compose=False, with_artifact=False), } rpmlint_repo = "https://github.com/packit/tmt-plans.git" @@ -2763,7 +2749,7 @@ def test_koji_build_end_downstream( "name": "/plans/rpmlint", }, }, - **common_payload_no_compose, + **_common_payload(with_compose=False, with_artifact=False), } shared_tests_repo = "https://forge.fedoraproject.org/ci/shared-tests" @@ -2776,7 +2762,7 @@ def test_koji_build_end_downstream( "name": "/rmdepcheck", }, }, - **common_payload_no_compose, + **_common_payload(with_compose=False, with_artifact=False), } payload_license_validate = { @@ -2787,7 +2773,7 @@ def test_koji_build_end_downstream( "name": "/license-validate", }, }, - **common_payload_no_compose, + **_common_payload(with_compose=False, with_artifact=False), } payload_custom = { @@ -2797,37 +2783,7 @@ def test_koji_build_end_downstream( "ref": "0011223344", }, }, - "environments": [ - { - "arch": "x86_64", - "os": {"compose": compose}, - "variables": { - "KOJI_TASK_ID": "1", - }, - "artifacts": [ - { - "id": "1", - "type": "fedora-koji-build", - }, - ], - "tmt": { - "context": { - "distro": distro, - "arch": "x86_64", - "trigger": "commit", - "initiator": "fedora-ci", - "dist-git-branch": "rawhide", - **extra_context, - }, - }, - }, - ], - "notification": { - "webhook": { - "url": "https://stg.packit.dev/api/testing-farm/results", - "token": "secret token", - }, - }, + **_common_payload(with_compose=True, with_artifact=True), } flexmock(aliases).should_receive("get_aliases").and_return({"fedora-all": [], "epel-all": []}) @@ -2839,10 +2795,6 @@ def test_koji_build_end_downstream( distro, ).and_return(compose) - flexmock(KojiHelper).should_receive("get_candidate_tag").with_args("rawhide").and_return( - "f43-updates-candidate" - ) - pipeline_id = "5e8079d8-f181-41cf-af96-28e99774eb68" flexmock(TestingFarmClient).should_receive( "send_testing_farm_request",