From 26869fb3dbeaff7d024a6ebdd34da4e0776d0d68 Mon Sep 17 00:00:00 2001 From: Ina Panova Date: Fri, 21 Jul 2023 14:18:51 +0200 Subject: [PATCH] Taught repair task to be tolerant in the face of any artifact download failure. closes #4111 (cherry picked from commit 4310ea009488ac25478db30fd1350aa3b12487ef) --- CHANGES/4111.bugfix | 1 + .../app/management/commands/handle-artifact-checksums.py | 9 ++++----- pulpcore/app/tasks/repository.py | 7 +++---- 3 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 CHANGES/4111.bugfix diff --git a/CHANGES/4111.bugfix b/CHANGES/4111.bugfix new file mode 100644 index 0000000000..04e33541ba --- /dev/null +++ b/CHANGES/4111.bugfix @@ -0,0 +1 @@ +Taught repair task to be tolerant in the face of any artifact download failure. diff --git a/pulpcore/app/management/commands/handle-artifact-checksums.py b/pulpcore/app/management/commands/handle-artifact-checksums.py index 080b987ae3..78ab05b9ad 100644 --- a/pulpcore/app/management/commands/handle-artifact-checksums.py +++ b/pulpcore/app/management/commands/handle-artifact-checksums.py @@ -2,8 +2,6 @@ from gettext import gettext as _ -from aiohttp.client_exceptions import ClientResponseError - from django.conf import settings from django.core.management import BaseCommand, CommandError from django.db.models import Q, Sum @@ -128,7 +126,7 @@ def _download_artifact(self, artifact, checksum, file_path): downloader = remote.get_downloader(ra) try: dl_result = downloader.fetch() - except ClientResponseError as e: + except Exception as e: self.stdout.write( _("Redownload failed from '{}': {}.").format(ra.url, str(e)) ) @@ -141,8 +139,9 @@ def _download_artifact(self, artifact, checksum, file_path): setattr(artifact, checksum, dl_result.artifact_attributes[checksum]) restored = True break - self.stdout.write(_("Deleting unreparable file {}".format(file_path))) - artifact.file.delete(save=False) + if not restored: + self.stdout.write(_("Deleting unrepairable file {}".format(file_path))) + artifact.file.delete(save=False) else: break return restored diff --git a/pulpcore/app/tasks/repository.py b/pulpcore/app/tasks/repository.py index 032cc5380f..6f4b4e2561 100644 --- a/pulpcore/app/tasks/repository.py +++ b/pulpcore/app/tasks/repository.py @@ -4,7 +4,6 @@ import asyncio import hashlib -from aiohttp.client_exceptions import ClientResponseError from asgiref.sync import sync_to_async from django.core.files.storage import default_storage from django.db import transaction @@ -71,7 +70,7 @@ async def _repair_ca(content_artifact, repaired=None): _("Artifact {} is unrepairable - no remote source".format(content_artifact.artifact)) ) log.warning( - "Deleting file for the unreparable artifact {}".format(content_artifact.artifact) + "Deleting file for the unrepairable artifact {}".format(content_artifact.artifact) ) await sync_to_async(content_artifact.artifact.file.delete)(save=False) return False @@ -81,7 +80,7 @@ async def _repair_ca(content_artifact, repaired=None): downloader = detail_remote.get_downloader(remote_artifact) try: dl_result = await downloader.run() - except ClientResponseError as e: + except Exception as e: log.warn(_("Redownload failed from '{}': {}.").format(remote_artifact.url, str(e))) else: if dl_result.artifact_attributes["sha256"] == content_artifact.artifact.sha256: @@ -94,7 +93,7 @@ async def _repair_ca(content_artifact, repaired=None): if repaired is not None: await repaired.aincrement() return True - log.warning("Deleting file for the unreparable artifact {}".format(content_artifact.artifact)) + log.warning("Deleting file for the unrepairable artifact {}".format(content_artifact.artifact)) await sync_to_async(content_artifact.artifact.file.delete)(save=False) return False