Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Code changes for pulpcore-3.13 compatibility.
Browse files Browse the repository at this point in the history
enqueue_with_reservation() -> dispatch()
BaseDistribution -> Distribution

closes #8522
[nocoverage]
  • Loading branch information
ggainey committed Jun 11, 2021
1 parent e8aebef commit dda7d29
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGES/8522.doc
@@ -0,0 +1,5 @@
Taught 2to3 migration about changes in task-dispatching and Distributions.

**NOTE**: To minimize any potential impact from this change, please make sure
you've done a 2to3 migration after any Pulp2 changes to distributors **before**
upgrading to this release.
4 changes: 2 additions & 2 deletions pulp_2to3_migration/app/migration.py
Expand Up @@ -14,7 +14,7 @@
TaskGroup,
)

from pulpcore.plugin.tasking import enqueue_with_reservation
from pulpcore.plugin.tasking import dispatch

from pulp_2to3_migration.app.models import (
Pulp2Content,
Expand Down Expand Up @@ -284,7 +284,7 @@ def create_repoversions_publications_distributions(plan, parallel=True):
repo_ver_to_create += len(repo_versions)
repo = Repository.objects.get(name=repo_name).cast()
task_args = [plugin, pulp3_repo_setup, repo_name]
enqueue_with_reservation(
dispatch(
complex_repo_migration,
[repo],
args=task_args,
Expand Down
29 changes: 29 additions & 0 deletions pulp_2to3_migration/app/migrations/0029_distribution_change.py
@@ -0,0 +1,29 @@
# Generated by Django 2.2.24 on 2021-06-07 15:14

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

_logger = logging.getLogger(__name__)

def unset_distribution_field(apps, schema_editor):
Pulp2Distributor = apps.get_model('pulp_2to3_migration', 'pulp2distributor')
nrows = Pulp2Distributor.objects.update(pulp3_distribution=None, is_migrated=False)
_logger.debug("Updated {} Pulp2Distributor rows.".format(nrows))

class Migration(migrations.Migration):

dependencies = [
('pulp_2to3_migration', '0028_create_missing_indices'),
]

operations = [
migrations.RunPython(
code=unset_distribution_field,
),
migrations.AlterField(
model_name='pulp2distributor',
name='pulp3_distribution',
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.Distribution'),
),
]
4 changes: 2 additions & 2 deletions pulp_2to3_migration/app/models/repository.py
Expand Up @@ -6,7 +6,7 @@
)
from pulpcore.plugin.models import (
BaseModel,
BaseDistribution,
Distribution,
Repository,
RepositoryVersion,
Publication,
Expand Down Expand Up @@ -175,7 +175,7 @@ class Pulp2Distributor(BaseModel):

# due to base_path overlap restriction, a distribution can't correspond to multiple pulp 2
# distributors, thus one-to-one relationship.
pulp3_distribution = models.OneToOneField(BaseDistribution,
pulp3_distribution = models.OneToOneField(Distribution,
on_delete=models.SET_NULL,
null=True)

Expand Down
4 changes: 2 additions & 2 deletions pulp_2to3_migration/app/pre_migration.py
Expand Up @@ -12,7 +12,7 @@

from pulpcore.plugin.constants import TASK_STATES
from pulpcore.plugin.models import (
BaseDistribution,
Distribution,
Publication,
ProgressReport,
)
Expand Down Expand Up @@ -799,7 +799,7 @@ def handle_outdated_resources(plan):
pulp2distributor__in=pulp2distributors_with_old_distributions_qs).delete()

# Delete outdated distributions
BaseDistribution.objects.filter(
Distribution.objects.filter(
pulp2distributor__in=pulp2distributors_with_old_distributions_qs).delete()

# Remove relations to the pulp2repository in case the relation changed.
Expand Down
10 changes: 5 additions & 5 deletions pulp_2to3_migration/app/viewsets.py
Expand Up @@ -14,7 +14,7 @@

from pulpcore.plugin.models import Task
from pulpcore.plugin.serializers import AsyncOperationResponseSerializer
from pulpcore.plugin.tasking import enqueue_with_reservation
from pulpcore.plugin.tasking import dispatch
from pulpcore.plugin.viewsets import (
BaseFilterSet,
NamedModelViewSet,
Expand Down Expand Up @@ -94,11 +94,11 @@ def run(self, request, pk):
if is_migration_plan_running():
raise ValidationError(_("Only one migration plan can run or be reset at a time"))

result = enqueue_with_reservation(
result = dispatch(
migrate_from_pulp2,
[PULP_2TO3_MIGRATION_RESOURCE],
kwargs={
'migration_plan_pk': migration_plan.pk,
'migration_plan_pk': str(migration_plan.pk),
'validate': validate,
'dry_run': dry_run,
'skip_corrupted': skip_corrupted
Expand All @@ -120,11 +120,11 @@ def reset(self, request, pk):
if is_migration_plan_running():
raise ValidationError(_("Only one migration plan can run or be reset at a time"))

result = enqueue_with_reservation(
result = dispatch(
reset_pulp3_data,
[PULP_2TO3_MIGRATION_RESOURCE],
kwargs={
'migration_plan_pk': migration_plan.pk,
'migration_plan_pk': str(migration_plan.pk),
}
)
return OperationPostponedResponse(result, request)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,4 +1,4 @@
pulpcore>=3.6
pulpcore>=3.12
mongoengine
semantic_version
jsonschema>=3.0

0 comments on commit dda7d29

Please sign in to comment.