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

[PR #1713/ae2c2f6d backport][2.21] Handles an exception for non-existing repository #1719

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/1703.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed an issue causing an HTTP 500 error when a GET request for a non-existing
blob was made to a distribution with only a `repository_version` set.
6 changes: 4 additions & 2 deletions pulp_container/app/registry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,15 @@ def get_drv_pull(self, path):
except models.ContainerDistribution.DoesNotExist:
# get a pull-through cache distribution whose base_path is a substring of the path
return self.get_pull_through_drv(path)
if distribution.repository:
repository = distribution.repository
if repository:
repository_version = distribution.repository.latest_version()
elif distribution.repository_version:
repository_version = distribution.repository_version
repository = repository_version.repository
else:
raise RepositoryNotFound(name=path)
return distribution, distribution.repository, repository_version
return distribution, repository, repository_version

def get_pull_through_drv(self, path):
pull_through_cache_distribution = (
Expand Down
14 changes: 13 additions & 1 deletion pulp_container/tests/functional/api/test_pull_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
REGISTRY_V2_REPO_HELLO_WORLD,
PULP_HELLO_WORLD_LINUX_TAG,
)
from pulp_container.constants import EMPTY_BLOB, MEDIA_TYPE
from pulp_container.constants import EMPTY_BLOB, EMPTY_JSON, MEDIA_TYPE

from pulpcore.client.pulp_container import (
ContainerContainerDistribution,
Expand Down Expand Up @@ -279,6 +279,18 @@ def test_pull_nonexistent_image(self):
with self.assertRaises(exceptions.CalledProcessError):
registry.pull(local_url)

def test_pull_nonexistent_blob(self):
"""
Verify that a GET request to a nonexistent BLOB will be properly handled
instead of outputting a stacktrace.
"""
blob_path = "/v2/{}/blobs/{}".format(self.distribution_with_repo.base_path, EMPTY_JSON)
non_existing_blob_url = urljoin(self.cfg.get_base_url(), blob_path)

auth = get_auth_for_url(non_existing_blob_url)
content_response = requests.get(non_existing_blob_url, auth=auth)
assert content_response.status_code, 404


class PullOnDemandContentTestCase(unittest.TestCase):
"""Verify whether on-demand served images by Pulp can be pulled."""
Expand Down