Skip to content

Commit

Permalink
Add Domain support.
Browse files Browse the repository at this point in the history
closes #3008

(based on PR #2920)
Co-authored by: Grant Gainey <ggainey@redhat.com>
  • Loading branch information
pavelpicka authored and ggainey committed Apr 17, 2023
1 parent 2ed7370 commit e54ae55
Show file tree
Hide file tree
Showing 22 changed files with 330 additions and 71 deletions.
1 change: 1 addition & 0 deletions CHANGES/3008.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for Domains.
1 change: 1 addition & 0 deletions pulp_rpm/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ class PulpRpmPluginAppConfig(PulpPluginAppConfig):
label = "rpm"
version = "3.20.0.dev"
python_package_name = "pulp-rpm"
domain_compatible = True
115 changes: 115 additions & 0 deletions pulp_rpm/app/migrations/0049_domains.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Generated by Django 3.2.18 on 2023-04-05 16:39

from django.db import migrations, models
import django.db.models.deletion
import pulpcore.app.util


class Migration(migrations.Migration):

dependencies = [
('core', '0102_add_domain_relations'),
('rpm', '0048_artifacts_dependencies_fix'),
]

operations = [
migrations.AddField(
model_name='distributiontree',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, related_name='rpm_distributiontree', to='core.domain'),
),
migrations.AddField(
model_name='modulemd',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, related_name='rpm_modulemd', to='core.domain'),
),
migrations.AddField(
model_name='modulemddefaults',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, related_name='rpm_modulemddefaults', to='core.domain'),
),
migrations.AddField(
model_name='modulemdobsolete',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, related_name='rpm_modulemdobsolete', to='core.domain'),
),
migrations.AddField(
model_name='package',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, related_name='rpm_package', to='core.domain'),
),
migrations.AddField(
model_name='packagecategory',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, related_name='rpm_packagecategory', to='core.domain'),
),
migrations.AddField(
model_name='packageenvironment',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, related_name='rpm_packageenvironment', to='core.domain'),
),
migrations.AddField(
model_name='packagegroup',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, related_name='rpm_packagegroup', to='core.domain'),
),
migrations.AddField(
model_name='packagelangpacks',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, related_name='rpm_packagelangpacks', to='core.domain'),
),
migrations.AddField(
model_name='repometadatafile',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, related_name='rpm_repometadatafile', to='core.domain'),
),
migrations.AddField(
model_name='updaterecord',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, related_name='rpm_updaterecord', to='core.domain'),
),
migrations.AlterUniqueTogether(
name='distributiontree',
unique_together={('_pulp_domain', 'digest')},
),
migrations.AlterUniqueTogether(
name='modulemd',
unique_together={('_pulp_domain', 'name', 'stream', 'version', 'context', 'arch')},
),
migrations.AlterUniqueTogether(
name='modulemddefaults',
unique_together={('_pulp_domain', 'digest')},
),
migrations.AlterUniqueTogether(
name='modulemdobsolete',
unique_together={('_pulp_domain', 'modified', 'module_name', 'module_stream')},
),
migrations.AlterUniqueTogether(
name='package',
unique_together={('_pulp_domain', 'name', 'epoch', 'version', 'release', 'arch', 'checksum_type', 'pkgId')},
),
migrations.AlterUniqueTogether(
name='packagecategory',
unique_together={('_pulp_domain', 'digest')},
),
migrations.AlterUniqueTogether(
name='packageenvironment',
unique_together={('_pulp_domain', 'digest')},
),
migrations.AlterUniqueTogether(
name='packagegroup',
unique_together={('_pulp_domain', 'digest')},
),
migrations.AlterUniqueTogether(
name='packagelangpacks',
unique_together={('_pulp_domain', 'digest')},
),
migrations.AlterUniqueTogether(
name='repometadatafile',
unique_together={('_pulp_domain', 'data_type', 'checksum', 'relative_path')},
),
migrations.AlterUniqueTogether(
name='updaterecord',
unique_together={('_pulp_domain', 'digest')},
),
]
4 changes: 4 additions & 0 deletions pulp_rpm/app/models/advisory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
BaseModel,
Content,
)
from pulpcore.plugin.util import get_domain_pk

from pulp_rpm.app.constants import (
CR_UPDATE_COLLECTION_ATTRS,
Expand Down Expand Up @@ -102,6 +103,8 @@ class UpdateRecord(Content):
# UpdateCollection or UpdateCollectionPackage.
digest = models.TextField(unique=True)

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

@classmethod
def natural_key_fields(cls):
"""
Expand Down Expand Up @@ -228,6 +231,7 @@ def get_module_list(self):

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
unique_together = ("_pulp_domain", "digest")


class UpdateCollection(BaseModel):
Expand Down
13 changes: 13 additions & 0 deletions pulp_rpm/app/models/comps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.db import models

from pulpcore.plugin.models import Content
from pulpcore.plugin.util import get_domain_pk

from pulp_rpm.app.constants import (
LIBCOMPS_CATEGORY_ATTRS,
Expand Down Expand Up @@ -77,8 +78,11 @@ class PackageGroup(Content):

repo_key_fields = ("id",)

_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", "digest")

@classmethod
def natural_key_fields(cls):
Expand Down Expand Up @@ -234,8 +238,11 @@ class PackageCategory(Content):

repo_key_fields = ("id",)

_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", "digest")

@classmethod
def natural_key_fields(cls):
Expand Down Expand Up @@ -361,8 +368,11 @@ class PackageEnvironment(Content):

repo_key_fields = ("id",)

_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", "digest")

@classmethod
def natural_key_fields(cls):
Expand Down Expand Up @@ -465,8 +475,11 @@ class PackageLangpacks(Content):

digest = models.TextField(unique=True)

_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", "digest")

@classmethod
def natural_key_fields(cls):
Expand Down
5 changes: 4 additions & 1 deletion pulp_rpm/app/models/custom_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db import models

from pulpcore.plugin.models import Content
from pulpcore.plugin.util import get_domain_pk
from pulp_rpm.app.constants import CHECKSUM_CHOICES

log = getLogger(__name__)
Expand Down Expand Up @@ -32,9 +33,11 @@ class RepoMetadataFile(Content):

repo_key_fields = ("data_type",)

_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 = ("data_type", "checksum", "relative_path")
unique_together = ("_pulp_domain", "data_type", "checksum", "relative_path")

@property
def unsupported_metadata_type(self):
Expand Down
5 changes: 4 additions & 1 deletion pulp_rpm/app/models/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ContentArtifact,
Repository,
)
from pulpcore.plugin.util import get_domain_pk

log = getLogger(__name__)

Expand Down Expand Up @@ -94,6 +95,8 @@ class DistributionTree(Content):

digest = models.TextField(null=False)

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

def repositories(self):
"""
Return the subrepos in this DistributionTree.
Expand Down Expand Up @@ -134,7 +137,7 @@ def artifacts(self):

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
unique_together = ("digest",)
unique_together = ("_pulp_domain", "digest")


class Checksum(BaseModel):
Expand Down
12 changes: 10 additions & 2 deletions pulp_rpm/app/models/modulemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db import models

from pulpcore.plugin.models import Content
from pulpcore.plugin.util import get_domain_pk

from pulp_rpm.app.models.package import Package

Expand Down Expand Up @@ -65,9 +66,11 @@ class Modulemd(Content):

snippet = models.TextField()

_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 = ("name", "stream", "version", "context", "arch")
unique_together = ("_pulp_domain", "name", "stream", "version", "context", "arch")


class ModulemdDefaults(Content):
Expand Down Expand Up @@ -98,6 +101,8 @@ class ModulemdDefaults(Content):

repo_key_fields = ("module",)

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

@classmethod
def natural_key_fields(cls):
"""
Expand All @@ -107,6 +112,7 @@ def natural_key_fields(cls):

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
unique_together = ("_pulp_domain", "digest")


class ModulemdObsolete(Content):
Expand Down Expand Up @@ -151,6 +157,8 @@ class ModulemdObsolete(Content):

snippet = models.TextField()

_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 = ("modified", "module_name", "module_stream")
unique_together = ("_pulp_domain", "modified", "module_name", "module_stream")
14 changes: 13 additions & 1 deletion pulp_rpm/app/models/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.db.models.functions import RowNumber

from pulpcore.plugin.models import Content, ContentManager
from pulpcore.plugin.util import get_domain_pk

from pulp_rpm.app.constants import (
CHECKSUM_CHOICES,
Expand Down Expand Up @@ -236,6 +237,8 @@ class Package(Content):
# E.g. glibc-2.26.11.3.2.nosrc.rpm vs glibc-2.26.11.3.2.src.rpm
repo_key_fields = ("name", "epoch", "version", "release", "arch", "location_href")

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

@property
def filename(self):
"""
Expand Down Expand Up @@ -283,7 +286,16 @@ def nevra_short(self):

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
unique_together = ("name", "epoch", "version", "release", "arch", "checksum_type", "pkgId")
unique_together = (
"_pulp_domain",
"name",
"epoch",
"version",
"release",
"arch",
"checksum_type",
"pkgId",
)

class ReadonlyMeta:
readonly = ["evr"]
Expand Down
2 changes: 1 addition & 1 deletion pulp_rpm/app/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def content_handler(self, path):
return
base_url = "{}/".format(
urlpath_sanitize(
settings.CONTENT_ORIGIN, settings.CONTENT_PATH_PREFIX, self.base_path
settings.CONTENT_ORIGIN, settings.CONTENT_PATH_PREFIX, self.pulp_domain.name, self.base_path
)
)
val = textwrap.dedent(
Expand Down
10 changes: 10 additions & 0 deletions pulp_rpm/app/serializers/advisory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ModelSerializer,
NoArtifactContentUploadSerializer,
)
from pulpcore.plugin.util import get_domain

from pulp_rpm.app.advisory import hash_update_record
from pulp_rpm.app.fields import (
Expand Down Expand Up @@ -231,6 +232,15 @@ def validate(self, data):
validated_data = super().validate(update_record_data)
return validated_data

# pulpcore 3.22 feature
# when uploading content second time I don't get error but already existing content
def retrieve(self, validated_data):
content = UpdateRecord.objects.filter(
id=validated_data["id"],
pulp_domain=get_domain(),
)
return content.first()

class Meta:
fields = NoArtifactContentUploadSerializer.Meta.fields + (
"id",
Expand Down
8 changes: 8 additions & 0 deletions pulp_rpm/app/serializers/comps.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,13 @@ class CompsXmlSerializer(serializers.Serializer):
write_only=True,
)

# TODO: determine what comps is uploaded
# def retrieve(self, validated_data):
# content = UpdateRecord.objects.filter(
# digest=validated_data["id"],
# pulp_domain=get_domain(),
# )
# return content.first()

class Meta:
fields = ("file", "repository", "replace")
Loading

0 comments on commit e54ae55

Please sign in to comment.