
This attempts to import openstack/swift3 package into swift upstream repository, namespace. This is almost simple porting except following items. 1. Rename swift3 namespace to swift.common.middleware.s3api 1.1 Rename also some conflicted class names (e.g. Request/Response) 2. Port unittests to test/unit/s3api dir to be able to run on the gate. 3. Port functests to test/functional/s3api and setup in-process testing 4. Port docs to doc dir, then address the namespace change. 5. Use get_logger() instead of global logger instance 6. Avoid global conf instance Ex. fix various minor issue on those steps (e.g. packages, dependencies, deprecated things) The details and patch references in the work on feature/s3api are listed at https://trello.com/b/ZloaZ23t/s3api (completed board) Note that, because this is just a porting, no new feature is developed since the last swift3 release, and in the future work, Swift upstream may continue to work on remaining items for further improvements and the best compatibility of Amazon S3. Please read the new docs for your deployment and keep track to know what would be changed in the future releases. Change-Id: Ib803ea89cfee9a53c429606149159dd136c036fd Co-Authored-By: Thiago da Silva <thiago@redhat.com> Co-Authored-By: Tim Burke <tim.burke@gmail.com>
81 lines
3.6 KiB
Python
81 lines
3.6 KiB
Python
# Copyright (c) 2014 OpenStack Foundation
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
# implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import unittest
|
|
|
|
from swift.common.swob import Response
|
|
from swift.common.utils import HeaderKeyDict
|
|
from swift.common.middleware.s3api.s3response import S3Response
|
|
from swift.common.middleware.s3api.utils import sysmeta_prefix
|
|
|
|
|
|
class TestResponse(unittest.TestCase):
|
|
def test_from_swift_resp_slo(self):
|
|
for expected, header_vals in \
|
|
((True, ('true', '1')), (False, ('false', 'ugahhh', None))):
|
|
for val in header_vals:
|
|
resp = Response(headers={'X-Static-Large-Object': val})
|
|
s3resp = S3Response.from_swift_resp(resp)
|
|
self.assertEqual(expected, s3resp.is_slo)
|
|
|
|
def test_response_s3api_sysmeta_headers(self):
|
|
for _server_type in ('object', 'container'):
|
|
swift_headers = HeaderKeyDict(
|
|
{sysmeta_prefix(_server_type) + 'test': 'ok'})
|
|
resp = Response(headers=swift_headers)
|
|
s3resp = S3Response.from_swift_resp(resp)
|
|
self.assertEqual(swift_headers, s3resp.sysmeta_headers)
|
|
|
|
def test_response_s3api_sysmeta_headers_ignore_other_sysmeta(self):
|
|
for _server_type in ('object', 'container'):
|
|
swift_headers = HeaderKeyDict(
|
|
# sysmeta not leading sysmeta_prefix even including s3api word
|
|
{'x-%s-sysmeta-test-s3api' % _server_type: 'ok',
|
|
sysmeta_prefix(_server_type) + 'test': 'ok'})
|
|
resp = Response(headers=swift_headers)
|
|
s3resp = S3Response.from_swift_resp(resp)
|
|
expected_headers = HeaderKeyDict(
|
|
{sysmeta_prefix(_server_type) + 'test': 'ok'})
|
|
self.assertEqual(expected_headers, s3resp.sysmeta_headers)
|
|
|
|
def test_response_s3api_sysmeta_from_swift3_sysmeta(self):
|
|
for _server_type in ('object', 'container'):
|
|
# swift could return older swift3 sysmeta
|
|
swift_headers = HeaderKeyDict(
|
|
{('x-%s-sysmeta-swift3-' % _server_type) + 'test': 'ok'})
|
|
resp = Response(headers=swift_headers)
|
|
s3resp = S3Response.from_swift_resp(resp)
|
|
expected_headers = HeaderKeyDict(
|
|
{sysmeta_prefix(_server_type) + 'test': 'ok'})
|
|
# but Response class should translates as s3api sysmeta
|
|
self.assertEqual(expected_headers, s3resp.sysmeta_headers)
|
|
|
|
def test_response_swift3_sysmeta_does_not_overwrite_s3api_sysmeta(self):
|
|
for _server_type in ('object', 'container'):
|
|
# same key name except sysmeta prefix
|
|
swift_headers = HeaderKeyDict(
|
|
{('x-%s-sysmeta-swift3-' % _server_type) + 'test': 'ng',
|
|
sysmeta_prefix(_server_type) + 'test': 'ok'})
|
|
resp = Response(headers=swift_headers)
|
|
s3resp = S3Response.from_swift_resp(resp)
|
|
expected_headers = HeaderKeyDict(
|
|
{sysmeta_prefix(_server_type) + 'test': 'ok'})
|
|
# but only s3api sysmeta remains in the response sysmeta_headers
|
|
self.assertEqual(expected_headers, s3resp.sysmeta_headers)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|