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 2, 2021
1 parent d55f1c2 commit 65fdab8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 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 functest_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ dynaconf
pulp-smash @ git+https://github.com/pulp/pulp-smash.git
pulpcore-client
pulp-file-client
pulp-certguard
pytest
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 65fdab8

Please sign in to comment.