Skip to content

Commit

Permalink
Merge pull request #28 from rohanpm/commit-phase1
Browse files Browse the repository at this point in the history
Use --exodus-commit=phase1 in pulp hook [RHELDST-20490]
  • Loading branch information
rohanpm authored Oct 19, 2023
2 parents 032079e + d394238 commit de5506e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pubtools/exodus/_hooks/pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`):
Expand All @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tests/test_exodus_pulp_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_exodus_pulp_typical(
rsync_extra_args=[
"--existing-arg",
"--exodus-publish=497f6eca-6276-4993-bfeb-53cbbbba6f08",
"--exodus-commit=phase1",
],
)

Expand All @@ -55,6 +56,29 @@ 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")

Expand Down

0 comments on commit de5506e

Please sign in to comment.