Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected PulpImport/Export handling of sub-content. #2193

Merged
merged 1 commit into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

ggainey marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 4 additions & 4 deletions pulpcore/app/importexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,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 @@ -164,6 +160,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.
mdellweg marked this conversation as resolved.
Show resolved Hide resolved
"""

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