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

Commit

Permalink
Use proper 2to3 uniqueness constraints for deb
Browse files Browse the repository at this point in the history
closes #484
#484

Previously the uniqueness constraints allowed for only one 2to3 unit per
Pulp 3 unit to be created. This causes problems when there is more than
one Pulp 2 unit that map onto the same Pulp 3 unit to be created.
If prevents the resultant Pulp 3 unit from being added to every repo it
belongs in.
  • Loading branch information
quba42 authored and goosemania committed Jan 4, 2022
1 parent dcf24e6 commit 00276b7
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES/484.bugfix
@@ -0,0 +1 @@
Fixed a bug in the deb migration that caused migrated repos to lack content needed for structured publications in some circumstances.
53 changes: 53 additions & 0 deletions pulp_2to3_migration/app/migrations/0031_add_repoid_to_deb_types.py
@@ -0,0 +1,53 @@
# Generated by Django 2.2.20 on 2021-12-07 13:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pulp_2to3_migration', '0030_update_json_field'),
]

operations = [
migrations.AddField(
model_name='pulp2debcomponent',
name='repoid',
field=models.TextField(default='blub'),
preserve_default=False,
),
migrations.AddField(
model_name='pulp2debrelease',
name='repoid',
field=models.TextField(default='blub'),
preserve_default=False,
),
migrations.AddField(
model_name='pulp2debcomponentpackage',
name='repoid',
field=models.TextField(default='blub'),
preserve_default=False,
),
migrations.AddField(
model_name='pulp2debreleasearchitecture',
name='repoid',
field=models.TextField(default='blub'),
preserve_default=False,
),
migrations.AlterUniqueTogether(
name='pulp2debcomponent',
unique_together={('component', 'codename', 'suite', 'distribution', 'repoid')},
),
migrations.AlterUniqueTogether(
name='pulp2debrelease',
unique_together={('codename', 'suite', 'distribution', 'repoid')},
),
migrations.AlterUniqueTogether(
name='pulp2debcomponentpackage',
unique_together={('package_relative_path', 'package_sha256', 'component', 'distribution', 'codename', 'suite', 'repoid')},
),
migrations.AlterUniqueTogether(
name='pulp2debreleasearchitecture',
unique_together={('architecture', 'distribution', 'codename', 'suite', 'repoid')},
),
]
22 changes: 16 additions & 6 deletions pulp_2to3_migration/app/plugin/deb/pulp_2to3_models.py
Expand Up @@ -202,10 +202,11 @@ class Pulp2DebRelease(Pulp2to3Content):
distribution = django_models.TextField()
codename = django_models.TextField()
suite = django_models.TextField(null=True)
repoid = django_models.TextField()

class Meta:
default_related_name = 'deb_release_detail_model'
unique_together = ('codename', 'suite', 'distribution')
unique_together = ('codename', 'suite', 'distribution', 'repoid')

@classmethod
def pre_migrate_content_detail(cls, content_batch):
Expand All @@ -221,6 +222,7 @@ def pre_migrate_content_detail(cls, content_batch):
units_to_save = [Pulp2DebRelease(distribution=release.distribution,
codename=release.codename,
suite=release.suite,
repoid=release.repoid,
pulp2content=pulp2_unit_map[release.id],)
for release in pulp2_unit_batch]

Expand Down Expand Up @@ -255,10 +257,11 @@ class Pulp2DebComponent(Pulp2to3Content):
codename = django_models.TextField()
component = django_models.TextField()
suite = django_models.TextField()
repoid = django_models.TextField()

class Meta:
default_related_name = 'deb_component_detail_model'
unique_together = ('component', 'codename', 'suite', 'distribution')
unique_together = ('component', 'codename', 'suite', 'distribution', 'repoid')

@classmethod
def pre_migrate_content_detail(cls, content_batch):
Expand Down Expand Up @@ -291,8 +294,9 @@ def pre_migrate_content_detail(cls, content_batch):
distribution = component_unit.distribution
codename = component_unit.release
component = component_unit.name
repoid = component_unit.repoid
release = pulp2_models.DebRelease.objects.filter(
repoid=component_unit.repoid,
repoid=repoid,
distribution=distribution,
).first()
suite = release.suite
Expand All @@ -301,6 +305,7 @@ def pre_migrate_content_detail(cls, content_batch):
codename=codename,
component=component,
suite=suite,
repoid=repoid,
pulp2content=pulp2_base_record,
))
architectures = set()
Expand All @@ -310,7 +315,7 @@ def pre_migrate_content_detail(cls, content_batch):
package_sha256 = package_unit.checksum

# We are using the sha256 of the concatenated unique_together fields for the subid:
pulp2_subid_string = (suite + codename + distribution + component
pulp2_subid_string = (component + codename + suite + distribution + repoid
+ package_relative_path + package_sha256)
pulp2_subid = sha256(pulp2_subid_string.encode('utf-8')).hexdigest()

Expand All @@ -332,14 +337,15 @@ def pre_migrate_content_detail(cls, content_batch):
distribution=distribution,
codename=codename,
suite=suite,
repoid=repoid,
pulp2content=pulp2_sub_record,
))
architectures.add(package_unit.architecture)

architectures.discard('all')
for architecture in architectures:
# We are using the sha256 of the concatenated unique_together fields for the subid:
pulp2_subid_string = architecture + distribution + codename + suite
pulp2_subid_string = architecture + distribution + codename + suite + repoid
pulp2_subid = sha256(pulp2_subid_string.encode('utf-8')).hexdigest()

pulp2_sub_record = Pulp2Content(
Expand All @@ -358,6 +364,7 @@ def pre_migrate_content_detail(cls, content_batch):
distribution=distribution,
codename=codename,
suite=suite,
repoid=repoid,
pulp2content=pulp2_sub_record,
))

Expand Down Expand Up @@ -412,6 +419,7 @@ class Pulp2DebComponentPackage(Pulp2to3Content):
distribution = django_models.TextField()
codename = django_models.TextField()
suite = django_models.TextField()
repoid = django_models.TextField()

class Meta:
default_related_name = 'deb_component_package_detail_model'
Expand All @@ -422,6 +430,7 @@ class Meta:
'distribution',
'codename',
'suite',
'repoid',
)

@classmethod
Expand Down Expand Up @@ -471,10 +480,11 @@ class Pulp2DebReleaseArchitecture(Pulp2to3Content):
distribution = django_models.TextField()
codename = django_models.TextField()
suite = django_models.TextField()
repoid = django_models.TextField()

class Meta:
default_related_name = 'deb_release_architecture_detail_model'
unique_together = ('architecture', 'distribution', 'codename', 'suite')
unique_together = ('architecture', 'distribution', 'codename', 'suite', 'repoid')

@classmethod
def pre_migrate_content_detail(cls, content_batch):
Expand Down

0 comments on commit 00276b7

Please sign in to comment.