Skip to content

Commit

Permalink
Add domain support
Browse files Browse the repository at this point in the history
closes: #321
  • Loading branch information
git-hyagi committed Feb 8, 2024
1 parent ea22222 commit d00911c
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ if [ "$TEST" = "s3" ]; then
sed -i -e '$a s3_test: true\
minio_access_key: "'$MINIO_ACCESS_KEY'"\
minio_secret_key: "'$MINIO_SECRET_KEY'"\
pulp_scenario_settings: null\
pulp_scenario_settings: {"domain_enabled": true}\
pulp_scenario_env: {}\
' vars/main.yaml
export PULP_API_ROOT="/rerouted/djnd/"
Expand Down
1 change: 1 addition & 0 deletions CHANGES/321.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_ostree/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ class PulpOstreePluginAppConfig(PulpPluginAppConfig):
label = "ostree"
version = "2.3.0.dev"
python_package_name = "pulp-ostree"
domain_compatible = True
94 changes: 94 additions & 0 deletions pulp_ostree/app/migrations/0008_add_domain_support.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Generated by Django 4.2.9 on 2024-02-06 10:31

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


class Migration(migrations.Migration):

dependencies = [
('core', '0116_alter_remoteartifact_md5_alter_remoteartifact_sha1_and_more'),
('ostree', '0007_add_model_permissions'),
]

operations = [
migrations.AlterUniqueTogether(
name='ostreecommit',
unique_together=set(),
),
migrations.AlterUniqueTogether(
name='ostreeconfig',
unique_together=set(),
),
migrations.AlterUniqueTogether(
name='ostreecontent',
unique_together=set(),
),
migrations.AlterUniqueTogether(
name='ostreeobject',
unique_together=set(),
),
migrations.AlterUniqueTogether(
name='ostreeref',
unique_together=set(),
),
migrations.AlterUniqueTogether(
name='ostreesummary',
unique_together=set(),
),
migrations.AddField(
model_name='ostreecommit',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, to='core.domain'),
),
migrations.AddField(
model_name='ostreeconfig',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, to='core.domain'),
),
migrations.AddField(
model_name='ostreecontent',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, to='core.domain'),
),
migrations.AddField(
model_name='ostreeobject',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, to='core.domain'),
),
migrations.AddField(
model_name='ostreeref',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, to='core.domain'),
),
migrations.AddField(
model_name='ostreesummary',
name='_pulp_domain',
field=models.ForeignKey(default=pulpcore.app.util.get_domain_pk, on_delete=django.db.models.deletion.PROTECT, to='core.domain'),
),
migrations.AlterUniqueTogether(
name='ostreecommit',
unique_together={('checksum', 'relative_path', '_pulp_domain')},
),
migrations.AlterUniqueTogether(
name='ostreeconfig',
unique_together={('sha256', 'relative_path', '_pulp_domain')},
),
migrations.AlterUniqueTogether(
name='ostreecontent',
unique_together={('relative_path', 'digest', '_pulp_domain')},
),
migrations.AlterUniqueTogether(
name='ostreeobject',
unique_together={('checksum', 'relative_path', '_pulp_domain')},
),
migrations.AlterUniqueTogether(
name='ostreeref',
unique_together={('name', 'commit', 'relative_path', '_pulp_domain')},
),
migrations.AlterUniqueTogether(
name='ostreesummary',
unique_together={('sha256', 'relative_path', '_pulp_domain')},
),
]
20 changes: 14 additions & 6 deletions pulp_ostree/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
)
from pulpcore.plugin.repo_version_utils import remove_duplicates, validate_duplicate_content

from pulpcore.plugin.util import get_domain_pk

logger = getLogger(__name__)


Expand All @@ -32,28 +34,30 @@ class OstreeObject(Content):

TYPE = "object"

_pulp_domain = models.ForeignKey("core.Domain", default=get_domain_pk, on_delete=models.PROTECT)
typ = models.IntegerField(choices=OstreeObjectType.choices)
checksum = models.CharField(max_length=64, db_index=True)
relative_path = models.TextField(null=False)

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
unique_together = [["checksum", "relative_path"]]
unique_together = [["checksum", "relative_path", "_pulp_domain"]]


class OstreeCommit(Content):
"""A content model for an OSTree commit."""

TYPE = "commit"

_pulp_domain = models.ForeignKey("core.Domain", default=get_domain_pk, on_delete=models.PROTECT)
parent_commit = models.ForeignKey("self", null=True, blank=True, on_delete=models.CASCADE)
checksum = models.CharField(max_length=64, db_index=True)
relative_path = models.TextField(null=False)
objs = models.ManyToManyField(OstreeObject, through="OstreeCommitObject")

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
unique_together = [["checksum", "relative_path"]]
unique_together = [["checksum", "relative_path", "_pulp_domain"]]


class OstreeRef(Content):
Expand All @@ -62,6 +66,7 @@ class OstreeRef(Content):
TYPE = "refs"
repo_key_fields = ("name",)

_pulp_domain = models.ForeignKey("core.Domain", default=get_domain_pk, on_delete=models.PROTECT)
commit = models.ForeignKey(
OstreeCommit, related_name="refs_commit", null=True, on_delete=models.CASCADE
)
Expand All @@ -70,7 +75,7 @@ class OstreeRef(Content):

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
unique_together = [["name", "commit", "relative_path"]]
unique_together = [["name", "commit", "relative_path", "_pulp_domain"]]


class OstreeCommitObject(models.Model):
Expand All @@ -88,12 +93,13 @@ class OstreeContent(Content):

repo_key_fields = ("relative_path",)

_pulp_domain = models.ForeignKey("core.Domain", default=get_domain_pk, on_delete=models.PROTECT)
relative_path = models.TextField(null=False)
digest = models.CharField(max_length=64, null=False)

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


class OstreeConfig(Content):
Expand All @@ -102,12 +108,13 @@ class OstreeConfig(Content):
TYPE = "config"
repo_key_fields = ("relative_path",)

_pulp_domain = models.ForeignKey("core.Domain", default=get_domain_pk, on_delete=models.PROTECT)
sha256 = models.CharField(max_length=64, db_index=True)
relative_path = models.TextField(null=False)

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
unique_together = [["sha256", "relative_path"]]
unique_together = [["sha256", "relative_path", "_pulp_domain"]]


class OstreeSummary(Content):
Expand All @@ -116,12 +123,13 @@ class OstreeSummary(Content):
TYPE = "summary"
repo_key_fields = ("relative_path",)

_pulp_domain = models.ForeignKey("core.Domain", default=get_domain_pk, on_delete=models.PROTECT)
sha256 = models.CharField(max_length=64, db_index=True)
relative_path = models.TextField(null=False)

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
unique_together = [["sha256", "relative_path"]]
unique_together = [["sha256", "relative_path", "_pulp_domain"]]


class OstreeRemote(Remote, AutoAddObjPermsMixin):
Expand Down
20 changes: 12 additions & 8 deletions pulp_ostree/app/tasks/importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def parse_ref(self, name, ref_commit_checksum, has_referenced_parent=False
parent_checksum = OSTree.commit_get_parent(ref_commit)
if not parent_checksum:
# there are not any parent commits, return and continue parsing the next ref
commit = OstreeCommit(checksum=ref_commit_checksum)
commit = OstreeCommit(checksum=ref_commit_checksum, _pulp_domain=self.domain)
commit_dc = self.create_dc(relative_path, commit)
await self.put(commit_dc)

Expand All @@ -103,7 +103,7 @@ async def parse_ref(self, name, ref_commit_checksum, has_referenced_parent=False
return

checksum = ref_commit_checksum
ref_commit = OstreeCommit(checksum=checksum)
ref_commit = OstreeCommit(checksum=checksum, _pulp_domain=self.domain)
ref_commit_dc = self.create_dc(relative_path, ref_commit)
self.commit_dcs.append(ref_commit_dc)

Expand All @@ -118,7 +118,9 @@ async def parse_ref(self, name, ref_commit_checksum, has_referenced_parent=False
return parent_checksum, ref_commit_dc
else:
try:
parent_commit = await OstreeCommit.objects.aget(checksum=parent_checksum)
parent_commit = await OstreeCommit.objects.aget(
checksum=parent_checksum, _pulp_domain=self.domain
)
except OstreeCommit.DoesNotExist:
raise ValueError(
gettext("The parent commit '{}' could not be loaded").format(
Expand All @@ -138,7 +140,7 @@ async def load_next_commits(self, parent_commit, checksum, has_referenced_parent
parent_checksum = OSTree.commit_get_parent(parent_commit)

while parent_checksum:
commit = OstreeCommit(checksum=checksum)
commit = OstreeCommit(checksum=checksum, _pulp_domain=self.domain)
commit_dc = self.create_dc(relative_path, commit)
self.commit_dcs.append(commit_dc)

Expand All @@ -161,7 +163,7 @@ async def load_next_commits(self, parent_commit, checksum, has_referenced_parent
)
parent_checksum = OSTree.commit_get_parent(parent_commit)

commit = OstreeCommit(checksum=checksum)
commit = OstreeCommit(checksum=checksum, _pulp_domain=self.domain)
commit_dc = self.create_dc(relative_path, commit)
self.commit_dcs.append(commit_dc)

Expand Down Expand Up @@ -263,7 +265,9 @@ async def run(self):
parent_commit = None

try:
parent_commit = await OstreeCommit.objects.aget(checksum=parent_checksum)
parent_commit = await OstreeCommit.objects.aget(
checksum=parent_checksum, _pulp_domain=self.domain
)
except OstreeCommit.DoesNotExist:
pass
else:
Expand Down Expand Up @@ -332,7 +336,7 @@ async def run(self):
num_of_parsed_commits = len(self.commit_dcs)

commit = await OstreeCommit.objects.select_related("parent_commit").aget(
checksum=ref_commit_checksum
checksum=ref_commit_checksum, _pulp_domain=self.domain
)
parent_commit = commit.parent_commit
if parent_commit and num_of_parsed_commits == 1:
Expand Down Expand Up @@ -364,7 +368,7 @@ async def run(self):
ref_file = await ref._artifacts.aget()
copy_to_local_storage(ref_file.file, file_path)

commit = await OstreeCommit.objects.aget(refs_commit=ref)
commit = await OstreeCommit.objects.aget(refs_commit=ref, _pulp_domain=self.domain)
await self.copy_from_storage_to_tmp(commit, OstreeObject.objects.none())

self.repo.regenerate_summary()
Expand Down
26 changes: 17 additions & 9 deletions pulp_ostree/app/tasks/modifying.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db.models import Q

from pulpcore.plugin.models import Repository, RepositoryVersion, Content
from pulpcore.plugin.util import get_domain

from pulp_ostree.app.models import (
OstreeCommit,
Expand Down Expand Up @@ -69,16 +70,20 @@ def modify_content(repository_pk, add_content_units, remove_content_units, base_

def get_content_data_by_model(model_type, add_content_units, remove_content_units):
"""Return an object that holds a reference to querysets of added and removed content."""
to_add = model_type.objects.filter(pk__in=add_content_units)
to_remove = model_type.objects.filter(pk__in=remove_content_units)
curr_domain = get_domain()
to_add = model_type.objects.filter(pk__in=add_content_units, _pulp_domain=curr_domain)
to_remove = model_type.objects.filter(pk__in=remove_content_units, _pulp_domain=curr_domain)
return ModifyContentData(to_add, to_remove)


def recursively_get_add_content(commit_data, ref_data):
"""Get all the content required for addition that the passed objects reference."""
curr_domain = get_domain()
ref_commits_pks = ref_data.values_list("commit", flat=True)

commit_data = commit_data.union(OstreeCommit.objects.filter(pk__in=ref_commits_pks))
commit_data = commit_data.union(
OstreeCommit.objects.filter(pk__in=ref_commits_pks, _pulp_domain=curr_domain)
)
objects_pks = commit_data.values_list("objs", flat=True)
commit_data_pks = commit_data.values_list("pk", flat=True)

Expand All @@ -89,9 +94,12 @@ def recursively_get_add_content(commit_data, ref_data):

def recursively_get_remove_content(commit_data, ref_data, latest_content):
"""Get all the content required for removal that the passed objects reference."""
curr_domain = get_domain()
ref_commits_pks = ref_data.values_list("commit", flat=True)

commit_data = commit_data.union(OstreeCommit.objects.filter(pk__in=ref_commits_pks))
commit_data = commit_data.union(
OstreeCommit.objects.filter(pk__in=ref_commits_pks, _pulp_domain=curr_domain)
)
commit_data_pks = commit_data.values_list("pk", flat=True)

# we do not want to get removed objects that are referenced by other commits in the repository
Expand All @@ -100,17 +108,17 @@ def recursively_get_remove_content(commit_data, ref_data, latest_content):
).values_list("pk", flat=True)
if remaining_commits_pks:
remaining_objects_pks = OstreeCommit.objects.filter(
~Q(pk__in=remaining_commits_pks)
~Q(pk__in=remaining_commits_pks), _pulp_domain=curr_domain
).values_list("objs", flat=True)
objects_pks = (
OstreeCommit.objects.filter(pk__in=commit_data_pks)
OstreeCommit.objects.filter(pk__in=commit_data_pks, _pulp_domain=curr_domain)
.values_list("objs", flat=True)
.difference(remaining_objects_pks)
)
else:
objects_pks = OstreeCommit.objects.filter(pk__in=commit_data_pks).values_list(
"objs", flat=True
)
objects_pks = OstreeCommit.objects.filter(
pk__in=commit_data_pks, _pulp_domain=curr_domain
).values_list("objs", flat=True)

return Content.objects.filter(
Q(pk__in=commit_data_pks) | Q(pk__in=ref_data) | Q(pk__in=objects_pks)
Expand Down
10 changes: 7 additions & 3 deletions pulp_ostree/app/tasks/stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ async def submit_related_objects(self, commit_dc):
if obj_checksum == commit_dc.content.checksum:
continue

obj = OstreeObject(typ=obj_type, checksum=obj_checksum)
obj = OstreeObject(typ=obj_type, checksum=obj_checksum, _pulp_domain=self.domain)
obj_relative_path = get_checksum_filepath(obj_checksum, obj_type)
object_dc = self.create_object_dc_func(obj_relative_path, obj)
object_dc.extra_data["commit_relation"] = await commit_dc.resolution()
await self.put(object_dc)

def init_ref_object(self, name, relative_path, commit_dc):
"""Initialize a DeclarativeContent object for a ref object."""
ref = OstreeRef(name=name)
ref = OstreeRef(name=name, _pulp_domain=self.domain)
ref_dc = self.create_dc(relative_path, ref)
ref_dc.extra_data["ref_commit"] = commit_dc
self.refs_dcs.append(ref_dc)
Expand Down Expand Up @@ -120,7 +120,11 @@ async def compute_static_delta(self, ref_commit_checksum, parent_checksum=None):
full_path = os.path.join(dirpath, filename)
relative_path = os.path.relpath(full_path, self.repo_path)

content = OstreeContent(relative_path=relative_path, digest=compute_hash(full_path))
content = OstreeContent(
relative_path=relative_path,
digest=compute_hash(full_path),
_pulp_domain=self.domain,
)
content_dc = self.create_dc(relative_path, content)
await self.put(content_dc)

Expand Down
Loading

0 comments on commit d00911c

Please sign in to comment.