Skip to content

Commit

Permalink
Handles a PushRepository.DoesNotExist exception
Browse files Browse the repository at this point in the history
fixes: pulp#1712
  • Loading branch information
git-hyagi committed Aug 1, 2024
1 parent e2a1003 commit 92876c3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES/1712.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Resolved an issue that caused an HTTP 500 error when attempting to push an image with the same name
as an existing regular 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 a content with the same name of an existing
"regular" repository will fail.

!!! note

Expand Down
11 changes: 10 additions & 1 deletion pulp_container/app/registry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,16 @@ 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})
try:
repository = serializers.ContainerPushRepositorySerializer.get_or_create(
{"name": path}
)
except models.ContainerPushRepository.DoesNotExist:
raise RepositoryInvalid(
name=path,
message='Cannot create "' + path + '" push repository, another repository with '
"the same name already exists.",
)
distribution = serializers.ContainerDistributionSerializer.get_or_create(
{"base_path": path, "name": path}, {"repository": get_url(repository)}
)
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 92876c3

Please sign in to comment.