Skip to content

Commit

Permalink
Allow two modules with same NSVCA but different snippet content.
Browse files Browse the repository at this point in the history
closes pulp#3241

It no longer holds true to rely on NSVCA module's uniqueness, add the
hash of the document snippet to it.
  • Loading branch information
ipanova committed Sep 4, 2023
1 parent 748b3dd commit b92efb8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES/3241.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adjust modules uniqueness to allow two modules with same NSVCA but different snippet content.
51 changes: 51 additions & 0 deletions pulp_rpm/app/migrations/0052_modulemd_digest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Generated by Django 4.2.4 on 2023-09-04 14:06

from django.db import migrations, models
import hashlib


def add_snippet_hash(apps, schema_editor):
"""Calculate and add digest hash of the snippet."""

Modulemd = apps.get_model("rpm", "Modulemd")
modules_to_update = []

for mmd in Modulemd.objects.all().only("snippet").iterator():
digest = hashlib.sha256(mmd.snippet.encode()).hexdigest()
modules_to_update.append(mmd)
Modulemd.objects.bulk_update(modules_to_update, fields=["digest"])


class Migration(migrations.Migration):

dependencies = [
("rpm", "0051_alter_distributiontree_unique_together_and_more"),
]

operations = [
migrations.AddField(
model_name="modulemd",
name="digest",
field=models.TextField(default=""),
),
migrations.RunPython(
code=add_snippet_hash,
reverse_code=migrations.RunPython.noop,
elidable=True,
),
migrations.AlterUniqueTogether(
name="modulemd",
unique_together=set(),
),
migrations.AlterField(
model_name="modulemd",
name="digest",
field=models.TextField(),
),
migrations.AlterUniqueTogether(
name="modulemd",
unique_together={
("_pulp_domain", "name", "stream", "version", "context", "arch", "digest")
},
),
]
13 changes: 9 additions & 4 deletions pulp_rpm/app/models/modulemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ class Modulemd(Content):
packages (Text):
List of Packages connected to this modulemd.
snippet (Text):
A string to hold modulemd-obsolete snippet
A string to hold modulemd snippet
digest (Text):
Modulemd snippet digest
"""

TYPE = "modulemd"
Expand All @@ -63,14 +66,16 @@ class Modulemd(Content):
packages = models.ManyToManyField(Package)
profiles = models.JSONField(default=dict)
description = models.TextField()
digest = models.TextField()

snippet = models.TextField()
repo_key_fields = ("name", "stream", "version", "context", "arch")

_pulp_domain = models.ForeignKey("core.Domain", default=get_domain_pk, on_delete=models.PROTECT)

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
unique_together = ("_pulp_domain", "name", "stream", "version", "context", "arch")
unique_together = ("_pulp_domain", "name", "stream", "version", "context", "arch", "digest")


class ModulemdDefaults(Content):
Expand All @@ -85,9 +90,9 @@ class ModulemdDefaults(Content):
profiles (Json):
Default profiles for modulemd streams.
digest (Text):
Modulemd digest
Modulemd defaults snippet digest
snippet (Text):
A string to hold modulemd-obsolete snippet
A string to hold modulemd-defaults snippet
"""

TYPE = "modulemd_defaults"
Expand Down
1 change: 1 addition & 0 deletions pulp_rpm/app/modulemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def create_modulemd(modulemd, snippet):

new_module[PULP_MODULE_ATTR.PROFILES] = profiles
new_module["snippet"] = snippet
new_module[PULP_MODULE_ATTR.DIGEST] = hashlib.sha256(snippet.encode()).hexdigest()

return new_module

Expand Down

0 comments on commit b92efb8

Please sign in to comment.