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

Taught advisory-upload to handle advisory-conflicts better. #1973

Merged
merged 1 commit into from Apr 27, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/7282.bugfix
@@ -0,0 +1 @@
Fixed advisory upload-and-merge of already-existing advisories.
20 changes: 16 additions & 4 deletions pulp_rpm/app/advisory.py
Expand Up @@ -268,12 +268,24 @@ def merge_advisories(previous_advisory, added_advisory):
# First thing to do is ensure collection-name-uniqueness
# in the newly-merged advisory.

# If we've seen a collection-name already, create a new name
# by appending "_<suffix>" and rename the collection before
# merging.
# NOTE: keeping the collections separate is DELIBERATE:
ggainey marked this conversation as resolved.
Show resolved Hide resolved
# 1) after the fact, it's clear that an advisory merge happened, and that one set of
# packages comes from one place, one from a different one
# 2) package-grouping can be *relevant* (e.g. base-rpms vs debuginfo-rpms)
# 3) package-grouping can be *required* (e.g., module-collections must be kept separate)

# dictionary of collection-name:first-unused-suffix pairs
names_seen = {}
# if a collection has no name, we assign it the name "collection" and uniquify-it from there
names_seen = {"collection": 0}
for collection in chain(previous_collections, added_collections):
# If we've seen a collection-name already, create a new name
# by appending "_<suffix>" and rename the collection before
# merging

# no-name? When merging, ILLEGAL! Give it a name
ggainey marked this conversation as resolved.
Show resolved Hide resolved
if not collection.name:
collection.name = "collection"

if collection.name in names_seen.keys():
orig_name = collection.name
new_name = f"{orig_name}_{names_seen[orig_name]}"
Expand Down
11 changes: 11 additions & 0 deletions pulp_rpm/app/serializers/advisory.py
Expand Up @@ -119,6 +119,10 @@ def create(self, validated_data):
"""
references = validated_data.pop("references", [])
pkglist = validated_data.pop("pkglist", [])

# detach any specified repository; attach once the advisory exists
repository = validated_data.pop("repository", None)
ggainey marked this conversation as resolved.
Show resolved Hide resolved

update_collection_packages_to_save = list()
update_references_to_save = list()
try:
Expand Down Expand Up @@ -168,6 +172,13 @@ def create(self, validated_data):
update_record.digest = hash_update_record(cr_update_record)
update_record.save()

# create new repo version with uploaded advisory
if repository:
repository.cast()
content_to_add = self.Meta.model.objects.filter(pk=update_record.pk)
with repository.new_version() as new_version:
new_version.add_content(content_to_add)

return update_record

def validate(self, data):
Expand Down