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

Add domain support #346

Merged
merged 1 commit into from
Feb 14, 2024
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
4 changes: 2 additions & 2 deletions .ci/ansible/Containerfile.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM {{ ci_base | default("ghcr.io/pulp/pulp-ci-centos:" + pulp_container_tag) }}
FROM {{ ci_base | default(pulp_default_container) }}

# Add source directories to container
{% for item in plugins %}
Expand All @@ -11,7 +11,7 @@ ADD ./{{ item.name }} ./{{ item.name }}

RUN pip3 install
{%- if s3_test | default(false) -%}
{{ " " }}git+https://github.com/fabricio-aguiar/botocore.git@fix-100-continue
{{ " " }}git+https://github.com/gerrod3/botocore.git@fix-100-continue
{%- endif -%}
{%- for item in plugins -%}
{{ " " }}{{ item.source }}
Expand Down
2 changes: 1 addition & 1 deletion .github/template_gitref
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2021.08.26-313-g0528507
2021.08.26-315-g8ecb63d
6 changes: 2 additions & 4 deletions .github/workflows/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ cat >> vars/main.yaml << VARSYAML
pulp_env: {}
pulp_settings: null
pulp_scheme: https

pulp_container_tag: "latest"

pulp_default_container: ghcr.io/pulp/pulp-ci-centos:latest
VARSYAML

if [ "$TEST" = "s3" ]; then
Expand All @@ -98,7 +96,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}\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not manually edit this file. We want to update the plugin template configuration (pulp_settings_s3) and then re-generate the workflow scripts (by running /plugin-template --github pulp_ostree).

https://github.com/pulp/plugin_template/?tab=readme-ov-file#add-ci-configuration-to-a-pulp-plugin

https://github.com/pulp/pulpcore/blob/a33612b89f48985448f5315dc5c67aa54f94d196/template_config.yml#L70

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still did not update the template configuration and did not run the plugin-template utility to re-generate the workflow scripts.

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
Loading
Loading