From aa4285c0cc3c31fb7cd860dfd79097e9d3bedba6 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Apr 27 2021 06:23:31 +0000 Subject: [PATCH 1/3] backend: catch correct client exceptions in copr_prune_results Complements PR#1783 --- diff --git a/backend/run/copr_prune_results.py b/backend/run/copr_prune_results.py index b552a11..60b832c 100755 --- a/backend/run/copr_prune_results.py +++ b/backend/run/copr_prune_results.py @@ -14,8 +14,7 @@ import multiprocessing from prunerepo.helpers import get_rpms_to_remove -from copr.exceptions import CoprException -from copr.exceptions import CoprRequestException +from copr.v3.exceptions import CoprException from copr_backend.helpers import BackendConfigReader, get_redis_logger from copr_backend.helpers import uses_devel_repo, get_persistent_status, get_auto_prune_status, call_copr_repo @@ -134,7 +133,7 @@ class Pruner(object): LOG.info("Skipped %s/%s since auto-prunning is disabled for the project", username, projectdir) return - except (CoprException, CoprRequestException) as exception: + except CoprException as exception: LOG.error("Failed to get project details for %s/%s with error: %s", username, projectdir, exception) return From 74458729f3b6441e7bc7bae841cdb6a0d9e8350e Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Apr 27 2021 06:23:31 +0000 Subject: [PATCH 2/3] backend: prunerepo: don't re-createrepo when no rpm is removed Fixes: #1789 --- diff --git a/backend/run/copr_prune_results.py b/backend/run/copr_prune_results.py index 60b832c..c6637a3 100755 --- a/backend/run/copr_prune_results.py +++ b/backend/run/copr_prune_results.py @@ -60,7 +60,8 @@ def run_prunerepo(chroot_path, username, projectdir, sub_dir_name, prune_days): try: LOG.info("Pruning of %s/%s/%s started", username, projectdir, sub_dir_name) rpms = get_rpms_to_remove(chroot_path, days=prune_days, log=LOG) - call_copr_repo(directory=chroot_path, rpms_to_remove=rpms) + if rpms: + call_copr_repo(directory=chroot_path, rpms_to_remove=rpms) clean_copr(chroot_path, prune_days, verbose=True) except Exception as err: # pylint: disable=broad-except LOG.exception(err) @@ -188,6 +189,11 @@ def clean_copr(path, days=DEF_DAYS, verbose=True): continue if is_rpm_in_dir(dir_path): continue + + # Note that deleting some rpm files from the directory by + # run_prunerepo() actually bumps the st_mtime of the directory. So we + # keep the directory here at least one another period after the last RPM + # removal. if time.time() - os.stat(dir_path).st_mtime <= days * 24 * 3600: continue From c55b3c37fb5971e96731faaf7ca0b7f1d23a7a25 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Apr 27 2021 06:23:31 +0000 Subject: [PATCH 3/3] backend: better logging in prunerepo --- diff --git a/backend/run/copr_prune_results.py b/backend/run/copr_prune_results.py index c6637a3..fdc3a8f 100755 --- a/backend/run/copr_prune_results.py +++ b/backend/run/copr_prune_results.py @@ -61,7 +61,9 @@ def run_prunerepo(chroot_path, username, projectdir, sub_dir_name, prune_days): LOG.info("Pruning of %s/%s/%s started", username, projectdir, sub_dir_name) rpms = get_rpms_to_remove(chroot_path, days=prune_days, log=LOG) if rpms: - call_copr_repo(directory=chroot_path, rpms_to_remove=rpms) + LOG.info("Going to remove %s RPMs in %s", len(rpms), chroot_path) + call_copr_repo(directory=chroot_path, rpms_to_remove=rpms, + logger=LOG) clean_copr(chroot_path, prune_days, verbose=True) except Exception as err: # pylint: disable=broad-except LOG.exception(err) @@ -179,7 +181,7 @@ def clean_copr(path, days=DEF_DAYS, verbose=True): """ Remove whole copr build dirs if they no longer contain a RPM file """ - LOG.info("Cleaning COPR repository...") + LOG.info("Cleaning COPR repository %s", path) for dir_name in os.listdir(path): dir_path = os.path.abspath(os.path.join(path, dir_name))