Merge "Fix BadResponseLength error when creating symlink" into stable/train

This commit is contained in:
Zuul 2019-12-27 07:48:07 +00:00 committed by Gerrit Code Review
commit 8fded7ad25
2 changed files with 22 additions and 5 deletions

View File

@ -209,7 +209,7 @@ from swift.common.request_helpers import get_sys_meta_prefix, \
check_path_header, get_container_update_override_key
from swift.common.swob import Request, HTTPBadRequest, HTTPTemporaryRedirect, \
HTTPException, HTTPConflict, HTTPPreconditionFailed, wsgi_quote, \
wsgi_unquote
wsgi_unquote, status_map
from swift.common.http import is_success, HTTP_NOT_FOUND
from swift.common.exceptions import LinkIterError
from swift.common.header_key_dict import HeaderKeyDict
@ -514,11 +514,15 @@ class SymlinkObjectContext(WSGIContext):
if self._get_status_int() == HTTP_NOT_FOUND:
raise HTTPConflict(
body='X-Symlink-Target does not exist',
request=req,
headers={
'Content-Type': 'text/plain',
'Content-Location': self._last_target_path})
if not is_success(self._get_status_int()):
return resp
with closing_if_possible(resp):
for chunk in resp:
pass
raise status_map[self._get_status_int()](request=req)
response_headers = HeaderKeyDict(self._response_headers)
# carry forward any etag update params (e.g. "slo_etag"), we'll append
# symlink_target_* params to this header after this method returns
@ -563,10 +567,8 @@ class SymlinkObjectContext(WSGIContext):
symlink_target_path, etag = _validate_and_prep_request_headers(req)
if etag:
resp = self._validate_etag_and_update_sysmeta(
self._validate_etag_and_update_sysmeta(
req, symlink_target_path, etag)
if resp is not None:
return resp
# N.B. TGT_ETAG_SYMLINK_HDR was converted as part of verifying it
symlink_usermeta_to_sysmeta(req.headers)
# Store info in container update that this object is a symlink.

View File

@ -228,6 +228,21 @@ class TestSymlinkMiddleware(TestSymlinkMiddlewareBase):
self.assertIn(('Content-Location', '/v1/a/c1/o'), headers)
self.assertIn(b'does not exist', body)
def test_symlink_simple_put_error(self):
self.app.register('HEAD', '/v1/a/c1/o',
swob.HTTPInternalServerError, {}, 'bad news')
req = Request.blank('/v1/a/c/symlink', method='PUT',
headers={
'X-Symlink-Target': 'c1/o',
'X-Symlink-Target-Etag': 'not-tgt-etag',
}, body='')
status, headers, body = self.call_sym(req)
self.assertEqual(status, '500 Internal Error')
# this is a PUT response; so if we have a content-length...
self.assertGreater(int(dict(headers)['Content-Length']), 0)
# ... we better have a body!
self.assertIn(b'Internal Error', body)
def test_symlink_put_with_prevalidated_etag(self):
self.app.register('PUT', '/v1/a/c/symlink', swob.HTTPCreated, {})
req = Request.blank('/v1/a/c/symlink', method='PUT', headers={