Merge "Use Python 3 by default to run storlet applications"

This commit is contained in:
Zuul 2020-01-17 10:04:38 +00:00 committed by Gerrit Code Review
commit 2af9e9608d
8 changed files with 24 additions and 18 deletions

View File

@ -49,11 +49,13 @@ class MultiInputMIMEStorlet(object):
input_file.close()
if in_files:
# in_files still have items
out_files[0].write('\n--%s\n' % mime_boundary)
out_files[0].write(
('\n--%s\n' % mime_boundary).encode('utf-8'))
else:
# this is the end of input_files so the boundary should end
# the content
out_files[0].write('\n--%s--' % mime_boundary)
out_files[0].write(
('\n--%s--' % mime_boundary).encode('utf-8'))
self.logger.debug('Complete')
out_files[0].close()

View File

@ -40,7 +40,8 @@ class TestStorlet(object):
if op == 'print':
for key, value in params.items():
out_files[0].write('%s %s\n' % (key, value))
out_files[0].write(
('%s %s\n' % (key, value)).encode('utf-8'))
if op == 'hold':
time.sleep(100000)

View File

@ -297,7 +297,10 @@ function install_storlets_code {
# Also install code to library directory so that we can import them
# from docker container.
sudo mkdir -p -m 755 /usr/local/lib/storlets/python
pip_install . -t /usr/local/lib/storlets/python --no-compile
# NOTE(takashi): We need --no-deps to avoid enum34 installed in py 2 env,
# which causes failure in py3 execution.
pip_install . -t /usr/local/lib/storlets/python --no-compile --no-deps
for bin_file in storlets-daemon storlets-daemon-factory ; do
sudo cp `which ${bin_file}` /usr/local/libexec/storlets/
done

View File

@ -104,13 +104,12 @@ class StorletDaemonFactory(SBusServer):
def get_python_args(self, daemon_language, storlet_path, storlet_name,
pool_size, uds_path, log_level,
daemon_language_version):
daemon_language_version = daemon_language_version or 2
if int(float(daemon_language_version)) == 3:
daemon_language_version = DEFAULT_PY3
else:
# TODO(takashi): Switch default python version to 3 once we drop
# python2 support.
daemon_language_version = daemon_language_version or 3
# TODO(takashi): Drop Py2 support
if int(float(daemon_language_version)) == 2:
daemon_language_version = DEFAULT_PY2
else:
daemon_language_version = DEFAULT_PY3
python_interpreter = '/usr/bin/python%s' % daemon_language_version
str_daemon_main_file = '/usr/local/libexec/storlets/storlets-daemon'

View File

@ -128,12 +128,12 @@ class StorletGatewayDocker(StorletGatewayBase):
if '-' not in name or '.' not in name:
raise ValueError('Storlet name is incorrect')
elif params['Language'].lower() == 'python':
# support both py2 and py3
try:
version = int(float(params.get('Language-Version', 2)))
version = int(float(params.get('Language-Version', 3)))
except ValueError:
raise ValueError('Language-Version is invalid')
# TODO(takashi): Drop Py2 support
if version not in [2, DEFAULT_PY2, 3, DEFAULT_PY3]:
# TODO(kota_): more strict version check should be nice.
raise ValueError('Not supported version specified')

View File

@ -17,7 +17,7 @@ from swiftclient import client
from swiftclient.exceptions import ClientException
from tests.functional.python import StorletPythonFunctionalTest
import unittest
from storlets.agent.common.utils import DEFAULT_PY3
from storlets.agent.common.utils import DEFAULT_PY2
class TestBrokenStorlet(StorletPythonFunctionalTest):
@ -43,9 +43,9 @@ class TestBrokenStorlet(StorletPythonFunctionalTest):
self.assertEqual(e.http_status, 503)
class TestBrokenStorletRunPy3(TestBrokenStorlet):
class TestBrokenStorletRunPy2(TestBrokenStorlet):
def setUp(self):
super(TestBrokenStorletRunPy3, self).setUp(version=DEFAULT_PY3)
super(TestBrokenStorletRunPy2, self).setUp(version=DEFAULT_PY2)
if __name__ == '__main__':

View File

@ -20,7 +20,7 @@ from nose.plugins.attrib import attr
from tests.functional.python import StorletPythonFunctionalTest
import unittest
from six.moves.urllib.request import Request, urlopen
from storlets.agent.common.utils import DEFAULT_PY3
from storlets.agent.common.utils import DEFAULT_PY2
class TestSimpleStorlet(StorletPythonFunctionalTest):
@ -164,9 +164,9 @@ class TestSimpleStorletOnProxy(TestSimpleStorlet):
self.additional_headers = {'X-Storlet-Run-On-Proxy': ''}
class TestSimpleStorletRunPy3(TestSimpleStorlet):
class TestSimpleStorletRunPy2(TestSimpleStorlet):
def setUp(self):
super(TestSimpleStorletRunPy3, self).setUp(version=DEFAULT_PY3)
super(TestSimpleStorletRunPy2, self).setUp(version=DEFAULT_PY2)
if __name__ == '__main__':

View File

@ -88,6 +88,7 @@ class TestStorletDaemonFactory(unittest.TestCase):
env['LD_LIBRARY_PATH'].split(':'))
def test_get_python_args(self):
self._test_get_python_args(None, DEFAULT_PY3)
self._test_get_python_args(DEFAULT_PY2, DEFAULT_PY2)
self._test_get_python_args(2, DEFAULT_PY2)
self._test_get_python_args(DEFAULT_PY3, DEFAULT_PY3)