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 #556/df24d163 backport][2.8] Return a concise message exception on 500 in case file is missing on the FS. #612

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
1 change: 1 addition & 0 deletions CHANGES/555.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Return a more concise message exception on 500 during image pull when content is missing on the FS.
13 changes: 6 additions & 7 deletions pulp_container/app/registry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import logging
import os
from gettext import gettext as _

from concurrent.futures import ThreadPoolExecutor

Expand Down Expand Up @@ -70,17 +71,15 @@ async def _dispatch(file, headers):
The :class:`aiohttp.web.FileResponse` for the file.

"""
path = os.path.join(settings.MEDIA_ROOT, file.name)
if not os.path.exists(path):
raise Exception(_("Expected path '{}' is not found").format(path))

full_headers = MultiDict()

full_headers["Content-Type"] = headers["Content-Type"]
full_headers["Docker-Content-Digest"] = headers["Docker-Content-Digest"]
full_headers["Docker-Distribution-API-Version"] = "registry/2.0"
full_headers["Content-Length"] = str(file.size)
full_headers["Content-Disposition"] = "attachment; filename={n}".format(
n=os.path.basename(file.name)
)

path = os.path.join(settings.MEDIA_ROOT, file.name)
file_response = web.FileResponse(path, headers=full_headers)
return file_response

Expand Down Expand Up @@ -133,7 +132,7 @@ def get_tag_blocking():
and tag.tagged_manifest.media_type not in accepted_media_types
):
log.warn(
"OCI format found, but the client only accepts {accepted_media_types}.".format(
_("OCI format found, but the client only accepts {accepted_media_types}.").format(
accepted_media_types=accepted_media_types
)
)
Expand Down
12 changes: 11 additions & 1 deletion pulp_container/app/schema_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import itertools
import json
import logging

from gettext import gettext as _

from collections import namedtuple
from jwkest import jws, jwk, ecc

Expand Down Expand Up @@ -323,4 +326,11 @@ def _get_manifest_dict(manifest):


def _get_dict(artifact):
return json.load(artifact.file)
try:
return json.load(artifact.file)
except FileNotFoundError:
raise Exception(
_(
"Expected manifest file 'sha256:{}' needed for schema conversion is not found"
).format(artifact.sha256)
)