From f908301c0fad5ea6722e1baa60dfc70a6712374a 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 1ff82f6542..92f96056dd 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 @@ -126,7 +124,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)) ) @@ -139,8 +137,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 f8834932dc..f949d07d29 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.db import transaction from rest_framework.serializers import ValidationError @@ -68,7 +67,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 @@ -78,7 +77,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: @@ -91,7 +90,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