Use swift.backend_path from Swift/s3api to extract account/container
Still use PATH_INFO by default if s3api not enabled and swift.backend_path not available Depends-On: https://review.opendev.org/#/c/718086/ Change-Id: Ibb5fc6a717b9bc938aa86c4550d156fe93dae65c
This commit is contained in:
parent
c6b90ec56a
commit
ba22defb59
|
@ -298,7 +298,7 @@ class Swift(object):
|
||||||
env.get('swift.source') is not None):
|
env.get('swift.source') is not None):
|
||||||
return
|
return
|
||||||
|
|
||||||
path = urlparse.quote(env['PATH_INFO'])
|
path = urlparse.quote(env.get('swift.backend_path', env['PATH_INFO']))
|
||||||
method = env['REQUEST_METHOD']
|
method = env['REQUEST_METHOD']
|
||||||
headers = {}
|
headers = {}
|
||||||
for header in env:
|
for header in env:
|
||||||
|
|
|
@ -72,10 +72,13 @@ class TestSwift(tests_base.TestCase):
|
||||||
def start_response(*args):
|
def start_response(*args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_request(self, path, environ=None, headers=None):
|
||||||
|
return FakeRequest(path, environ=environ, headers=headers)
|
||||||
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
app = swift.Swift(FakeApp(), {})
|
app = swift.Swift(FakeApp(), {})
|
||||||
req = FakeRequest('/1.0/account/container/obj',
|
req = self.get_request('/1.0/account/container/obj',
|
||||||
environ={'REQUEST_METHOD': 'GET'})
|
environ={'REQUEST_METHOD': 'GET'})
|
||||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||||
resp = app(req.environ, self.start_response)
|
resp = app(req.environ, self.start_response)
|
||||||
self.assertEqual(["This string is 28 bytes long"], list(resp))
|
self.assertEqual(["This string is 28 bytes long"], list(resp))
|
||||||
|
@ -96,8 +99,8 @@ class TestSwift(tests_base.TestCase):
|
||||||
app = swift.Swift(FakeApp(),
|
app = swift.Swift(FakeApp(),
|
||||||
{"nonblocking_notify": "True",
|
{"nonblocking_notify": "True",
|
||||||
"send_queue_size": "1"})
|
"send_queue_size": "1"})
|
||||||
req = FakeRequest('/1.0/account/container/obj',
|
req = self.get_request('/1.0/account/container/obj',
|
||||||
environ={'REQUEST_METHOD': 'GET'})
|
environ={'REQUEST_METHOD': 'GET'})
|
||||||
with mock.patch('oslo_messaging.Notifier.info',
|
with mock.patch('oslo_messaging.Notifier.info',
|
||||||
side_effect=lambda *args, **kwargs: notified.set()
|
side_effect=lambda *args, **kwargs: notified.set()
|
||||||
) as notify:
|
) as notify:
|
||||||
|
@ -118,7 +121,7 @@ class TestSwift(tests_base.TestCase):
|
||||||
|
|
||||||
def test_put(self):
|
def test_put(self):
|
||||||
app = swift.Swift(FakeApp(body=['']), {})
|
app = swift.Swift(FakeApp(body=['']), {})
|
||||||
req = FakeRequest(
|
req = self.get_request(
|
||||||
'/1.0/account/container/obj',
|
'/1.0/account/container/obj',
|
||||||
environ={'REQUEST_METHOD': 'PUT',
|
environ={'REQUEST_METHOD': 'PUT',
|
||||||
'wsgi.input':
|
'wsgi.input':
|
||||||
|
@ -139,7 +142,7 @@ class TestSwift(tests_base.TestCase):
|
||||||
|
|
||||||
def test_post(self):
|
def test_post(self):
|
||||||
app = swift.Swift(FakeApp(body=['']), {})
|
app = swift.Swift(FakeApp(body=['']), {})
|
||||||
req = FakeRequest(
|
req = self.get_request(
|
||||||
'/1.0/account/container/obj',
|
'/1.0/account/container/obj',
|
||||||
environ={'REQUEST_METHOD': 'POST',
|
environ={'REQUEST_METHOD': 'POST',
|
||||||
'wsgi.input': six.moves.cStringIO('some other stuff')})
|
'wsgi.input': six.moves.cStringIO('some other stuff')})
|
||||||
|
@ -159,8 +162,8 @@ class TestSwift(tests_base.TestCase):
|
||||||
|
|
||||||
def test_head(self):
|
def test_head(self):
|
||||||
app = swift.Swift(FakeApp(body=['']), {})
|
app = swift.Swift(FakeApp(body=['']), {})
|
||||||
req = FakeRequest('/1.0/account/container/obj',
|
req = self.get_request('/1.0/account/container/obj',
|
||||||
environ={'REQUEST_METHOD': 'HEAD'})
|
environ={'REQUEST_METHOD': 'HEAD'})
|
||||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||||
list(app(req.environ, self.start_response))
|
list(app(req.environ, self.start_response))
|
||||||
self.assertEqual(1, len(notify.call_args_list))
|
self.assertEqual(1, len(notify.call_args_list))
|
||||||
|
@ -176,8 +179,8 @@ class TestSwift(tests_base.TestCase):
|
||||||
def test_bogus_request(self):
|
def test_bogus_request(self):
|
||||||
"""Test even for arbitrary request method, this will still work."""
|
"""Test even for arbitrary request method, this will still work."""
|
||||||
app = swift.Swift(FakeApp(body=['']), {})
|
app = swift.Swift(FakeApp(body=['']), {})
|
||||||
req = FakeRequest('/1.0/account/container/obj',
|
req = self.get_request('/1.0/account/container/obj',
|
||||||
environ={'REQUEST_METHOD': 'BOGUS'})
|
environ={'REQUEST_METHOD': 'BOGUS'})
|
||||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||||
list(app(req.environ, self.start_response))
|
list(app(req.environ, self.start_response))
|
||||||
self.assertEqual(1, len(notify.call_args_list))
|
self.assertEqual(1, len(notify.call_args_list))
|
||||||
|
@ -192,8 +195,8 @@ class TestSwift(tests_base.TestCase):
|
||||||
|
|
||||||
def test_get_container(self):
|
def test_get_container(self):
|
||||||
app = swift.Swift(FakeApp(), {})
|
app = swift.Swift(FakeApp(), {})
|
||||||
req = FakeRequest('/1.0/account/container',
|
req = self.get_request('/1.0/account/container',
|
||||||
environ={'REQUEST_METHOD': 'GET'})
|
environ={'REQUEST_METHOD': 'GET'})
|
||||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||||
list(app(req.environ, self.start_response))
|
list(app(req.environ, self.start_response))
|
||||||
self.assertEqual(1, len(notify.call_args_list))
|
self.assertEqual(1, len(notify.call_args_list))
|
||||||
|
@ -210,8 +213,8 @@ class TestSwift(tests_base.TestCase):
|
||||||
|
|
||||||
def test_no_metadata_headers(self):
|
def test_no_metadata_headers(self):
|
||||||
app = swift.Swift(FakeApp(), {})
|
app = swift.Swift(FakeApp(), {})
|
||||||
req = FakeRequest('/1.0/account/container',
|
req = self.get_request('/1.0/account/container',
|
||||||
environ={'REQUEST_METHOD': 'GET'})
|
environ={'REQUEST_METHOD': 'GET'})
|
||||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||||
list(app(req.environ, self.start_response))
|
list(app(req.environ, self.start_response))
|
||||||
self.assertEqual(1, len(notify.call_args_list))
|
self.assertEqual(1, len(notify.call_args_list))
|
||||||
|
@ -230,11 +233,11 @@ class TestSwift(tests_base.TestCase):
|
||||||
app = swift.Swift(FakeApp(), {
|
app = swift.Swift(FakeApp(), {
|
||||||
'metadata_headers': 'X_VAR1, x-var2, x-var3, token'
|
'metadata_headers': 'X_VAR1, x-var2, x-var3, token'
|
||||||
})
|
})
|
||||||
req = FakeRequest('/1.0/account/container',
|
req = self.get_request('/1.0/account/container',
|
||||||
environ={'REQUEST_METHOD': 'GET'},
|
environ={'REQUEST_METHOD': 'GET'},
|
||||||
headers={'X_VAR1': 'value1',
|
headers={'X_VAR1': 'value1',
|
||||||
'X_VAR2': 'value2',
|
'X_VAR2': 'value2',
|
||||||
'TOKEN': 'token'})
|
'TOKEN': 'token'})
|
||||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||||
list(app(req.environ, self.start_response))
|
list(app(req.environ, self.start_response))
|
||||||
self.assertEqual(1, len(notify.call_args_list))
|
self.assertEqual(1, len(notify.call_args_list))
|
||||||
|
@ -258,9 +261,9 @@ class TestSwift(tests_base.TestCase):
|
||||||
'metadata_headers': 'unicode'
|
'metadata_headers': 'unicode'
|
||||||
})
|
})
|
||||||
uni = u'\xef\xbd\xa1\xef\xbd\xa5'
|
uni = u'\xef\xbd\xa1\xef\xbd\xa5'
|
||||||
req = FakeRequest('/1.0/account/container',
|
req = self.get_request('/1.0/account/container',
|
||||||
environ={'REQUEST_METHOD': 'GET'},
|
environ={'REQUEST_METHOD': 'GET'},
|
||||||
headers={'UNICODE': uni})
|
headers={'UNICODE': uni})
|
||||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||||
list(app(req.environ, self.start_response))
|
list(app(req.environ, self.start_response))
|
||||||
self.assertEqual(1, len(notify.call_args_list))
|
self.assertEqual(1, len(notify.call_args_list))
|
||||||
|
@ -281,8 +284,8 @@ class TestSwift(tests_base.TestCase):
|
||||||
app = swift.Swift(FakeApp(), {
|
app = swift.Swift(FakeApp(), {
|
||||||
'metadata_headers': 'x-var3'
|
'metadata_headers': 'x-var3'
|
||||||
})
|
})
|
||||||
req = FakeRequest('/1.0/account/container',
|
req = self.get_request('/1.0/account/container',
|
||||||
environ={'REQUEST_METHOD': 'GET'})
|
environ={'REQUEST_METHOD': 'GET'})
|
||||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||||
list(app(req.environ, self.start_response))
|
list(app(req.environ, self.start_response))
|
||||||
self.assertEqual(1, len(notify.call_args_list))
|
self.assertEqual(1, len(notify.call_args_list))
|
||||||
|
@ -316,8 +319,8 @@ class TestSwift(tests_base.TestCase):
|
||||||
def test_emit_event_fail(self, mocked_func):
|
def test_emit_event_fail(self, mocked_func):
|
||||||
mocked_func.side_effect = Exception("a exception")
|
mocked_func.side_effect = Exception("a exception")
|
||||||
app = swift.Swift(FakeApp(body=["test"]), {})
|
app = swift.Swift(FakeApp(body=["test"]), {})
|
||||||
req = FakeRequest('/1.0/account/container',
|
req = self.get_request('/1.0/account/container',
|
||||||
environ={'REQUEST_METHOD': 'GET'})
|
environ={'REQUEST_METHOD': 'GET'})
|
||||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||||
resp = list(app(req.environ, self.start_response))
|
resp = list(app(req.environ, self.start_response))
|
||||||
self.assertEqual(0, len(notify.call_args_list))
|
self.assertEqual(0, len(notify.call_args_list))
|
||||||
|
@ -325,8 +328,8 @@ class TestSwift(tests_base.TestCase):
|
||||||
|
|
||||||
def test_reseller_prefix(self):
|
def test_reseller_prefix(self):
|
||||||
app = swift.Swift(FakeApp(), {})
|
app = swift.Swift(FakeApp(), {})
|
||||||
req = FakeRequest('/1.0/AUTH_account/container/obj',
|
req = self.get_request('/1.0/AUTH_account/container/obj',
|
||||||
environ={'REQUEST_METHOD': 'GET'})
|
environ={'REQUEST_METHOD': 'GET'})
|
||||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||||
list(app(req.environ, self.start_response))
|
list(app(req.environ, self.start_response))
|
||||||
self.assertEqual(1, len(notify.call_args_list))
|
self.assertEqual(1, len(notify.call_args_list))
|
||||||
|
@ -459,3 +462,14 @@ class TestSwift(tests_base.TestCase):
|
||||||
app.ignore_projects)
|
app.ignore_projects)
|
||||||
warning.assert_called_once_with(
|
warning.assert_called_once_with(
|
||||||
"fail to find project '%s' in keystone", "gnocchi")
|
"fail to find project '%s' in keystone", "gnocchi")
|
||||||
|
|
||||||
|
|
||||||
|
class TestSwiftS3Api(TestSwift):
|
||||||
|
|
||||||
|
def get_request(self, path, environ=None, headers=None):
|
||||||
|
# Add Swift Path in environ, provided by swift s3api middleware
|
||||||
|
environ['swift.backend_path'] = path
|
||||||
|
# Emulate S3 api PATH_INFO by removing /v1 and account parts
|
||||||
|
path = '/' + path.split('/', 3)[-1]
|
||||||
|
|
||||||
|
return FakeRequest(path, environ=environ, headers=headers)
|
||||||
|
|
Loading…
Reference in New Issue