Skip to content

Commit

Permalink
Merge pull request #27 from rohanpm/hook-disable
Browse files Browse the repository at this point in the history
Introduce var to disable just pulp hook [RHELDST-20492]
  • Loading branch information
rohanpm authored Sep 26, 2023
2 parents 3c96e48 + 352a1e1 commit ca48c61
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
12 changes: 12 additions & 0 deletions pubtools/exodus/_hooks/pulp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
import sys
from threading import Lock

Expand Down Expand Up @@ -49,6 +50,17 @@ def pulp_repository_pre_publish(self, repository, options):
args.append("--exodus-publish=%s" % self.publish["id"])
return attr.evolve(options, rsync_extra_args=args)

@property
def exodus_enabled(self):
# If this hook-specific env var is set, then it solely determines
# whether the hook is enabled.
enabled = os.getenv("EXODUS_PULP_HOOK_ENABLED")
if enabled is not None:
return enabled.lower() in ["true", "t", "1", "yes", "y"]

# Otherwise, we let super decide, which will check a more generic env var.
return super().exodus_enabled

def ensure_publish_committed(self):
"""Commit the current publish, if and only if there is a current publish
and it was not already committed.
Expand Down
17 changes: 16 additions & 1 deletion tests/test_exodus_pulp_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def test_exodus_pulp_no_publish(patch_env_vars, caplog):
assert "No exodus-gw publish to commit" in caplog.text


def test_exodus_pulp_disabled(monkeypatch, caplog):
def test_exodus_pulp_disabled_global(monkeypatch, caplog):
"""Tests disablement of hook via global EXODUS_ENABLED var."""
monkeypatch.setenv("EXODUS_ENABLED", "False")
caplog.set_level(logging.INFO, "pubtools-exodus")

Expand All @@ -74,3 +75,17 @@ def test_exodus_pulp_disabled(monkeypatch, caplog):

# Should not have generated anything INFO or higher.
assert caplog.text == ""


def test_exodus_pulp_disabled_hook(monkeypatch, caplog):
"""Tests disablement of hook via hook-specific var."""
monkeypatch.setenv("EXODUS_ENABLED", "True")
monkeypatch.setenv("EXODUS_PULP_HOOK_ENABLED", "0")
caplog.set_level(logging.INFO, "pubtools-exodus")

with task_context():
# With Exodus disabled, this should be a no-op.
pm.hook.pulp_repository_pre_publish(repository=None, options={})

# Should not have generated anything INFO or higher.
assert caplog.text == ""

0 comments on commit ca48c61

Please sign in to comment.