diff --git a/swift/common/middleware/x_profile/html_viewer.py b/swift/common/middleware/x_profile/html_viewer.py index b575c5383b..e43fd2cd71 100644 --- a/swift/common/middleware/x_profile/html_viewer.py +++ b/swift/common/middleware/x_profile/html_viewer.py @@ -21,9 +21,13 @@ import string import tempfile from swift import gettext_ as _ -from exceptions import PLOTLIBNotInstalled, ODFLIBNotInstalled,\ - NotFoundException, MethodNotAllowed, DataLoadFailure, ProfileException -from profile_model import Stats2 +from swift.common.middleware.x_profile.exceptions import PLOTLIBNotInstalled +from swift.common.middleware.x_profile.exceptions import ODFLIBNotInstalled +from swift.common.middleware.x_profile.exceptions import NotFoundException +from swift.common.middleware.x_profile.exceptions import MethodNotAllowed +from swift.common.middleware.x_profile.exceptions import DataLoadFailure +from swift.common.middleware.x_profile.exceptions import ProfileException +from swift.common.middleware.x_profile.profile_model import Stats2 PLOTLIB_INSTALLED = True try: diff --git a/swift/common/middleware/xprofile.py b/swift/common/middleware/xprofile.py index fd8797a0ee..d5cdb8bb84 100644 --- a/swift/common/middleware/xprofile.py +++ b/swift/common/middleware/xprofile.py @@ -86,10 +86,11 @@ from six.moves import urllib from swift import gettext_ as _ from swift.common.utils import get_logger, config_true_value from swift.common.swob import Request -from x_profile.exceptions import NotFoundException, MethodNotAllowed,\ - ProfileException -from x_profile.html_viewer import HTMLViewer -from x_profile.profile_model import ProfileLog +from swift.common.middleware.x_profile.exceptions import MethodNotAllowed +from swift.common.middleware.x_profile.exceptions import NotFoundException +from swift.common.middleware.x_profile.exceptions import ProfileException +from swift.common.middleware.x_profile.html_viewer import HTMLViewer +from swift.common.middleware.x_profile.profile_model import ProfileLog DEFAULT_PROFILE_PREFIX = '/tmp/log/swift/profile/default.profile' @@ -107,7 +108,10 @@ PROFILE_EXEC_LAZY = """ app_iter_ = self.app(environ, start_response) """ -thread = patcher.original('thread') # non-monkeypatched module needed +if six.PY3: + thread = patcher.original('_thread') # non-monkeypatched module needed +else: + thread = patcher.original('thread') # non-monkeypatched module needed # This monkey patch code fix the problem of eventlet profile tool @@ -177,7 +181,7 @@ class ProfileMiddleware(object): def _combine_body_qs(self, request): wsgi_input = request.environ['wsgi.input'] query_dict = request.params - qs_in_body = wsgi_input.read() + qs_in_body = wsgi_input.read().decode('utf-8') query_dict.update(urllib.parse.parse_qs(qs_in_body, keep_blank_values=True, strict_parsing=False)) diff --git a/test/unit/common/middleware/test_xprofile.py b/test/unit/common/middleware/test_xprofile.py index 55d8ee8638..3e79b7c0d2 100644 --- a/test/unit/common/middleware/test_xprofile.py +++ b/test/unit/common/middleware/test_xprofile.py @@ -132,7 +132,7 @@ class TestProfileMiddleware(unittest.TestCase): 'QUERY_STRING': 'profile=all&format=json', 'wsgi.input': wsgi_input} resp = self.app(environ, self.start_response) - self.assertTrue(resp[0].find('') > 0, resp) + self.assertTrue(resp[0].find(b'') > 0, resp) self.assertEqual(self.got_statuses, ['200 OK']) self.assertEqual(self.headers, [('content-type', 'text/html')]) wsgi_input = BytesIO(body + b'&plot=plot') @@ -144,12 +144,12 @@ class TestProfileMiddleware(unittest.TestCase): else: resp = self.app(environ, self.start_response) self.assertEqual(self.got_statuses, ['500 Internal Server Error']) - wsgi_input = BytesIO(body + '&download=download&format=default') + wsgi_input = BytesIO(body + b'&download=download&format=default') environ['wsgi.input'] = wsgi_input resp = self.app(environ, self.start_response) self.assertEqual(self.headers, [('content-type', HTMLViewer.format_dict['default'])]) - wsgi_input = BytesIO(body + '&download=download&format=json') + wsgi_input = BytesIO(body + b'&download=download&format=json') environ['wsgi.input'] = wsgi_input resp = self.app(environ, self.start_response) self.assertTrue(self.headers == [('content-type', diff --git a/tox.ini b/tox.ini index 8e2db0e04e..c607071838 100644 --- a/tox.ini +++ b/tox.ini @@ -53,6 +53,7 @@ commands = test/unit/common/middleware/test_memcache.py \ test/unit/common/middleware/test_proxy_logging.py \ test/unit/common/middleware/test_tempauth.py \ + test/unit/common/middleware/test_xprofile.py \ test/unit/common/ring \ test/unit/common/test_base_storage_server.py \ test/unit/common/test_bufferedhttp.py \