Skip to content

Commit f131b9b

Browse files
authored
Merge pull request #1337 from balasankarc/add-auto-publish
Support automatically publishing new repository versions
2 parents 5df3921 + e516032 commit f131b9b

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed

CHANGES/406.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Added autopublish functionality.
2+
Creates a structured APT publication when used.
3+
Cannot be used to create verbatim publications.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from django.db import migrations, models
2+
3+
class Migration(migrations.Migration):
4+
5+
dependencies = [
6+
('deb', '0001_initial_squashed_0031_add_domains'),
7+
]
8+
9+
operations = [
10+
migrations.AddField(
11+
model_name='aptrepository',
12+
name='autopublish',
13+
field=models.BooleanField(default=False),
14+
),
15+
]
16+

pulp_deb/app/models/repository.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,30 @@ class AptRepository(Repository, AutoAddObjPermsMixin):
6868
)
6969
# Implicit signing_service_release_overrides
7070

71+
autopublish = models.BooleanField(default=False)
72+
73+
def on_new_version(self, version):
74+
"""
75+
Called when new repository versions are created.
76+
77+
Args:
78+
version: The new repository version.
79+
"""
80+
super().on_new_version(version)
81+
82+
# avoid circular import issues
83+
from pulp_deb.app import tasks
84+
85+
if self.autopublish:
86+
tasks.publish(
87+
repository_version_pk=version.pk,
88+
# We currently support only automatically creating a structured
89+
# publication
90+
simple=False,
91+
structured=True,
92+
signing_service_pk=getattr(self.signing_service, "pk", None),
93+
)
94+
7195
class Meta:
7296
default_related_name = "%(app_label)s_%(model_name)s"
7397
permissions = [

pulp_deb/app/serializers/repository_serializers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ class AptRepositorySerializer(RepositorySerializer):
4444
A Serializer for AptRepository.
4545
"""
4646

47+
autopublish = serializers.BooleanField(
48+
help_text=_(
49+
"Whether to automatically create publications for new repository versions, "
50+
"and update any distributions pointing to this repository. Will create a "
51+
"standard structured APT publication."
52+
),
53+
default=False,
54+
required=False,
55+
)
56+
4757
publish_upstream_release_fields = serializers.BooleanField(
4858
help_text=_(
4959
"Previously, pulp_deb only synced the Release file fields codename and suite, now "
@@ -78,6 +88,7 @@ class AptRepositorySerializer(RepositorySerializer):
7888

7989
class Meta:
8090
fields = RepositorySerializer.Meta.fields + (
91+
"autopublish",
8192
"publish_upstream_release_fields",
8293
"signing_service",
8394
"signing_service_release_overrides",
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import pytest
2+
3+
from pulpcore.client.pulp_deb import (
4+
AptRepositorySyncURL,
5+
)
6+
7+
8+
@pytest.fixture
9+
def setup_autopublish(
10+
deb_get_fixture_server_url, deb_repository_factory, deb_remote_factory, deb_distribution_factory
11+
):
12+
"""Create remote, repo, publish settings, and distribution."""
13+
url = deb_get_fixture_server_url()
14+
remote = deb_remote_factory(url=url)
15+
repo = deb_repository_factory(autopublish=True)
16+
distribution = deb_distribution_factory(repository=repo)
17+
18+
return repo, remote, distribution
19+
20+
21+
@pytest.mark.parallel
22+
def test_01_sync(setup_autopublish, apt_repository_api, apt_publication_api, monitor_task):
23+
"""Assert that syncing the repository triggers auto-publish and auto-distribution."""
24+
repo, remote, distribution = setup_autopublish
25+
assert apt_publication_api.list(repository=repo.pulp_href).count == 0
26+
assert distribution.publication is None
27+
28+
# Sync the repository.
29+
repository_sync_data = AptRepositorySyncURL(remote=remote.pulp_href)
30+
sync_response = apt_repository_api.sync(repo.pulp_href, repository_sync_data)
31+
task = monitor_task(sync_response.task)
32+
33+
# Check that all the appropriate resources were created
34+
assert len(task.created_resources) > 1
35+
publications = apt_publication_api.list(repository=repo.pulp_href)
36+
assert publications.count == 1
37+
38+
# Sync the repository again. Since there should be no new repository version, there
39+
# should be no new publications or distributions either.
40+
sync_response = apt_repository_api.sync(repo.pulp_href, repository_sync_data)
41+
task = monitor_task(sync_response.task)
42+
43+
assert len(task.created_resources) == 0
44+
assert apt_publication_api.list(repository=repo.pulp_href).count == 1
45+
46+
47+
@pytest.mark.parallel
48+
def test_02_modify(
49+
setup_autopublish, apt_repository_api, apt_package_api, apt_publication_api, monitor_task
50+
):
51+
"""Assert that modifying the repository triggers auto-publish and auto-distribution."""
52+
repo, remote, distribution = setup_autopublish
53+
assert apt_publication_api.list(repository=repo.pulp_href).count == 0
54+
assert distribution.publication is None
55+
56+
# Modify the repository by adding a content unit
57+
content = apt_package_api.list().results[0].pulp_href
58+
59+
modify_response = apt_repository_api.modify(repo.pulp_href, {"add_content_units": [content]})
60+
task = monitor_task(modify_response.task)
61+
62+
# Check that all the appropriate resources were created
63+
assert len(task.created_resources) > 1
64+
publications = apt_publication_api.list(repository=repo.pulp_href)
65+
assert publications.count == 1

0 commit comments

Comments
 (0)