From 5fb98812f2ae89a02711553de8803936d797b7c2 Mon Sep 17 00:00:00 2001 From: Tanya Tereshchenko Date: Thu, 11 Mar 2021 14:59:02 +0100 Subject: [PATCH] Fix migration for the case when no importer is specified. closes #8389 https://pulp.plan.io/issues/8389 backports #8382 https://pulp.plan.io/issues/8382 (cherry picked from commit a2176107bfbff075d052bc33ec0f773fadcd8276) --- CHANGES/8389.bugfix | 1 + pulp_2to3_migration/app/models/base.py | 4 +-- .../functional/test_migration_behaviour.py | 33 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 CHANGES/8389.bugfix diff --git a/CHANGES/8389.bugfix b/CHANGES/8389.bugfix new file mode 100644 index 00000000..bca94d65 --- /dev/null +++ b/CHANGES/8389.bugfix @@ -0,0 +1 @@ +Fixed a migraiton failure when no importer was specified in the migration plan. diff --git a/pulp_2to3_migration/app/models/base.py b/pulp_2to3_migration/app/models/base.py index a554cb52..c383aef3 100644 --- a/pulp_2to3_migration/app/models/base.py +++ b/pulp_2to3_migration/app/models/base.py @@ -434,7 +434,7 @@ def set_importer(cls, repo_id, repo_type, importer_repo_id): pulp2_resource_type=cls.IMPORTER, pulp2_repo_type=repo_type, pulp2_repo_id=repo_id, - pulp2_resource_repo_id=importer_repo_id, + pulp2_resource_repo_id=importer_repo_id or '', defaults={'status': cls.NEW} ) @@ -478,7 +478,7 @@ def set_distributors(cls, repo_id, repo_type, distributor_repo_ids): pulp2_resource_type=cls.DISTRIBUTOR, pulp2_repo_type=repo_type, pulp2_repo_id=repo_id, - pulp2_resource_repo_id=distributor_repo_id, + pulp2_resource_repo_id=distributor_repo_id or '', status=cls.NEW, ) except IntegrityError: diff --git a/pulp_2to3_migration/tests/functional/test_migration_behaviour.py b/pulp_2to3_migration/tests/functional/test_migration_behaviour.py index 6b15b118..77942aa4 100644 --- a/pulp_2to3_migration/tests/functional/test_migration_behaviour.py +++ b/pulp_2to3_migration/tests/functional/test_migration_behaviour.py @@ -107,6 +107,23 @@ }] }) +NO_IMPORTER_PLAN = json.dumps({ + "plugins": [{ + "type": "iso", + "repositories": [ + { + "name": "file", + "repository_versions": [ + { + "pulp2_repository_id": "file", # content count: iso - 3 + "pulp2_distributor_repository_ids": ["file"] + } + ] + } + ] + }] +}) + CONTENT_COUNT = { 'file': 3, 'file2': 3, @@ -303,3 +320,19 @@ def test_no_immediate_importer(self): self.assertEqual(self.file_repo_versions_api.list(pulp3_repo.pulp_href).count, 2) self.assertEqual(repo_content.count, 3) + + def test_no_importer(self): + """Test that if there is no importer specified at all, migraiton is still working fine.""" + self.run_migration(NO_IMPORTER_PLAN) + pulp3_repo = self.file_repo_api.list().results[0] + repo_content = self.file_content_api.list(repository_version=pulp3_repo.latest_version_href) + pulp2repository = self.pulp2repositories_api.list().results[0] + pulp3_pub = self.file_publication_api.read(pulp2repository.pulp3_publication_href) + pulp3_dist = self.file_distribution_api.read(pulp2repository.pulp3_distribution_hrefs[0]) + + self.assertEqual(self.file_repo_versions_api.list(pulp3_repo.pulp_href).count, 2) + self.assertEqual(repo_content.count, 3) + self.assertEqual(pulp2repository.pulp2_repo_id, 'file') + self.assertEqual(pulp3_pub.repository_version, pulp2repository.pulp3_repository_version) + self.assertEqual(pulp3_pub.distributions[0], pulp3_dist.pulp_href) + self.assertEqual(pulp3_dist.base_path, 'file')