Skip to content

Commit

Permalink
Make auto-distribute feature more intuitive
Browse files Browse the repository at this point in the history
backports: #9039
https://pulp.plan.io/issues/9039

fixes #9059

(cherry picked from commit 2cc9804)
  • Loading branch information
David Davis authored and daviddavis committed Jul 13, 2021
1 parent 8f44267 commit c28d266
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES/9059.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed the behavior of setting "repository" on a distribution for publication-based plugins.
(backported from #9039)
11 changes: 10 additions & 1 deletion pulpcore/app/models/publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ def delete(self, **kwargs):
Deletes the Task.created_resource when complete is False.
"""
with transaction.atomic():
# invalidate cache
if settings.CACHE_ENABLED:
# Find any publications being served directly
base_paths = self.distribution_set.values_list("base_path", flat=True)
# Find any publications being served indirectly by auto-distribute feature
versions = self.repository.versions.all()
pubs = Publication.objects.filter(repository_version__in=versions, complete=True)
publication = pubs.latest("repository_version", "-pulp_created")
publication = pubs.latest("repository_version", "pulp_created")
if self.pk == publication.pk:
base_paths |= self.repository.distributions.values_list("base_path", flat=True)
# Invalidate cache for all distributions serving this publication
Expand Down Expand Up @@ -183,6 +184,14 @@ def __exit__(self, exc_type, exc_val, exc_tb):
self.delete()
raise

# invalidate cache
if settings.CACHE_ENABLED:
base_paths = Distribution.objects.filter(
repository=self.repository_version.repository
).values_list("base_path", flat=True)
if base_paths:
Cache().delete(base_key=base_paths)


class PublishedArtifact(BaseModel):
"""
Expand Down
10 changes: 8 additions & 2 deletions pulpcore/content/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,18 +466,24 @@ def check_permit_blocking():
def get_latest_publication_or_version_blocking():
nonlocal repo_version
nonlocal publication
repo_version = repository.latest_version()

# Search for publication serving the closest latest version
if not publication:
try:
versions = repository.versions.all()
publications = Publication.objects.filter(
repository_version__in=versions, complete=True
)
publication = publications.latest("repository_version", "-pulp_created")
publication = publications.select_related("repository_version").latest(
"repository_version", "pulp_created"
)
repo_version = publication.repository_version
except ObjectDoesNotExist:
pass

if not repo_version:
repo_version = repository.latest_version()

await loop.run_in_executor(None, get_latest_publication_or_version_blocking)

if publication:
Expand Down

0 comments on commit c28d266

Please sign in to comment.