Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handles a PushRepository.DoesNotExist exception #1727

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES/1712.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed an HTTP 500 error returned when pushing an image with the same name as the name of an existing
read-only repository.
3 changes: 2 additions & 1 deletion docs/user/guides/push-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ X-Frame-Options: SAMEORIGIN
!!! note

Content is pushed to a push repository type. A push repository does not support mirroring of the
remote content via the Pulp API.
remote content via the Pulp API. Trying to push content with the same name as an existing
"regular" repository will fail.

!!! note

Expand Down
24 changes: 17 additions & 7 deletions pulp_container/app/registry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from urllib.parse import urljoin, urlparse, urlunparse, parse_qs, urlencode
from tempfile import NamedTemporaryFile

from django.core.exceptions import ObjectDoesNotExist
from django.core.files.storage import default_storage as storage
from django.core.files.base import ContentFile, File
from django.db import IntegrityError, transaction
Expand Down Expand Up @@ -320,9 +321,13 @@ def get_pull_through_drv(self, path):
upstream_name = path.split(pull_through_cache_distribution.base_path, maxsplit=1)[1].strip(
"/"
)
pull_through_remote = models.ContainerPullThroughRemote.objects.get(
pk=pull_through_cache_distribution.remote_id
)
try:
pull_through_remote = models.ContainerPullThroughRemote.objects.get(
pk=pull_through_cache_distribution.remote_id
)
except ObjectDoesNotExist:
raise RepositoryNotFound(name=path)

if not filter_resource(
upstream_name, pull_through_remote.includes, pull_through_remote.excludes
):
Expand Down Expand Up @@ -392,10 +397,15 @@ def get_dr_push(self, request, path, create=False):

def create_dr(self, path, request):
with transaction.atomic():
repository = serializers.ContainerPushRepositorySerializer.get_or_create({"name": path})
distribution = serializers.ContainerDistributionSerializer.get_or_create(
{"base_path": path, "name": path}, {"repository": get_url(repository)}
)
try:
repository = serializers.ContainerPushRepositorySerializer.get_or_create(
{"name": path}
)
distribution = serializers.ContainerDistributionSerializer.get_or_create(
{"base_path": path, "name": path}, {"repository": get_url(repository)}
)
except ObjectDoesNotExist:
raise RepositoryInvalid(name=path, message="Repository is read-only.")

if distribution.repository:
dist_repository = distribution.repository.cast()
Expand Down
21 changes: 21 additions & 0 deletions pulp_container/tests/functional/api/test_push_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
)

from pulpcore.client.pulp_container import (
ContainerContainerRepository,
ContentManifestsApi,
ContentTagsApi,
DistributionsContainerApi,
Expand Down Expand Up @@ -394,6 +395,26 @@ def test_push_matching_username(
add_to_cleanup(container_namespace_api, distribution.namespace)


def test_push_to_existing_regular_repository(
container_repository_api,
gen_object_with_cleanup,
local_registry,
registry_client,
):
"""
Test the push to an existing non-push repository.

It should fail to create a new push repository.
"""
gen_object_with_cleanup(container_repository_api, ContainerContainerRepository(name="foo"))
image_path = f"{REGISTRY_V2_REPO_PULP}:manifest_a"
local_url = "foo:1.0"

registry_client.pull(image_path)
with pytest.raises(CalledProcessError):
local_registry.tag_and_push(image_path, local_url)


class PushManifestListTestCase(PulpTestCase, rbac_base.BaseRegistryTest):
"""A test case that verifies if a container client can push manifest lists to the registry."""

Expand Down