Skip to content

Commit 11d4722

Browse files
Fix/tf include tf extra params for install (#2779)
Fix/tf include tf extra params for install TODO: Write new tests or update the old ones to cover new functionality. Update doc-strings where appropriate. Update or write new documentation in packit/packit.dev. ‹fill in› RELEASE NOTES BEGIN tf_extra_params should now be included when submitting the automatic upstream installability check to the Testing Farm. RELEASE NOTES END Reviewed-by: Laura Barcziová
2 parents 68593a0 + f33b8ee commit 11d4722

File tree

2 files changed

+112
-40
lines changed

2 files changed

+112
-40
lines changed

packit_service/worker/helpers/testing_farm.py

+53-39
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,26 @@ def is_final(v):
446446
for payload_el, params_el in zip(payload, params):
447447
cls._merge_payload_with_extra_params(payload_el, params_el)
448448

449+
def _inject_extra_params(self, payload: dict) -> dict:
450+
if not hasattr(self.job_config, "tf_extra_params"):
451+
return payload
452+
453+
extra_params = self.job_config.tf_extra_params
454+
# Merge only some subtrees, we do not want the user to override notification or api_key!
455+
for subtree in TESTING_FARM_EXTRA_PARAM_MERGED_SUBTREES:
456+
if subtree not in extra_params:
457+
continue
458+
459+
if subtree not in payload:
460+
payload[subtree] = extra_params[subtree]
461+
else:
462+
self._merge_payload_with_extra_params(
463+
payload[subtree],
464+
extra_params[subtree],
465+
)
466+
467+
return payload
468+
449469
@classmethod
450470
def _handle_extra_artifacts(cls, payload: Any, extra_params_artifacts: Any):
451471
"""
@@ -599,23 +619,7 @@ def _payload(
599619
},
600620
}
601621

602-
if hasattr(self.job_config, "tf_extra_params"):
603-
extra_params = self.job_config.tf_extra_params
604-
else:
605-
extra_params = {}
606-
# Merge only some subtrees, we do not want the user to override notification or api_key!
607-
for subtree in TESTING_FARM_EXTRA_PARAM_MERGED_SUBTREES:
608-
if subtree not in extra_params:
609-
continue
610-
if subtree not in payload:
611-
payload[subtree] = extra_params[subtree]
612-
else:
613-
self._merge_payload_with_extra_params(
614-
payload[subtree],
615-
extra_params[subtree],
616-
)
617-
618-
return payload
622+
return self._inject_extra_params(payload)
619623

620624
def _payload_install_test(self, build_id: int, target: str, compose: str) -> dict:
621625
"""
@@ -625,31 +629,41 @@ def _payload_install_test(self, build_id: int, target: str, compose: str) -> dic
625629
"""
626630
copr_build = CoprBuildTargetModel.get_by_build_id(build_id)
627631
distro, arch = target.rsplit("-", 1)
628-
return {
629-
"api_key": self.service_config.testing_farm_secret,
630-
"test": {
631-
"tmt": {
632-
"url": TESTING_FARM_INSTALLABILITY_TEST_URL,
633-
"ref": TESTING_FARM_INSTALLABILITY_TEST_REF,
634-
"name": "/packit/installation",
635-
},
636-
},
637-
"environments": [
638-
{
639-
"arch": arch,
640-
"os": {"compose": compose},
641-
"variables": {
642-
"REPOSITORY": f"{copr_build.owner}/{copr_build.project_name}",
632+
return self._inject_extra_params(
633+
{
634+
"api_key": self.service_config.testing_farm_secret,
635+
"test": {
636+
"tmt": {
637+
"url": TESTING_FARM_INSTALLABILITY_TEST_URL,
638+
"ref": TESTING_FARM_INSTALLABILITY_TEST_REF,
639+
"name": "/packit/installation",
643640
},
644641
},
645-
],
646-
"notification": {
647-
"webhook": {
648-
"url": f"{self.api_url}/testing-farm/results",
649-
"token": self.service_config.testing_farm_secret,
642+
"environments": [
643+
{
644+
"arch": arch,
645+
"os": {"compose": compose},
646+
"variables": {
647+
"REPOSITORY": f"{copr_build.owner}/{copr_build.project_name}",
648+
},
649+
"tmt": {
650+
"context": {
651+
"distro": distro,
652+
"arch": arch,
653+
"trigger": "commit",
654+
"initiator": "packit",
655+
},
656+
},
657+
},
658+
],
659+
"notification": {
660+
"webhook": {
661+
"url": f"{self.api_url}/testing-farm/results",
662+
"token": self.service_config.testing_farm_secret,
663+
},
650664
},
651-
},
652-
}
665+
}
666+
)
653667

654668
def check_comment_pr_argument_and_report(self) -> bool:
655669
"""

tests/unit/test_testing_farm.py

+59-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
)
3131
from packit_service.models import (
3232
BuildStatus,
33+
CoprBuildTargetModel,
3334
PipelineModel,
3435
ProjectEventModel,
3536
ProjectEventModelType,
@@ -1002,7 +1003,7 @@ def test_merge_payload_with_extra_params(payload, params, result):
10021003
assert payload == result
10031004

10041005

1005-
def test_merge_extra_params_with_install():
1006+
def test_merge_extra_params():
10061007
tf_settings = {"provisioning": {"tags": {"BusinessUnit": "sst_upgrades"}}}
10071008

10081009
service_config = flexmock(
@@ -1058,6 +1059,63 @@ def test_merge_extra_params_with_install():
10581059
)
10591060

10601061

1062+
def test_merge_extra_params_with_install():
1063+
tf_settings = {"provisioning": {"tags": {"BusinessUnit": "sst_upgrades"}}}
1064+
1065+
service_config = flexmock(
1066+
testing_farm_secret="secret token",
1067+
deployment="prod",
1068+
comment_command_prefix="/packit-dev",
1069+
)
1070+
package_config = flexmock()
1071+
project = flexmock(full_repo_name="test/merge")
1072+
metadata = flexmock(
1073+
commit_sha="0000000",
1074+
pr_id=None,
1075+
tag_name=None,
1076+
event_dict={"comment": ""},
1077+
)
1078+
db_project_event = (
1079+
flexmock().should_receive("get_project_event_object").and_return(flexmock()).mock()
1080+
)
1081+
flexmock(CoprBuildTargetModel).should_receive("get_by_build_id").with_args(1234).and_return(
1082+
flexmock(
1083+
owner="packit",
1084+
project_name="packit",
1085+
)
1086+
)
1087+
job_config = flexmock(
1088+
fmf_url="https://github.com/fmf/",
1089+
fmf_ref="main",
1090+
fmf_path="/",
1091+
tmt_plan=None,
1092+
upstream_package_name="test",
1093+
upstream_project_url="https://github.com/test",
1094+
downstream_package_name="test",
1095+
downstream_project_url="https://src.fedoraproject.org/test",
1096+
use_internal_tf=False,
1097+
tf_extra_params={
1098+
"environments": [
1099+
{"tmt": {"context": {"distro": "rhel-7.9"}}, "settings": tf_settings},
1100+
],
1101+
},
1102+
)
1103+
helper = TFJobHelper(
1104+
service_config,
1105+
package_config,
1106+
project,
1107+
metadata,
1108+
db_project_event,
1109+
job_config,
1110+
)
1111+
1112+
payload = helper._payload_install_test(1234, "rhel-7.9", "rhel-7.9")
1113+
assert (
1114+
payload["environments"][0]["settings"]["provisioning"]["tags"]["BusinessUnit"]
1115+
== "sst_upgrades"
1116+
)
1117+
1118+
10611119
@pytest.mark.parametrize(
10621120
(
10631121
"fmf_url",

0 commit comments

Comments
 (0)