Skip to content

Commit

Permalink
Add support for automatic publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
dralley committed Apr 6, 2021
1 parent d55f1c2 commit 23bb55c
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES/7626.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for automatic publishing and distributing.
1 change: 1 addition & 0 deletions CHANGES/plugin_api/7626.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added a new callback method to ``Repository`` named ``on_new_version()``, which runs when a new repository version has been created. This can be used for e.g. automatically publishing or distributing a new repository version after it has been created.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Migration(migrations.Migration):
('content_guard', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.ContentGuard')),
('publication', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.Publication')),
('remote', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.Remote')),
('repository', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.Repository')),
('repository', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.Repository', related_name='distributions')),
('repository_version', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.RepositoryVersion')),
],
options={
Expand Down
4 changes: 3 additions & 1 deletion pulpcore/app/models/publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ class Distribution(MasterModel):
content_guard = models.ForeignKey(ContentGuard, null=True, on_delete=models.SET_NULL)
publication = models.ForeignKey(Publication, null=True, on_delete=models.SET_NULL)
remote = models.ForeignKey(Remote, null=True, on_delete=models.SET_NULL)
repository = models.ForeignKey(Repository, null=True, on_delete=models.SET_NULL)
repository = models.ForeignKey(
Repository, null=True, on_delete=models.SET_NULL, related_name="distributions"
)
repository_version = models.ForeignKey(RepositoryVersion, null=True, on_delete=models.SET_NULL)

def content_handler(self, path):
Expand Down
15 changes: 13 additions & 2 deletions pulpcore/app/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from django.db import models, transaction
from django.urls import reverse

from django.contrib.postgres.fields import JSONField

from pulpcore.app.util import batch_qs, get_view_name_for_model
from pulpcore.constants import ALL_KNOWN_CONTENT_CHECKSUMS
from pulpcore.download.factory import DownloaderFactory
Expand All @@ -21,8 +23,6 @@
from .content import Artifact, Content
from .task import CreatedResource, Task

from django.contrib.postgres.fields import JSONField


_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -59,6 +59,16 @@ class Repository(MasterModel):
class Meta:
verbose_name_plural = "repositories"

def on_new_version(self, version):
"""Called when new repository versions are created.
Subclasses are expected to override this to do useful things.
Args:
version: The new repository version.
"""
pass

def save(self, *args, **kwargs):
"""
Saves Repository model and creates an initial repository version.
Expand Down Expand Up @@ -913,6 +923,7 @@ def __exit__(self, exc_type, exc_value, traceback):
self.repository.save()
self.save()
self._compute_counts()
repository.on_new_version(self)
except Exception:
self.delete()
raise
Expand Down
4 changes: 3 additions & 1 deletion pulpcore/plugin/stages/artifact_stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ def _add_to_pending(coro):
# Set to None if stage is shutdown.
content_get_task = _add_to_pending(content_iterator.__anext__())

with ProgressReport(message="Downloading Artifacts", code="downloading.artifacts") as pb:
with ProgressReport(
message="Downloading Artifacts", code="sync.downloading.artifacts"
) as pb:
try:
while pending:
done, pending = await asyncio.wait(pending, return_when=asyncio.FIRST_COMPLETED)
Expand Down
4 changes: 4 additions & 0 deletions pulpcore/plugin/stages/declarative_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def pipeline_stages(self, new_version):
def create(self):
"""
Perform the work. This is the long-blocking call where all syncing occurs.
Returns: The created RepositoryVersion or None if it represents no change from the latest.
"""
with tempfile.TemporaryDirectory(dir="."):
with self.repository.new_version() as new_version:
Expand All @@ -145,3 +147,5 @@ def create(self):
stages.append(EndStage())
pipeline = create_pipeline(stages)
loop.run_until_complete(pipeline)

return new_version if new_version.complete else None
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_01_create(self):

self.publication = self.client.get(self.publication["pulp_href"])

# content_guard is the only parameter unset.
# content_guard and repository parameters unset.
for key, val in self.distribution.items():
if key in ["content_guard", "repository"]:
self.assertIsNone(val, self.distribution)
Expand Down

0 comments on commit 23bb55c

Please sign in to comment.