|
10 | 10 | from ogr.services.pagure import PagureProject |
11 | 11 | from packit.api import PackitAPI |
12 | 12 | from packit.config import Deployment, JobConfigTriggerType |
13 | | -from packit.exceptions import PackitException |
| 13 | +from packit.exceptions import PackitCommandFailedError, PackitException |
14 | 14 | from packit.local_project import LocalProjectBuilder |
15 | 15 | from packit.utils import commands |
16 | 16 |
|
@@ -244,6 +244,55 @@ def test_downstream_koji_scratch_build_cancel_running(mock_distgit_pr_functional |
244 | 244 | assert first_dict_value(results["job"])["success"] |
245 | 245 |
|
246 | 246 |
|
| 247 | +def test_downstream_koji_scratch_build_retry_on_submission_failure( |
| 248 | + mock_distgit_pr_functionality, |
| 249 | +): |
| 250 | + """Test that DownstreamKojiScratchBuildHandler retries on build submission failure. |
| 251 | +
|
| 252 | + Simulates a Koji CLI failure (e.g. network issue, Koji outage) and verifies |
| 253 | + the handler sets retry status and schedules a retry via Celery. |
| 254 | + """ |
| 255 | + flexmock(PackitAPI).should_receive("init_kerberos_ticket") |
| 256 | + koji_build_target = flexmock( |
| 257 | + id=123, |
| 258 | + target="main", |
| 259 | + status="queued", |
| 260 | + ) |
| 261 | + koji_build_target.should_receive("set_status").with_args("retry").once() |
| 262 | + koji_build_target.should_receive("set_task_id") |
| 263 | + koji_build_target.should_receive("set_web_url") |
| 264 | + koji_build_target.should_receive("set_build_logs_urls") |
| 265 | + koji_build_target.should_receive("set_data") |
| 266 | + koji_build_target.should_receive("set_build_submission_stdout") |
| 267 | + flexmock(KojiBuildTargetModel).should_receive("create").and_return(koji_build_target) |
| 268 | + flexmock(KojiBuildGroupModel).should_receive("create").and_return( |
| 269 | + flexmock(grouped_targets=[koji_build_target]), |
| 270 | + ) |
| 271 | + |
| 272 | + # Simulate koji CLI failure |
| 273 | + flexmock(commands).should_receive("run_command_remote").and_raise( |
| 274 | + PackitCommandFailedError, |
| 275 | + "Command failed", |
| 276 | + stdout_output="", |
| 277 | + stderr_output="koji: AuthError: unable to obtain a session", |
| 278 | + ) |
| 279 | + |
| 280 | + # Mock the Celery task's retry method to prevent actual retry and verify it's called |
| 281 | + flexmock(run_downstream_koji_scratch_build_handler).should_receive("retry").once() |
| 282 | + |
| 283 | + processing_results = SteveJobs().process_message(mock_distgit_pr_functionality) |
| 284 | + event_dict, _, job_config, package_config = get_parameters_from_results( |
| 285 | + processing_results[:1], |
| 286 | + ) |
| 287 | + results = run_downstream_koji_scratch_build_handler( |
| 288 | + package_config=package_config, |
| 289 | + event=event_dict, |
| 290 | + job_config=job_config, |
| 291 | + ) |
| 292 | + |
| 293 | + assert first_dict_value(results["job"])["success"] |
| 294 | + |
| 295 | + |
247 | 296 | def test_downstream_koji_build_cancel_running(monkeypatch): |
248 | 297 | """Test that DownstreamKojiBuildHandler calls cancel_running_builds. |
249 | 298 |
|
|
0 commit comments