Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Removed no-longer-needed pre_migration codepath.
Browse files Browse the repository at this point in the history
Removes part of the changes for #7280.

fixes #8166
  • Loading branch information
ggainey committed Feb 16, 2021
1 parent 2eaf2ce commit c7d0e2d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 56 deletions.
1 change: 1 addition & 0 deletions CHANGES/8166.bugfix
@@ -0,0 +1 @@
Fixed an edge-case failure in erratum-migration when doing repeated migrations.
56 changes: 0 additions & 56 deletions pulp_2to3_migration/app/pre_migration.py
@@ -1,7 +1,6 @@
import logging

from collections import namedtuple
from datetime import datetime

from django.db import transaction
from django.db.models import Max, Q
Expand Down Expand Up @@ -222,61 +221,6 @@ def pre_migrate_content_type(content_model, mutable_type, lazy_type, premigrate_
pulp2content.clear()
existing_count = 0

# If a content type needs to be associated per-repo, we need to make sure that the
# existing content hasn't been associated with a new repo since our last migration,
# and if so, we need to go back and create a Pulp2Content for these new relations.
if set_pulp2_repo and last_updated:
# last_updated is a unix timestamp that sometimes defaults to 0 (if there is no
# existing content). If there's no existing content we can just skip this entire
# process; otherwise we need to convert it to use in our Django query.
last_updated = datetime.utcfromtimestamp(last_updated)

# This content requires to set pulp 2 repo. E.g. for errata, because 1 pulp2
# content unit is converted into N pulp3 content units and repo_id is the only
# way to have unique records for those.
content_relations = Pulp2RepoContent.objects.filter(
pulp2_content_type_id=record._content_type_id,
pulp2_repository__not_in_plan=False,
pulp2_created__gte=last_updated
).select_related(
'pulp2_repository'
).only(
'pulp2_repository'
)

mongo_content_qs = content_model.pulp2.objects(
id__in=content_relations.values_list('pulp2_unit_id', flat=True))
pulp2_content_by_id = {
record.id: record for record in mongo_content_qs.only(*mongo_fields).no_cache()
}

for relation in content_relations:
record = pulp2_content_by_id[relation.pulp2_unit_id]
downloaded = record.downloaded if hasattr(record, 'downloaded') else False
item = Pulp2Content(
pulp2_id=record.id,
pulp2_content_type_id=record._content_type_id,
pulp2_last_updated=record._last_updated,
pulp2_storage_path=record._storage_path,
downloaded=downloaded,
pulp2_repo=relation.pulp2_repository
)
_logger.debug(
'Add content item to the list to migrate: {item}'.format(item=item))
pulp2content.append(item)
pulp2content_pb.total += 1
pulp2detail_pb.total += 1

pulp2content_batch = Pulp2Content.objects.bulk_create(pulp2content,
ignore_conflicts=True)
pulp2content_pb.done += len(pulp2content_batch)
pulp2content_pb.save()

content_model.pulp_2to3_detail.pre_migrate_content_detail(pulp2content_batch)

pulp2detail_pb.done += len(pulp2content_batch)
pulp2detail_pb.save()

pulp2content_pb.save()
pulp2detail_pb.save()

Expand Down

0 comments on commit c7d0e2d

Please sign in to comment.