Skip to content
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
1 change: 1 addition & 0 deletions CHANGES/360.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replaced some uses of deprecated pulpcore functionality.
77 changes: 77 additions & 0 deletions pulp_python/app/migrations/0004_DATA_swap_distribution_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Generated by Django 2.2.19 on 2021-03-19 17:42

from django.db import migrations, models, transaction
import django.db.models.deletion


def migrate_data_from_old_model_to_new_model_up(apps, schema_editor):
""" Move objects from PythonDistribution to NewPythonDistribution."""
PythonDistribution = apps.get_model('python', 'PythonDistribution')
NewPythonDistribution = apps.get_model('python', 'NewPythonDistribution')
for python_distribution in PythonDistribution.objects.all():
with transaction.atomic():
NewPythonDistribution(
pulp_id=python_distribution.pulp_id,
pulp_created=python_distribution.pulp_created,
pulp_last_updated=python_distribution.pulp_last_updated,
pulp_type=python_distribution.pulp_type,
name=python_distribution.name,
base_path=python_distribution.base_path,
content_guard=python_distribution.content_guard,
remote=python_distribution.remote,
publication=python_distribution.publication
).save()
python_distribution.delete()


def migrate_data_from_old_model_to_new_model_down(apps, schema_editor):
""" Move objects from NewPythonDistribution to PythonDistribution."""
PythonDistribution = apps.get_model('python', 'PythonDistribution')
NewPythonDistribution = apps.get_model('python', 'NewPythonDistribution')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When migrating down, the operations are done in reverse order correct? So the 3.12 PythonDistribution would have been renamed back to NewPythonDistribution?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's my understanding

for python_distribution in NewPythonDistribution.objects.all():
with transaction.atomic():
PythonDistribution(
pulp_id=python_distribution.pulp_id,
pulp_created=python_distribution.pulp_created,
pulp_last_updated=python_distribution.pulp_last_updated,
pulp_type=python_distribution.pulp_type,
name=python_distribution.name,
base_path=python_distribution.base_path,
content_guard=python_distribution.content_guard,
remote=python_distribution.remote,
publication=python_distribution.publication
).save()
python_distribution.delete()


class Migration(migrations.Migration):
atomic = False

dependencies = [
('core', '0062_add_new_distribution_mastermodel'),
('python', '0003_new_sync_filters'),
]

operations = [
migrations.CreateModel(
name='NewPythonDistribution',
fields=[
('distribution_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='python_pythondistribution', serialize=False, to='core.Distribution')),
],
options={
'default_related_name': '%(app_label)s_%(model_name)s',
},
bases=('core.distribution',),
),
migrations.RunPython(
code=migrate_data_from_old_model_to_new_model_up,
reverse_code=migrate_data_from_old_model_to_new_model_down,
),
migrations.DeleteModel(
name='PythonDistribution',
),
migrations.RenameModel(
old_name='NewPythonDistribution',
new_name='PythonDistribution',
),
]
4 changes: 2 additions & 2 deletions pulp_python/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pulpcore.plugin.models import (
Content,
Publication,
PublicationDistribution,
Distribution,
Remote,
Repository
)
Expand Down Expand Up @@ -35,7 +35,7 @@
("linux", "linux"))


class PythonDistribution(PublicationDistribution):
class PythonDistribution(Distribution):
"""
Distribution for 'Python' Content.
"""
Expand Down
16 changes: 12 additions & 4 deletions pulp_python/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,22 @@ class Meta:
model = python_models.PythonRepository


class PythonDistributionSerializer(core_serializers.PublicationDistributionSerializer):
class PythonDistributionSerializer(core_serializers.DistributionSerializer):
"""
Serializer for Pulp distributions for the Python type.

"""

publication = core_serializers.DetailRelatedField(
required=False,
help_text=_("Publication to be served"),
view_name_pattern=r"publications(-.*/.*)?-detail",
queryset=core_models.Publication.objects.exclude(complete=False),
allow_null=True,
)

class Meta:
fields = core_serializers.PublicationDistributionSerializer.Meta.fields
fields = core_serializers.DistributionSerializer.Meta.fields + ('publication', )
model = python_models.PythonDistribution


Expand Down Expand Up @@ -359,8 +367,8 @@ class PythonPublicationSerializer(core_serializers.PublicationSerializer):
distributions = core_serializers.DetailRelatedField(
help_text=_('This publication is currently being hosted as configured by these '
'distributions.'),
source="python_pythondistribution",
view_name="filedistributions-detail",
source="distribution_set",
view_name="pythondistributions-detail",
many=True,
read_only=True,
)
Expand Down
2 changes: 1 addition & 1 deletion pulp_python/app/tasks/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def run(self):
environ.pop('http_proxy')
deferred_download = self.remote.policy != Remote.IMMEDIATE
with ProgressReport(
message="Fetching Project Metadata", code="fetching.project"
message="Fetching Project Metadata", code="sync.fetching.project"
) as p:
pmirror = PulpMirror(
serial=0, # Serial currently isn't supported by Pulp
Expand Down
14 changes: 7 additions & 7 deletions pulp_python/app/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
AsyncOperationResponseSerializer,
RepositorySyncURLSerializer,
)
from pulpcore.plugin.tasking import enqueue_with_reservation
from pulpcore.plugin.tasking import dispatch

from pulp_python.app import models as python_models
from pulp_python.app import serializers as python_serializers
Expand Down Expand Up @@ -49,12 +49,12 @@ def sync(self, request, pk):
remote = serializer.validated_data.get('remote', repository.remote)
mirror = serializer.validated_data.get('mirror')

result = enqueue_with_reservation(
result = dispatch(
tasks.sync,
[repository, remote],
kwargs={
'remote_pk': remote.pk,
'repository_pk': repository.pk,
'remote_pk': str(remote.pk),
'repository_pk': str(repository.pk),
'mirror': mirror
}
)
Expand All @@ -69,7 +69,7 @@ class PythonRepositoryVersionViewSet(core_viewsets.RepositoryVersionViewSet):
parent_viewset = PythonRepositoryViewSet


class PythonDistributionViewSet(core_viewsets.BaseDistributionViewSet):
class PythonDistributionViewSet(core_viewsets.DistributionViewSet):
"""
<!-- User-facing documentation, rendered as html-->
Pulp Python Distributions are used to distribute
Expand Down Expand Up @@ -213,11 +213,11 @@ def create(self, request):
repository = serializer.validated_data.get('repository')
repository_version = RepositoryVersion.latest(repository)

result = enqueue_with_reservation(
result = dispatch(
tasks.publish,
[repository_version.repository],
kwargs={
'repository_version_pk': repository_version.pk
'repository_version_pk': str(repository_version.pk)
}
)
return core_viewsets.OperationPostponedResponse(result, request)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pulpcore>=3.9
pulpcore>=3.12
pkginfo
packaging
bandersnatch==4.4.0