1414from packit .local_project import LocalProjectBuilder
1515from packit .utils import commands
1616
17+ from packit_service import utils
1718from packit_service .config import ServiceConfig
1819from packit_service .constants import SANDCASTLE_WORK_DIR
1920from packit_service .models import (
2829from packit_service .worker .jobs import SteveJobs
2930from packit_service .worker .monitoring import Pushgateway
3031from packit_service .worker .tasks import (
32+ run_downstream_koji_eln_scratch_build_handler ,
3133 run_downstream_koji_scratch_build_handler ,
3234)
3335from tests .spellbook import DATA_DIR , first_dict_value , get_parameters_from_results
@@ -39,30 +41,47 @@ def distgit_pr_event():
3941
4042
4143@pytest .mark .parametrize (
42- "target_branch, uid, check_name" ,
44+ "target_branch, uid, check_name, eln " ,
4345 [
4446 pytest .param (
4547 "rawhide" ,
4648 "e0091d5fbcb20572cbf2e6442af9bed5" ,
4749 "Packit - scratch build - rawhide" ,
50+ False ,
4851 id = "rawhide target branch" ,
4952 ),
53+ pytest .param (
54+ "rawhide" ,
55+ "8edd48272efe6aff7d1d92bdffcaf9a0" ,
56+ "Packit - scratch build - eln" ,
57+ True ,
58+ id = "rawhide branch, rawhide + eln target" ,
59+ ),
5060 pytest .param (
5161 "f42" ,
5262 "6f08c3bbb20660dc8c597bc7dbe4f056" ,
5363 "Packit - scratch build - f42" ,
64+ False ,
5465 id = "f42 target branch" ,
5566 ),
5667 ],
5768)
58- def test_downstream_koji_scratch_build (distgit_pr_event , target_branch , uid , check_name ):
69+ def test_downstream_koji_scratch_build (distgit_pr_event , target_branch , uid , check_name , eln ):
5970 distgit_pr_event ["pullrequest" ]["branch" ] = target_branch
6071 pr_object = (
61- flexmock ()
72+ flexmock (target_branch = target_branch )
6273 .should_receive ("set_flag" )
6374 .with_args (username = check_name , comment = str , url = str , status = CommitStatus , uid = uid )
6475 .mock ()
6576 )
77+ if eln :
78+ check_name = "Packit - scratch build - rawhide"
79+ uid = "e0091d5fbcb20572cbf2e6442af9bed5"
80+ (
81+ pr_object .should_receive ("set_flag" )
82+ .with_args (username = check_name , comment = str , url = str , status = CommitStatus , uid = uid )
83+ .mock ()
84+ )
6685 dg_project = (
6786 flexmock (
6887 PagureProject (namespace = "rpms" , repo = "optee_os" , service = flexmock (read_only = False ))
@@ -73,6 +92,9 @@ def test_downstream_koji_scratch_build(distgit_pr_event, target_branch, uid, che
7392 .should_receive ("get_pr" )
7493 .and_return (pr_object )
7594 .mock ()
95+ .should_receive ("get_git_urls" )
96+ .and_return ({"git" : "https://src.fedoraproject.org/rpms/optee_os.git" })
97+ .mock ()
7698 )
7799 service_config = (
78100 flexmock (
@@ -112,6 +134,13 @@ def test_downstream_koji_scratch_build(distgit_pr_event, target_branch, uid, che
112134 )
113135 flexmock (PipelineModel ).should_receive ("create" )
114136
137+ flexmock (utils ).should_receive ("get_eln_packages" ).and_return (["optee_os" ] if eln else [])
138+ if eln :
139+ flexmock (commands ).should_receive ("run_command" ).with_args (
140+ ["git" , "ls-remote" , "https://src.fedoraproject.org/rpms/optee_os.git" , "eln" ],
141+ output = True ,
142+ ).and_return (flexmock (stdout = "" ))
143+
115144 koji_build = flexmock (
116145 id = 123 ,
117146 target = "main" ,
@@ -130,8 +159,8 @@ def test_downstream_koji_scratch_build(distgit_pr_event, target_branch, uid, che
130159 )
131160
132161 flexmock (LocalProjectBuilder , _refresh_the_state = lambda * args : None )
133- flexmock (Signature ).should_receive ("apply_async" ).once ( )
134- flexmock (Pushgateway ).should_receive ("push" ).times (2 ).and_return ()
162+ flexmock (Signature ).should_receive ("apply_async" ).times ( 2 if eln else 1 )
163+ flexmock (Pushgateway ).should_receive ("push" ).times (3 if eln else 2 ).and_return ()
135164 flexmock (commands ).should_receive ("run_command_remote" ).with_args (
136165 cmd = [
137166 "koji" ,
@@ -145,15 +174,29 @@ def test_downstream_koji_scratch_build(distgit_pr_event, target_branch, uid, che
145174 output = True ,
146175 print_live = True ,
147176 ).and_return (flexmock (stdout = "some output" ))
177+ if eln :
178+ flexmock (commands ).should_receive ("run_command_remote" ).with_args (
179+ cmd = [
180+ "koji" ,
181+ "build" ,
182+ "--scratch" ,
183+ "--nowait" ,
184+ "eln" ,
185+ "git+https://src.fedoraproject.org/forks/zbyszek/rpms/optee_os.git#889f07af35d27bbcaf9c535c17a63b974aa42ee3" ,
186+ ],
187+ cwd = Path ,
188+ output = True ,
189+ print_live = True ,
190+ ).and_return (flexmock (stdout = "some output" ))
148191 flexmock (PackitAPI ).should_receive ("init_kerberos_ticket" )
149192
150193 flexmock (distgit ).should_receive ("get_koji_task_id_and_url_from_stdout" ).and_return (
151194 (123 , "koji-web-url" )
152- ).once ( )
195+ ).times ( 2 if eln else 1 )
153196
154197 processing_results = SteveJobs ().process_message (distgit_pr_event )
155198 event_dict , _ , job_config , package_config = get_parameters_from_results (
156- processing_results ,
199+ processing_results [: 1 ] ,
157200 )
158201 assert json .dumps (event_dict )
159202 results = run_downstream_koji_scratch_build_handler (
@@ -163,3 +206,12 @@ def test_downstream_koji_scratch_build(distgit_pr_event, target_branch, uid, che
163206 )
164207
165208 assert first_dict_value (results ["job" ])["success" ]
209+
210+ if eln :
211+ results = run_downstream_koji_eln_scratch_build_handler (
212+ package_config = package_config ,
213+ event = event_dict ,
214+ job_config = job_config ,
215+ )
216+
217+ assert first_dict_value (results ["job" ])["success" ]
0 commit comments