Skip to content

Commit

Permalink
Corrected PulpImport/Export handling of sub-content.
Browse files Browse the repository at this point in the history
fixes #2192.
[nocoverage]

(cherry picked from commit 849d410)
  • Loading branch information
ggainey authored and patchback[bot] committed Feb 16, 2022
1 parent 3debed4 commit c5daa43
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGES/2192.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fixed import/export of repositories with sub-content.

An example would be the sub-repositories in pulp_rpm
DistributionTrees.

8 changes: 4 additions & 4 deletions pulpcore/app/importexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ def _combine_content_mappings(map1, map2):
)
)

# Export the connection between content and artifacts
resource = ContentArtifactResource(repository_version)
_write_export(export.tarfile, resource, dest_dir)

# content mapping is used by repo versions with subrepos (eg distribution tree repos)
content_mapping = {}

Expand All @@ -138,6 +134,10 @@ def _combine_content_mappings(map1, map2):
content_mapping, resource.content_mapping
)

# Export the connection between content and artifacts
resource = ContentArtifactResource(repository_version, content_mapping)
_write_export(export.tarfile, resource, dest_dir)

msg = (
f"Exporting content for {plugin_name} "
f"repository-version {repository_version.repository.name}/{repository_version.number}"
Expand Down
19 changes: 16 additions & 3 deletions pulpcore/app/modelresource.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,19 @@ class ContentArtifactResource(QueryModelResource):
ContentArtifact is different from other import-export entities because it has no 'natural key'
other than a pulp_id, which aren't shared across instances. We do some magic to link up
ContentArtifacts to their matching (already-imported) Content.
Some plugin-models have sub-repositories. We take advantage of the content-mapping
machinery to account for those contentartifacts as well.
"""

artifact = fields.Field(
column_name="artifact", attribute="artifact", widget=ForeignKeyWidget(Artifact, "sha256")
)

def __init__(self, repo_version=None, content_mapping=None):
self.content_mapping = content_mapping
super().__init__(repo_version)

def before_import_row(self, row, **kwargs):
"""
Fixes the content-ptr of an incoming content-artifact row at import time.
Expand All @@ -92,9 +99,15 @@ def before_import_row(self, row, **kwargs):
row["content"] = str(linked_content.pulp_id)

def set_up_queryset(self):
return ContentArtifact.objects.filter(content__in=self.repo_version.content).order_by(
"content", "relative_path"
)
vers_content = ContentArtifact.objects.filter(content__in=self.repo_version.content)
if self.content_mapping:
all_content = []
for content_ids in self.content_mapping.values():
all_content.extend(content_ids)
vers_content = vers_content.union(
ContentArtifact.objects.filter(content__in=all_content)
)
return vers_content.order_by("content", "relative_path")

class Meta:
model = ContentArtifact
Expand Down

0 comments on commit c5daa43

Please sign in to comment.