Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use --exodus-commit=phase1 in pulp hook [RHELDST-20490] #28

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading