diff --git a/CHANGES/371.misc b/CHANGES/371.misc new file mode 100644 index 000000000..4f7236c47 --- /dev/null +++ b/CHANGES/371.misc @@ -0,0 +1 @@ +Auto-publish doesn't modify distributions diff --git a/pulp_python/app/models.py b/pulp_python/app/models.py index ac2a83b26..1975a4447 100644 --- a/pulp_python/app/models.py +++ b/pulp_python/app/models.py @@ -200,13 +200,4 @@ def on_new_version(self, version): from pulp_python.app import tasks if self.autopublish: - publication = tasks.publish( - repository_version_pk=version.pk, - ) - - distributions = self.distributions.all() - - if publication and distributions: - for distribution in distributions: - distribution.publication = publication - distribution.save() + tasks.publish(repository_version_pk=version.pk) diff --git a/pulp_python/app/serializers.py b/pulp_python/app/serializers.py index f9b4e6886..505ad3858 100644 --- a/pulp_python/app/serializers.py +++ b/pulp_python/app/serializers.py @@ -46,6 +46,28 @@ class PythonDistributionSerializer(core_serializers.DistributionSerializer): allow_null=True, ) + def validate(self, data): + """ + Ensure publication and repository are not set at the same time. + + This is needed here till https://pulp.plan.io/issues/8761 is resolved. + """ + data = super().validate(data) + repository_provided = data.get("repository", None) + publication_provided = data.get("publication", None) + + if repository_provided and publication_provided: + raise serializers.ValidationError( + _( + "Only one of the attributes 'repository' and 'publication' " + "may be used simultaneously." + ) + ) + if repository_provided or publication_provided: + data["repository"] = repository_provided + data["publication"] = publication_provided + return data + class Meta: fields = core_serializers.DistributionSerializer.Meta.fields + ('publication', ) model = python_models.PythonDistribution diff --git a/pulp_python/tests/functional/api/test_auto_publish.py b/pulp_python/tests/functional/api/test_auto_publish.py index 1358125bf..5db677b71 100644 --- a/pulp_python/tests/functional/api/test_auto_publish.py +++ b/pulp_python/tests/functional/api/test_auto_publish.py @@ -4,7 +4,7 @@ from pulp_smash import config from pulp_smash.pulp3.bindings import monitor_task -from pulp_smash.pulp3.utils import gen_repo, gen_distribution +from pulp_smash.pulp3.utils import gen_repo, gen_distribution, download_content_unit from pulp_python.tests.functional.utils import gen_python_client, gen_python_remote from pulp_python.tests.functional.utils import set_up_module as setUpModule # noqa:F401 @@ -57,13 +57,11 @@ def test_01_sync(self): repository_sync_data = RepositorySyncURL(remote=self.remote.pulp_href) sync_response = self.repo_api.sync(self.repo.pulp_href, repository_sync_data) task = monitor_task(sync_response.task) - self.distribution = self.distributions_api.read(self.distribution.pulp_href) # Check that all the appropriate resources were created self.assertGreater(len(task.created_resources), 1) self.assertEqual(self.publications_api.list().count, 1) - self.assertTrue(self.distribution.publication is not None) - self.assertTrue(self.distribution.publication in task.created_resources) + download_content_unit(self.cfg, self.distribution.to_dict(), "simple/") # Sync the repository again. Since there should be no new repository version, there # should be no new publications or distributions either. @@ -78,16 +76,14 @@ def test_02_modify(self): self.assertEqual(self.publications_api.list().count, 0) self.assertTrue(self.distribution.publication is None) - # Modify the repository by adding a coment unit + # Modify the repository by adding a content unit content = self.content_api.list().results[0].pulp_href modify_response = self.repo_api.modify( self.repo.pulp_href, {"add_content_units": [content]} ) task = monitor_task(modify_response.task) - self.distribution = self.distributions_api.read(self.distribution.pulp_href) # Check that all the appropriate resources were created self.assertGreater(len(task.created_resources), 1) self.assertEqual(self.publications_api.list().count, 1) - self.assertTrue(self.distribution.publication is not None) - self.assertTrue(self.distribution.publication in task.created_resources) + download_content_unit(self.cfg, self.distribution.to_dict(), "simple/") diff --git a/requirements.txt b/requirements.txt index 5199fa95b..278340b2e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -pulpcore>=3.12 +pulpcore>=3.13.0.dev pkginfo packaging bandersnatch==4.4.0