diff --git a/pubtools/exodus/_hooks/pulp.py b/pubtools/exodus/_hooks/pulp.py index 70f6ad8..b48f6a4 100644 --- a/pubtools/exodus/_hooks/pulp.py +++ b/pubtools/exodus/_hooks/pulp.py @@ -24,8 +24,8 @@ def __init__(self): def pulp_repository_pre_publish(self, repository, options): """Invoked as the first step in publishing a Pulp repository. - This implementation adds to each config the --exodus-publish argument, - attaching the repository to an exodus-gw publish. + This implementation adds to each config the necessary arguments + to attach this repository's publish task to an exodus-gw publish. Args: repository (:class:`~pubtools.pulplib.Repository`): @@ -48,6 +48,17 @@ def pulp_repository_pre_publish(self, repository, options): list(options.rsync_extra_args) if options.rsync_extra_args else [] ) args.append("--exodus-publish=%s" % self.publish["id"]) + + # 2023-10: by default, the pulp hook should always use phase1 commit. + # But since the functionality is relatively new, this is provided as an + # escape hatch in case it would need to be disabled in some environments + # for unanticipated reasons. + # + # Consider deleting this conditional once the functionality is proven + # in production. + if os.getenv("EXODUS_PULP_HOOK_PHASE1_COMMIT", "1") == "1": + args.append("--exodus-commit=phase1") + return attr.evolve(options, rsync_extra_args=args) @property diff --git a/tests/test_exodus_pulp_hooks.py b/tests/test_exodus_pulp_hooks.py index 8ff759d..353b4d5 100644 --- a/tests/test_exodus_pulp_hooks.py +++ b/tests/test_exodus_pulp_hooks.py @@ -34,6 +34,7 @@ def test_exodus_pulp_typical( rsync_extra_args=[ "--existing-arg", "--exodus-publish=497f6eca-6276-4993-bfeb-53cbbbba6f08", + "--exodus-commit=phase1", ], ) @@ -55,6 +56,27 @@ def test_exodus_pulp_typical( ) +def test_exodus_pulp_phase1_disabled(successful_gw_task, monkeypatch: pytest.MonkeyPatch): + monkeypatch.setenv("EXODUS_PULP_HOOK_PHASE1_COMMIT", "0") + + with task_context(): + hook_rets = pm.hook.pulp_repository_pre_publish( + repository=None, + options=FakePublishOptions(rsync_extra_args=["--existing-arg"]), + ) + hook_rets = [ret for ret in hook_rets if ret is not None] + + # The pre-publish hook should've returned options with exodus-publish + # arg appended to existing rsync_extra_args, but this time it should + # NOT have added exodus-commit due to the above env var. + assert hook_rets[0] == FakePublishOptions( + rsync_extra_args=[ + "--existing-arg", + "--exodus-publish=497f6eca-6276-4993-bfeb-53cbbbba6f08", + ], + ) + + def test_exodus_pulp_no_publish(patch_env_vars, caplog): caplog.set_level(logging.DEBUG, "pubtools-exodus")