Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/371.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Auto-publish doesn't modify distributions
11 changes: 1 addition & 10 deletions pulp_python/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
22 changes: 22 additions & 0 deletions pulp_python/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions pulp_python/tests/functional/api/test_auto_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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/")
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pulpcore>=3.12
pulpcore>=3.13.0.dev
pkginfo
packaging
bandersnatch==4.4.0