|
| 1 | +From 298018f116419e3a944f663a7d7fc89e426d0d1a Mon Sep 17 00:00:00 2001 |
| 2 | +From: Yasen <yasen@trahnov.eu> |
| 3 | +Date: Tue, 26 May 2026 13:18:58 +0200 |
| 4 | +Subject: [PATCH] fix migrate |
| 5 | + |
| 6 | +--- |
| 7 | + pulpcore/app/tasks/migrate.py | 36 +++++++++++++++++++++++------------ |
| 8 | + 1 file changed, 24 insertions(+), 12 deletions(-) |
| 9 | + |
| 10 | +diff --git a/pulpcore/app/tasks/migrate.py b/pulpcore/app/tasks/migrate.py |
| 11 | +index dd15adc1e..789c857d1 100644 |
| 12 | +--- a/pulpcore/app/tasks/migrate.py |
| 13 | ++++ b/pulpcore/app/tasks/migrate.py |
| 14 | +@@ -2,7 +2,6 @@ import logging |
| 15 | + from gettext import gettext as _ |
| 16 | + |
| 17 | + from django.utils.timezone import now |
| 18 | +-from rest_framework.serializers import ValidationError |
| 19 | + |
| 20 | + from pulpcore.app.models import Artifact, ProgressReport, storage |
| 21 | + from pulpcore.app.serializers import DomainBackendMigratorSerializer |
| 22 | +@@ -25,24 +24,30 @@ def migrate_backend(data): |
| 23 | + artifacts = Artifact.objects.filter(pulp_domain=domain) |
| 24 | + date = now() |
| 25 | + |
| 26 | ++ skipped = [] |
| 27 | + with ProgressReport( |
| 28 | + message=_("Migrating Artifacts"), code="migrate", total=artifacts.count() |
| 29 | + ) as pb: |
| 30 | + while True: |
| 31 | +- for digest in pb.iter(artifacts.values_list("sha256", flat=True)): |
| 32 | +- filename = storage.get_artifact_path(digest) |
| 33 | +- if not new_storage.exists(filename): |
| 34 | ++ for artifact in pb.iter(artifacts.iterator()): |
| 35 | ++ old_name = artifact.file.name |
| 36 | ++ new_name = storage.get_artifact_path(artifact.sha256) |
| 37 | ++ if not new_storage.exists(new_name): |
| 38 | + try: |
| 39 | +- file = old_storage.open(filename) |
| 40 | +- except FileNotFoundError: |
| 41 | +- raise ValidationError( |
| 42 | +- _( |
| 43 | +- "Found missing file for artifact(sha256={}). Please run the repair " |
| 44 | +- "task or delete the offending artifact." |
| 45 | +- ).format(digest) |
| 46 | ++ file = old_storage.open(old_name) |
| 47 | ++ except Exception as e: |
| 48 | ++ _logger.warning( |
| 49 | ++ "Skipping artifact(sha256=%s): unable to read from old storage: %s", |
| 50 | ++ artifact.sha256, |
| 51 | ++ e, |
| 52 | + ) |
| 53 | +- new_storage.save(filename, file) |
| 54 | ++ skipped.append(artifact.sha256) |
| 55 | ++ continue |
| 56 | ++ new_storage.save(new_name, file) |
| 57 | + file.close() |
| 58 | ++ if old_name != new_name: |
| 59 | ++ artifact.file.name = new_name |
| 60 | ++ artifact.save(update_fields=["file"]) |
| 61 | + # Handle new artifacts saved by the content app |
| 62 | + artifacts = Artifact.objects.filter(pulp_domain=domain, pulp_created__gte=date) |
| 63 | + if count := artifacts.count(): |
| 64 | +@@ -52,6 +57,13 @@ def migrate_backend(data): |
| 65 | + continue |
| 66 | + break |
| 67 | + |
| 68 | ++ if skipped: |
| 69 | ++ _logger.warning( |
| 70 | ++ "Migration completed with %d skipped artifacts (missing from old storage): %s", |
| 71 | ++ len(skipped), |
| 72 | ++ ", ".join(skipped), |
| 73 | ++ ) |
| 74 | ++ |
| 75 | + # Update the current domain to the new storage backend settings |
| 76 | + msg = _("Update Domain({domain})'s Backend Settings").format(domain=domain.name) |
| 77 | + with ProgressReport(message=msg, code="update", total=1) as pb: |
| 78 | +-- |
| 79 | +2.53.0 |
| 80 | + |
0 commit comments