Create unittest runner env for storlet_middleware
This patch enables to run a few unitttest for storlet_middleware for OpenStack Swift with similer way of native Swift middleware in tox environment. N.B. To enable this, this patch changes a few things in the setup.cfg in the top of directories but this doesn't care whole things for python software packaging so... TODO: Review and Fix setup.cfg to be correct packaging info Change-Id: I8210af17300c7f3d664d858d54fd804dcd300fae
This commit is contained in:
@@ -22,7 +22,8 @@ classifier =
|
|||||||
|
|
||||||
[files]
|
[files]
|
||||||
packages =
|
packages =
|
||||||
storlets
|
storlet_middleware
|
||||||
|
storlet_gateway
|
||||||
|
|
||||||
[build_sphinx]
|
[build_sphinx]
|
||||||
source-dir = doc/source
|
source-dir = doc/source
|
||||||
|
1
storlet_gateway
Symbolic link
1
storlet_gateway
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
Engine/swift/storlet_gateway
|
1
storlet_middleware
Symbolic link
1
storlet_middleware
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
Engine/swift/storlet_middleware
|
74
tests/unit/test_storlet_middleware.py
Normal file
74
tests/unit/test_storlet_middleware.py
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
# Copyright (c) 2010-2015 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.
|
||||||
|
|
||||||
|
from os.path import join
|
||||||
|
from storlet_middleware import storlet_handler
|
||||||
|
from swift.common.swob import Request
|
||||||
|
from swift.common.swob import Response
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_CONFIG = {
|
||||||
|
'storlet_container': 'storlet',
|
||||||
|
'storlet_dependency': 'dependency',
|
||||||
|
'storlet_timeout': '40',
|
||||||
|
'storlet_gateway_module':
|
||||||
|
'storlet_gateway.storlet_stub_gateway:StorletStubBase',
|
||||||
|
'storlet_gateway_conf': '/etc/swift/storlet_stub_gateway.conf',
|
||||||
|
'execution_server': 'proxy'}
|
||||||
|
|
||||||
|
|
||||||
|
class FakeApp(object):
|
||||||
|
def __call__(self, env, start_response):
|
||||||
|
req = Request(env)
|
||||||
|
return Response(request=req, body='FAKE APP')(
|
||||||
|
env, start_response)
|
||||||
|
|
||||||
|
|
||||||
|
class TestStorletsMiddleware(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.got_statuses = []
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_app(self, app, global_conf, **local_conf):
|
||||||
|
factory = storlet_handler.filter_factory(global_conf, **local_conf)
|
||||||
|
return factory(app)
|
||||||
|
|
||||||
|
def start_response(self, status, headers):
|
||||||
|
self.got_statuses.append(status)
|
||||||
|
|
||||||
|
def test_load_app(self):
|
||||||
|
try:
|
||||||
|
self.get_app(FakeApp(), DEFAULT_CONFIG)
|
||||||
|
except Exception:
|
||||||
|
self.fail('Application loading got an error')
|
||||||
|
|
||||||
|
def test_GET_without_storlets(self):
|
||||||
|
def basic_get(path):
|
||||||
|
req = Request.blank(path, environ={'REQUEST_METHOD': 'GET'})
|
||||||
|
app = self.get_app(FakeApp(), DEFAULT_CONFIG)
|
||||||
|
resp = app(req.environ, self.start_response)
|
||||||
|
self.assertEqual('200 OK', self.got_statuses[-1])
|
||||||
|
self.assertEqual(resp, ['FAKE APP'])
|
||||||
|
|
||||||
|
for target in ('AUTH_a', 'AUTH_a/c', 'AUTH_a/c/o'):
|
||||||
|
path = join('/', 'v1', target)
|
||||||
|
basic_get(path)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
@@ -1,27 +0,0 @@
|
|||||||
'''-------------------------------------------------------------------------
|
|
||||||
Copyright IBM Corp. 2015, 2015 All Rights Reserved
|
|
||||||
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.
|
|
||||||
-------------------------------------------------------------------------'''
|
|
||||||
|
|
||||||
'''
|
|
||||||
@author: cdoron
|
|
||||||
'''
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
subprocess.call(["pwd"])
|
|
||||||
|
|
||||||
'''------------------------------------------------------------------------'''
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
5
tox.ini
5
tox.ini
@@ -8,7 +8,10 @@ usedevelop = True
|
|||||||
install_command = pip install -U {opts} {packages}
|
install_command = pip install -U {opts} {packages}
|
||||||
setenv =
|
setenv =
|
||||||
VIRTUAL_ENV={envdir}
|
VIRTUAL_ENV={envdir}
|
||||||
deps = -r{toxinidir}/test-requirements.txt
|
deps =
|
||||||
|
-r{toxinidir}/test-requirements.txt
|
||||||
|
PyECLib==1.0.7
|
||||||
|
https://launchpad.net/swift/kilo/2.3.0/+download/swift-2.3.0.tar.gz
|
||||||
#commands = python setup.py test --slowest --testr-args='{posargs}'
|
#commands = python setup.py test --slowest --testr-args='{posargs}'
|
||||||
commands = ./.unittests
|
commands = ./.unittests
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user