Skip to content

Commit

Permalink
Handles a PushRepository.DoesNotExist exception
Browse files Browse the repository at this point in the history
fixes: #1712
  • Loading branch information
git-hyagi committed Aug 5, 2024
1 parent e2a1003 commit b4501fa
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
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
17 changes: 13 additions & 4 deletions pulp_container/app/registry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,19 @@ 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}
)
except models.ContainerPushRepository.DoesNotExist:
raise RepositoryInvalid(name=path, message="Repository is read-only.")

try:
distribution = serializers.ContainerDistributionSerializer.get_or_create(
{"base_path": path, "name": path}, {"repository": get_url(repository)}
)
except models.ContainerDistribution.DoesNotExist:
raise RepositoryInvalid(name=path, message="Repository is ready-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

0 comments on commit b4501fa

Please sign in to comment.