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

Multiple plugin migrations and migrating empty repos when specified in the plan #87

Merged
merged 2 commits into from Feb 8, 2020

Conversation

dralley
Copy link
Contributor

@dralley dralley commented Feb 4, 2020

@dralley
Copy link
Contributor Author

dralley commented Feb 4, 2020

Currently, I can only test this with pulpcore 3.0 and pulp_container 1.0, since the docker migration is broken with 3.1

@ipanova
Copy link
Member

ipanova commented Feb 4, 2020 via email

@dralley
Copy link
Contributor Author

dralley commented Feb 4, 2020

I'm still working on testing it thoroughly (I wasn't really expecting it to be looked at today). Probably needs a WIP tag.

@ipanova
Copy link
Member

ipanova commented Feb 4, 2020 via email

@dralley
Copy link
Contributor Author

dralley commented Feb 4, 2020

@ipanova I used this plan to test:

http POST :24817/pulp/api/v3/migration-plans/ plan='{"plugins": [{"type": "iso", "repositories": [{"name": "filetest", "pulp2_importer_repository_id": "file", "repository_versi
ons": [{"pulp2_repository_id": "file", "pulp2_distributor_repository_ids": ["file"]}, {"pulp2_repository_id": "file2", "pulp2_distributor_repository_ids": ["file2"]}]}]}, {"type": "docker", "repositories": [{"name": "test-fixture-1", "rep
ository_versions": [{"pulp2_repository_id": "test-fixture-1", "pulp2_distributor_repository_ids": ["test-fixture-1"]}]}]}]}'

{
    "plan": {
        "plugins": [
            {
                "repositories": [
                    {
                        "name": "filetest",
                        "pulp2_importer_repository_id": "file",
                        "repository_versions": [
                            {
                                "pulp2_distributor_repository_ids": [
                                    "file"
                                ],
                                "pulp2_repository_id": "file"
                            },
                            {
                                "pulp2_distributor_repository_ids": [
                                    "file2"
                                ],
                                "pulp2_repository_id": "file2"
                            }
                        ]
                    }
                ],
                "type": "iso"
            },
            {
                "repositories": [
                    {
                        "name": "test-fixture-1",
                        "repository_versions": [
                            {
                                "pulp2_distributor_repository_ids": [
                                    "test-fixture-1"
                                ],
                                "pulp2_repository_id": "test-fixture-1"
                            }
                        ]
                    }
                ],
                "type": "docker"
            }
        ]
    },
    "pulp_created": "2020-02-04T19:50:07.646432Z",
    "pulp_href": "/pulp/api/v3/migration-plans/3dde9e85-3343-4605-a626-86ae56748c5e/"
}

And got the following results, which looks correct.

    "results": [
        {
            "is_migrated": true,
            "not_in_plan": false,
            "pulp2_object_id": "5e39b6c26e50c93273818358",
            "pulp2_repo_id": "file",
            "pulp3_distribution_hrefs": [
                "/pulp/api/v3/distributions/file/file/e25f9387-5d0d-4178-85ef-4dfb1ed062a5/"
            ],
            "pulp3_publication_href": "/pulp/api/v3/publications/file/file/91bd9fca-56d2-43ca-8bd5-eb221509331c/",
            "pulp3_remote_href": "/pulp/api/v3/remotes/file/file/c1c19710-fe43-40db-b65a-e0a1c4129a6f/",
            "pulp3_repository_href": "/pulp/api/v3/repositories/file/file/b2c84286-768f-4716-911d-69aba1bdba6a/",
            "pulp3_repository_version": "/pulp/api/v3/repositories/file/file/b2c84286-768f-4716-911d-69aba1bdba6a/versions/1/",
            "pulp_created": "2020-02-04T19:50:29.909310Z",
            "pulp_href": "/pulp/api/v3/pulp2repositories/fbfbbd3a-76ab-47da-a235-448b00320538/",
            "type": "iso"
        },
        {
            "is_migrated": true,
            "not_in_plan": false,
            "pulp2_object_id": "5e39b6c26e50c9327381835b",
            "pulp2_repo_id": "file2",
            "pulp3_distribution_hrefs": [
                "/pulp/api/v3/distributions/file/file/54a9858e-ddf3-4e9f-a5f3-fc06c1160057/"
            ],
            "pulp3_publication_href": "/pulp/api/v3/publications/file/file/1cd90201-e198-4e8c-8d48-94e4c4f1195a/",
            "pulp3_remote_href": "/pulp/api/v3/remotes/file/file/c1c19710-fe43-40db-b65a-e0a1c4129a6f/",
            "pulp3_repository_href": "/pulp/api/v3/repositories/file/file/b2c84286-768f-4716-911d-69aba1bdba6a/",
            "pulp3_repository_version": "/pulp/api/v3/repositories/file/file/b2c84286-768f-4716-911d-69aba1bdba6a/versions/2/",
            "pulp_created": "2020-02-04T19:50:29.896925Z",
            "pulp_href": "/pulp/api/v3/pulp2repositories/ddea27bd-abd5-42e2-abc6-b0bc5dd989c8/",
            "type": "iso"
        },
        {
            "is_migrated": true,
            "not_in_plan": false,
            "pulp2_object_id": "5e39b6c46e50c93275f65aee",
            "pulp2_repo_id": "test-fixture-1",
            "pulp3_distribution_hrefs": [
                "/pulp/api/v3/distributions/container/container/5d898e56-7396-4063-9869-c03e9b4cf4fd/"
            ],
            "pulp3_publication_href": null,
            "pulp3_remote_href": null,
            "pulp3_repository_href": "/pulp/api/v3/repositories/container/container/7599c647-6206-4d06-b923-9b63b54419e6/",
            "pulp3_repository_version": "/pulp/api/v3/repositories/container/container/7599c647-6206-4d06-b923-9b63b54419e6/versions/1/",
            "pulp_created": "2020-02-04T19:50:29.877117Z",
            "pulp_href": "/pulp/api/v3/pulp2repositories/80279b10-7a78-4d78-83d1-878437526229/",
            "type": "docker"
        }
    ]

@dralley
Copy link
Contributor Author

dralley commented Feb 4, 2020

@ipanova However, I think I've found a bug in the docker migrator. Using this plan (which only migrates docker, no iso) and a clean database, and pulpcore 3.0, pulp_container 1.0, and master branch of the migration plugin (ha! not making that mistake again...):

If you run a migration plan for the docker plugin twice (any plan), you get this

Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: Traceback (most recent call last):
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: return self.cursor.execute(sql, params)
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "container_blobmanifest_manifest_id_manifest_blo_05da3e8d_uniq"
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: DETAIL:  Key (manifest_id, manifest_blob_id)=(379a3152-5461-464d-a971-ef662026c04e, e17f96db-ab2b-41be-aa90-d719a72d4886) already exists.
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: The above exception was the direct cause of the following exception:
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: Traceback (most recent call last):
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/home/vagrant/devel/pulp-2to3-migration/pulp_2to3_migration/app/plugin/docker/migrator.py", line 80, in migrate_content_to_pulp3
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: await dm.create()
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/home/vagrant/devel/pulp-2to3-migration/pulp_2to3_migration/app/plugin/content.py", line 83, in create
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: await pipeline
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/home/vagrant/devel/pulpcore/pulpcore/plugin/stages/api.py", line 209, in create_pipeline
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: await asyncio.gather(*futures)
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/home/vagrant/devel/pulpcore/pulpcore/plugin/stages/api.py", line 43, in __call__
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: await self.run()
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/home/vagrant/devel/pulp-2to3-migration/pulp_2to3_migration/app/plugin/docker/migrator.py", line 178, in run
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: self.relate_blob(dc)
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/home/vagrant/devel/pulp-2to3-migration/pulp_2to3_migration/app/plugin/docker/migrator.py", line 214, in relate_blob
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: thru.save()
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/db/models/base.py", line 741, in save
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: force_update=force_update, update_fields=update_fields)
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/db/models/base.py", line 779, in save_base
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: force_update, using, update_fields,
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/db/models/base.py", line 870, in _save_table
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/db/models/base.py", line 908, in _do_insert
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: using=using, raw=raw)
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: return getattr(self.get_queryset(), name)(*args, **kwargs)
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/db/models/query.py", line 1186, in _insert
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: return query.get_compiler(using=using).execute_sql(return_id)
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/db/models/sql/compiler.py", line 1368, in execute_sql
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: cursor.execute(sql, params)
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/db/backends/utils.py", line 67, in execute
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: return executor(sql, params, many, context)
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: return self.cursor.execute(sql, params)
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: raise dj_exc_value.with_traceback(traceback) from exc_value
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: File "/usr/local/lib/pulp/lib64/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: return self.cursor.execute(sql, params)
Feb 04 20:03:15 pulp2-nightly-pulp3-source-centos7.localhost.example.com rq[10867]: django.db.utils.IntegrityError: duplicate key value violates unique constraint "container_blobmanifest_manifest_id_manifest_blo_05da3e8d_uniq"

I've filed an issue for this: https://pulp.plan.io/issues/6099

@dralley
Copy link
Contributor Author

dralley commented Feb 4, 2020

Aside from that, a migration plan for all ISO and specific docker does seem to have issues though.

@dralley dralley added the WIP label Feb 4, 2020
@dralley
Copy link
Contributor Author

dralley commented Feb 5, 2020

I got it mostly working with that example (blanket ISO migrate, specific docker), it still needs a little more work and testing.

@dralley
Copy link
Contributor Author

dralley commented Feb 5, 2020

The container plugin doesn't use publications, correct?

@ipanova
Copy link
Member

ipanova commented Feb 5, 2020

The container plugin doesn't use publications, correct?

correct, it has only distributions

@ipanova
Copy link
Member

ipanova commented Feb 5, 2020

@dralley #88 i submitted a PR to fix integrity error

@dralley
Copy link
Contributor Author

dralley commented Feb 5, 2020

Thanks @ipanova !

This should be working now. Tested with:

  • 2 plugins, specific repos
  • 2 plugins, docker specific, iso everything
  • 2 plugins, docker everything, iso specific

@dralley dralley force-pushed the multiple-plugin branch 3 times, most recently from e7c1a23 to 62bf203 Compare February 5, 2020 22:48
@dralley dralley removed the WIP label Feb 6, 2020
@dralley dralley force-pushed the multiple-plugin branch 2 times, most recently from 6cb5ee9 to 523cb5c Compare February 7, 2020 02:22
@dralley dralley changed the title Fix migration of multiple plugins simultaneously Fix migration of multiple plugins simultaneously and migrate empty repos Feb 7, 2020
@dralley dralley changed the title Fix migration of multiple plugins simultaneously and migrate empty repos Multiple plugin migrations and migrating empty repos when specified in the plan Feb 7, 2020
@dralley
Copy link
Contributor Author

dralley commented Feb 7, 2020

Also, should now migrate empty repositories when they're specified.

pulp3_distribution=None,
pulp3_publication=None,
not_in_plan=False,
pulp2_type_id=plugin.type
Copy link
Member

Choose a reason for hiding this comment

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

when i run the migration it does not create any publications or distributions, i think because of this line.
In [3]: Pulp2Distributor.objects.all()[0].pulp2_type_id
Out[3]: 'iso_distributor'

in plugin.type you will have 'iso'

Copy link
Member

Choose a reason for hiding this comment

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

you can fetch the types for distributors from the plugin.migrator.distriubutor_migrators.keys()

Copy link
Member

Choose a reason for hiding this comment

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

@dralley you applied this logic to pulp2repos and pulp2 distributors, what about pulp2importers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Strange, I didn't seem to have that issue -- but I'll check again.

Copy link
Member

Choose a reason for hiding this comment

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

Strange, I didn't seem to have that issue -- but I'll check again.

https://paste.centos.org/view/0de7e0d2

@@ -156,6 +156,7 @@ class Pulp2RepositoriesSerializer(ModelSerializer):
)
pulp2_object_id = serializers.CharField(max_length=255)
pulp2_repo_id = serializers.CharField()
type = serializers.CharField()
Copy link
Member

Choose a reason for hiding this comment

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

what about pulp2_repo_type to stay consistent with other fields names?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I rename the database field as well? It is just type

Copy link
Member

Choose a reason for hiding this comment

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

+1 to that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you also like the database field renamed? It is just type

@dralley dralley force-pushed the multiple-plugin branch 4 times, most recently from 3f7fd96 to baabd6c Compare February 7, 2020 16:17
@dralley dralley force-pushed the multiple-plugin branch 2 times, most recently from a3e07ea to 9317b43 Compare February 7, 2020 16:30
@dralley
Copy link
Contributor Author

dralley commented Feb 7, 2020

@ipanova With continued testing I found a new bug :( I'll let you know when this is ready

@dralley
Copy link
Contributor Author

dralley commented Feb 7, 2020

Working again @ipanova


for plugin in plan.get_plugin_plans():
distributor_migrators.update(**plugin.migrator.distributor_migrators)
Copy link
Member

Choose a reason for hiding this comment

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

since we process distributors by plugin type now, i believe we can just assign directly distributor_migrators = plugin.migrator.distributor_migrators, no need to update the dict

not_in_plan=False,
pulp2_type_id__in=distributor_types
)
pb.total = pulp2distributors_qs.count()
Copy link
Member

Choose a reason for hiding this comment

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

pb.total += pulp2distributors_qs.count()

pulp2_type_id__in=distributor_types
)
pb.total = pulp2distributors_qs.count()
pb.save()
Copy link
Member

@ipanova ipanova Feb 7, 2020

Choose a reason for hiding this comment

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

i think we should save the counters outside of the for loop not that important

Copy link
Member

@ipanova ipanova left a comment

Choose a reason for hiding this comment

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

I left a minor comment about counters. I have tested various corner cases and they do seems to work!
nice work 🌴 🍺

@dralley dralley merged commit 84e1c01 into pulp:master Feb 8, 2020
@dralley dralley deleted the multiple-plugin branch February 8, 2020 05:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants