Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 22, 2023
1 parent 73d32ef commit 4796b1a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
15 changes: 7 additions & 8 deletions pubtools/_pulp/tasks/garbage_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
LOG = logging.getLogger("pubtools.pulp")
step = PulpTask.step

UNASSOCIATE_BATCH_LIMIT = int(
os.getenv("PULP_GC_UNASSOCIATE_BATCH_LIMIT", "10000"))
UNASSOCIATE_BATCH_LIMIT = int(os.getenv("PULP_GC_UNASSOCIATE_BATCH_LIMIT", "10000"))


class GarbageCollect(PulpClientService, PulpTask):
Expand Down Expand Up @@ -98,8 +97,7 @@ def clean_all_rpm_content(self):
Criteria.with_unit_type(RpmUnit, unit_fields=["unit_id"]),
Criteria.with_field(
"cdn_published",
Matcher.less_than(
datetime.utcnow() - timedelta(days=arc_threshold)),
Matcher.less_than(datetime.utcnow() - timedelta(days=arc_threshold)),
),
)

Expand All @@ -109,8 +107,10 @@ def clean_all_rpm_content(self):
LOG.info("No all-rpm-content found older than %s", arc_threshold)
return

unit_batches = [units[i:i + UNASSOCIATE_BATCH_LIMIT] for i in
range(0, len(units), UNASSOCIATE_BATCH_LIMIT)]
unit_batches = [
units[i : i + UNASSOCIATE_BATCH_LIMIT]
for i in range(0, len(units), UNASSOCIATE_BATCH_LIMIT)
]
for batch in unit_batches:
LOG.info("Submitting batch for deletion")
deletion_criteria = Criteria.and_(
Expand All @@ -121,8 +121,7 @@ def clean_all_rpm_content(self):
),
)
LOG.debug("Submitting batch for deletion")
deletion_task = arc_repo.remove_content(
criteria=deletion_criteria).result()
deletion_task = arc_repo.remove_content(criteria=deletion_criteria).result()
for task in deletion_task:
if task.repo_id == "all-rpm-content":
for unit in task.units:
Expand Down
60 changes: 36 additions & 24 deletions tests/garbage_collect/test_garbage_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ def test_arc_garbage_collect(mock_logger):
mock_logger.info.assert_any_call("Old all-rpm-content deleted: %s", rpm2.name)



def test_arc_garbage_collect_in_batches(mock_logger):
"""deletes relevant all-rpm-content content in batches"""
gc_module.UNASSOCIATE_BATCH_LIMIT = 5
Expand All @@ -249,27 +248,32 @@ def test_arc_garbage_collect_in_batches(mock_logger):
assert list(client.search_content()) == []

all_rpm_content = client.get_repository("all-rpm-content").result()
new_rpms = [RpmUnit(
cdn_published=datetime.datetime.utcnow(),
arch="src",
filename="test-arc-new%02d-1.0-1.src.rpm" % i,
name="test-arc-new%02d" % i,
version="1.0",
release="1",
content_type_id="rpm",
unit_id="gc_arc_new%02d" % i,
) for i in range(0, 10)]
old_rpms = [RpmUnit(
cdn_published=datetime.datetime.utcnow() - datetime.timedelta(
days=190),
arch="src",
filename="test-arc-old%02d-1.0-1.src.rpm" % i,
name="test-arc-old%02d" % i,
version="1.0",
release="1",
content_type_id="rpm",
unit_id="gc_arc_old%02d" % i,
) for i in range(0, 23)]
new_rpms = [
RpmUnit(
cdn_published=datetime.datetime.utcnow(),
arch="src",
filename="test-arc-new%02d-1.0-1.src.rpm" % i,
name="test-arc-new%02d" % i,
version="1.0",
release="1",
content_type_id="rpm",
unit_id="gc_arc_new%02d" % i,
)
for i in range(0, 10)
]
old_rpms = [
RpmUnit(
cdn_published=datetime.datetime.utcnow() - datetime.timedelta(days=190),
arch="src",
filename="test-arc-old%02d-1.0-1.src.rpm" % i,
name="test-arc-old%02d" % i,
version="1.0",
release="1",
content_type_id="rpm",
unit_id="gc_arc_old%02d" % i,
)
for i in range(0, 23)
]

controller.insert_units(all_rpm_content, new_rpms + old_rpms)
updated_rpm = list(client.get_repository("all-rpm-content").search_content())
Expand All @@ -282,8 +286,16 @@ def test_arc_garbage_collect_in_batches(mock_logger):
gc.main()
updated_rpm = list(client.get_repository("all-rpm-content").search_content())
assert len(updated_rpm) == 10
assert len([call for call in mock_logger.debug.call_args_list
if 'Submitting batch for deletion' in call.args]) == 5
assert (
len(
[
call
for call in mock_logger.debug.call_args_list
if "Submitting batch for deletion" in call.args
]
)
== 5
)


def test_arc_garbage_collect_0items(mock_logger):
Expand Down

0 comments on commit 4796b1a

Please sign in to comment.