From 7e7012c2f36b57fd9803c2c6feafac5acbccbfc5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 22 Nov 2023 14:22:55 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pubtools/_pulp/tasks/garbage_collect.py | 15 +++-- tests/garbage_collect/test_garbage_collect.py | 60 +++++++++++-------- 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/pubtools/_pulp/tasks/garbage_collect.py b/pubtools/_pulp/tasks/garbage_collect.py index 84cf4129..87cc5403 100644 --- a/pubtools/_pulp/tasks/garbage_collect.py +++ b/pubtools/_pulp/tasks/garbage_collect.py @@ -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): @@ -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)), ), ) @@ -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_( @@ -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: diff --git a/tests/garbage_collect/test_garbage_collect.py b/tests/garbage_collect/test_garbage_collect.py index 1710d84a..9a6fdfae 100644 --- a/tests/garbage_collect/test_garbage_collect.py +++ b/tests/garbage_collect/test_garbage_collect.py @@ -235,7 +235,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""" os.environ["PUBTOOLS_PULPLIB_PAGE_SIZE"] = "5" @@ -248,27 +247,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()) @@ -281,8 +285,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):