Skip to content
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
1 change: 1 addition & 0 deletions CHANGES/6712.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated API to allow adding custom metadata to exports
29 changes: 29 additions & 0 deletions pulp_file/tests/functional/api/test_pulp_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,32 @@ def test_cross_domain_exporter(
assert msgs["start_versions"] == [
"Requested RepositoryVersions must belong to the Repositories named by the Exporter!"
]


@pytest.mark.parallel
def test_export_with_meta(pulpcore_bindings, pulp_export_factory, full_pulp_exporter):
exporter = full_pulp_exporter
user_meta = {
"initiator": "ci",
"purpose": "export",
"checksum_type": "md5", # pulp should override only in TOC JSON
}

export = pulp_export_factory(exporter, {"meta": user_meta})

# toc_info contains exactly user meta (unmodified)
meta_info = export.toc_info.get("meta", {})
assert meta_info == user_meta

# Validate TOC JSON file content
toc_file_path = export.toc_info.get("file")
assert toc_file_path and isinstance(toc_file_path, str)

with open(toc_file_path, "r") as f:
toc_data = json.load(f)

meta_json = toc_data.get("meta", {})
assert meta_json.get("initiator") == "ci"
assert meta_json.get("purpose") == "export"
# overridden field check
assert meta_json.get("checksum_type") == "crc32"
9 changes: 8 additions & 1 deletion pulpcore/app/serializers/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class PulpExportSerializer(ExportSerializer):
)

toc_info = fields.JSONDictField(
help_text=_("Filename and sha256-checksum of table-of-contents for this export"),
help_text=_("Filename, sha256-checksum and meta of table-of-contents for this export"),
read_only=True,
)

Expand Down Expand Up @@ -166,6 +166,12 @@ class PulpExportSerializer(ExportSerializer):
write_only=True,
)

meta = serializers.DictField(
help_text=_("Dictionary of meta information about the export. Stored in the TOC JSON."),
required=False,
write_only=True,
)

def _validate_versions_to_repos(self, the_versions):
"""
If specifying repo-versions explicitly, must provide a version for each exporter-repository
Expand Down Expand Up @@ -248,6 +254,7 @@ class Meta:
"output_file_info",
"start_versions",
"toc_info",
"meta",
)


Expand Down
5 changes: 4 additions & 1 deletion pulpcore/app/tasks/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ def pulp_export(exporter_pk, params):
the_export.validated_start_versions = serializer.validated_data.get("start_versions", None)
the_export.validated_chunk_size = serializer.validated_data.get("chunk_size", None)

meta = serializer.validated_data.get("meta", {})

hasher = Crc32Hasher
checksum_type = "crc32"
try:
Expand Down Expand Up @@ -450,6 +452,7 @@ def pulp_export(exporter_pk, params):
with open(output_file_info_path, "w") as outfile:
table_of_contents = {
"meta": {
**meta,
"checksum_type": checksum_type,
},
"files": {},
Expand All @@ -466,7 +469,7 @@ def pulp_export(exporter_pk, params):
# store toc info
toc_hash = compute_file_hash(output_file_info_path)
the_export.output_file_info[output_file_info_path] = toc_hash
the_export.toc_info = {"file": output_file_info_path, "sha256": toc_hash}
the_export.toc_info = {"file": output_file_info_path, "sha256": toc_hash, "meta": meta}
finally:
# whatever may have happened, make sure we save the export
the_export.save()
Expand Down