Skip to content

Commit ab3cc04

Browse files
authored
Merge pull request #375 from gerrod3/autopublish_fix
Autopublish fix
2 parents e4b477f + 8f9e4a0 commit ab3cc04

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

CHANGES/371.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Auto-publish doesn't modify distributions

pulp_python/app/models.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,4 @@ def on_new_version(self, version):
200200
from pulp_python.app import tasks
201201

202202
if self.autopublish:
203-
publication = tasks.publish(
204-
repository_version_pk=version.pk,
205-
)
206-
207-
distributions = self.distributions.all()
208-
209-
if publication and distributions:
210-
for distribution in distributions:
211-
distribution.publication = publication
212-
distribution.save()
203+
tasks.publish(repository_version_pk=version.pk)

pulp_python/app/serializers.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ class PythonDistributionSerializer(core_serializers.DistributionSerializer):
4646
allow_null=True,
4747
)
4848

49+
def validate(self, data):
50+
"""
51+
Ensure publication and repository are not set at the same time.
52+
53+
This is needed here till https://pulp.plan.io/issues/8761 is resolved.
54+
"""
55+
data = super().validate(data)
56+
repository_provided = data.get("repository", None)
57+
publication_provided = data.get("publication", None)
58+
59+
if repository_provided and publication_provided:
60+
raise serializers.ValidationError(
61+
_(
62+
"Only one of the attributes 'repository' and 'publication' "
63+
"may be used simultaneously."
64+
)
65+
)
66+
if repository_provided or publication_provided:
67+
data["repository"] = repository_provided
68+
data["publication"] = publication_provided
69+
return data
70+
4971
class Meta:
5072
fields = core_serializers.DistributionSerializer.Meta.fields + ('publication', )
5173
model = python_models.PythonDistribution

pulp_python/tests/functional/api/test_auto_publish.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from pulp_smash import config
66
from pulp_smash.pulp3.bindings import monitor_task
7-
from pulp_smash.pulp3.utils import gen_repo, gen_distribution
7+
from pulp_smash.pulp3.utils import gen_repo, gen_distribution, download_content_unit
88

99
from pulp_python.tests.functional.utils import gen_python_client, gen_python_remote
1010
from pulp_python.tests.functional.utils import set_up_module as setUpModule # noqa:F401
@@ -57,13 +57,11 @@ def test_01_sync(self):
5757
repository_sync_data = RepositorySyncURL(remote=self.remote.pulp_href)
5858
sync_response = self.repo_api.sync(self.repo.pulp_href, repository_sync_data)
5959
task = monitor_task(sync_response.task)
60-
self.distribution = self.distributions_api.read(self.distribution.pulp_href)
6160

6261
# Check that all the appropriate resources were created
6362
self.assertGreater(len(task.created_resources), 1)
6463
self.assertEqual(self.publications_api.list().count, 1)
65-
self.assertTrue(self.distribution.publication is not None)
66-
self.assertTrue(self.distribution.publication in task.created_resources)
64+
download_content_unit(self.cfg, self.distribution.to_dict(), "simple/")
6765

6866
# Sync the repository again. Since there should be no new repository version, there
6967
# should be no new publications or distributions either.
@@ -78,16 +76,14 @@ def test_02_modify(self):
7876
self.assertEqual(self.publications_api.list().count, 0)
7977
self.assertTrue(self.distribution.publication is None)
8078

81-
# Modify the repository by adding a coment unit
79+
# Modify the repository by adding a content unit
8280
content = self.content_api.list().results[0].pulp_href
8381
modify_response = self.repo_api.modify(
8482
self.repo.pulp_href, {"add_content_units": [content]}
8583
)
8684
task = monitor_task(modify_response.task)
87-
self.distribution = self.distributions_api.read(self.distribution.pulp_href)
8885

8986
# Check that all the appropriate resources were created
9087
self.assertGreater(len(task.created_resources), 1)
9188
self.assertEqual(self.publications_api.list().count, 1)
92-
self.assertTrue(self.distribution.publication is not None)
93-
self.assertTrue(self.distribution.publication in task.created_resources)
89+
download_content_unit(self.cfg, self.distribution.to_dict(), "simple/")

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pulpcore>=3.12
1+
pulpcore>=3.13.0.dev
22
pkginfo
33
packaging
44
bandersnatch==4.4.0

0 commit comments

Comments
 (0)