Fix string/binary conversions for py34 compatibility
Default type of strings in py 2 and 3 are different. So, convert them explicitly when it is needed for py 2/3 compatibility. Partially-Implements: bp py3-compatibility Change-Id: I9b2d7e97fdc7d073a16e729ce0e90b92281fdf8d
This commit is contained in:
parent
45bb88c6e2
commit
ed6ed47202
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
from oslo_log import log
|
||||
import six
|
||||
import webob
|
||||
from webob import exc
|
||||
|
||||
@ -81,7 +82,7 @@ class AdminController(wsgi.Controller):
|
||||
try:
|
||||
self._update(context, id, update)
|
||||
except exception.NotFound as e:
|
||||
raise exc.HTTPNotFound(e)
|
||||
raise exc.HTTPNotFound(six.text_type(e))
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@wsgi.action('os-force_delete')
|
||||
@ -92,7 +93,7 @@ class AdminController(wsgi.Controller):
|
||||
try:
|
||||
resource = self._get(context, id)
|
||||
except exception.NotFound as e:
|
||||
raise exc.HTTPNotFound(e)
|
||||
raise exc.HTTPNotFound(six.text_type(e))
|
||||
self._delete(context, resource, force=True)
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
|
@ -243,7 +243,7 @@ class JSONDictSerializer(DictSerializer):
|
||||
"""Default JSON request body serialization"""
|
||||
|
||||
def default(self, data):
|
||||
return jsonutils.dumps(data)
|
||||
return six.b(jsonutils.dumps(data))
|
||||
|
||||
|
||||
def serializers(**serializers):
|
||||
|
@ -484,7 +484,7 @@ class XMLAPIHelper(object):
|
||||
return dest
|
||||
|
||||
def _send_request(self, req):
|
||||
req_xml = constants.XML_HEADER + ET.tostring(req)
|
||||
req_xml = six.b(constants.XML_HEADER) + ET.tostring(req)
|
||||
rsp_xml = self._conn.request(req_xml)
|
||||
|
||||
result = parser.parse_xml_api(
|
||||
|
@ -261,7 +261,7 @@ class GaneshaManager(object):
|
||||
for k, v in ganesha_utils.walk(confdict):
|
||||
# values in the export block template that need to be
|
||||
# filled in by Manila are pre-fixed by '@'
|
||||
if isinstance(v, basestring) and v[0] == '@':
|
||||
if isinstance(v, six.string_types) and v[0] == '@':
|
||||
msg = _("Incomplete export block: value %(val)s of attribute "
|
||||
"%(key)s is a stub.") % {'key': k, 'val': v}
|
||||
raise exception.InvalidParameterValue(err=msg)
|
||||
|
@ -62,9 +62,8 @@ class SopShareDriver(driver.ShareDriver):
|
||||
self.soppassword = self.configuration.safe_get('hdssop_adminpassword')
|
||||
|
||||
def get_sop_auth_header(self):
|
||||
return 'Basic ' + base64.b64encode(
|
||||
self.sopuser + ':' +
|
||||
self.soppassword).encode('utf-8').decode('ascii')
|
||||
return (six.b('Basic ') + base64.b64encode(
|
||||
six.b(self.sopuser + ':' + self.soppassword))).decode('ascii')
|
||||
|
||||
def _wait_for_job_completion(self, httpclient, job_uri):
|
||||
"""Wait for job identified by job_uri to complete."""
|
||||
|
@ -183,12 +183,12 @@ class RestHelper(object):
|
||||
need_encode = False
|
||||
for key in ['UserName', 'UserPassword']:
|
||||
node = root.find('Storage/%s' % key)
|
||||
node_text = node.text
|
||||
if node_text.find(prefix_name) > -1:
|
||||
logininfo[key] = base64.b64decode(node_text[4:])
|
||||
if node.text.find(prefix_name) > -1:
|
||||
logininfo[key] = base64.b64decode(six.b(node.text[4:]))
|
||||
else:
|
||||
logininfo[key] = node_text
|
||||
node.text = prefix_name + base64.b64encode(node_text)
|
||||
logininfo[key] = node.text
|
||||
node.text = prefix_name + six.text_type(
|
||||
base64.b64encode(six.b(node.text)))
|
||||
need_encode = True
|
||||
if need_encode:
|
||||
self._change_file_mode(filename)
|
||||
|
@ -762,7 +762,7 @@ class NetAppCmodeClient(client_base.NetAppBaseClient):
|
||||
@na_utils.trace
|
||||
def configure_ldap(self, security_service):
|
||||
"""Configures LDAP on Vserver."""
|
||||
config_name = hashlib.md5(security_service['id']).hexdigest()
|
||||
config_name = hashlib.md5(six.b(security_service['id'])).hexdigest()
|
||||
api_args = {
|
||||
'ldap-client-config': config_name,
|
||||
'servers': {
|
||||
|
@ -50,9 +50,9 @@ class BasicAuthCredentials(object):
|
||||
return self._username
|
||||
|
||||
def get_authorization_header(self):
|
||||
auth = base64.standard_b64encode(
|
||||
'%s:%s' % (self._username, self._password))
|
||||
return 'BASIC %s' % auth
|
||||
header = '%s:%s' % (self._username, self._password)
|
||||
auth = base64.standard_b64encode(six.b(header))
|
||||
return 'BASIC %s' % auth.decode()
|
||||
|
||||
|
||||
class HTTPSConnectionWithCaVerification(http_client.HTTPConnection):
|
||||
|
@ -20,6 +20,7 @@ import base64
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslo_utils import units
|
||||
import six
|
||||
|
||||
from manila import exception
|
||||
from manila.i18n import _
|
||||
@ -128,8 +129,8 @@ class ZFSSAShareDriver(driver.ShareDriver):
|
||||
LOG.debug("Connecting to host: %s.", lcfg.zfssa_host)
|
||||
self.zfssa = factory_zfssa()
|
||||
self.zfssa.set_host(lcfg.zfssa_host, timeout=lcfg.zfssa_rest_timeout)
|
||||
auth_str = base64.encodestring('%s:%s' % (lcfg.zfssa_auth_user,
|
||||
lcfg.zfssa_auth_password))[:-1]
|
||||
creds = '%s:%s' % (lcfg.zfssa_auth_user, lcfg.zfssa_auth_password)
|
||||
auth_str = base64.encodestring(six.b(creds))[:-1]
|
||||
self.zfssa.login(auth_str)
|
||||
if lcfg.zfssa_nas_mountpoint == '':
|
||||
self.mountpoint += lcfg.zfssa_project
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
import webob
|
||||
|
||||
from manila.common import constants
|
||||
@ -54,8 +55,8 @@ class AdminActionsTest(test.TestCase):
|
||||
req.method = 'POST'
|
||||
req.headers['content-type'] = 'application/json'
|
||||
# request status of 'error'
|
||||
req.body = jsonutils.dumps(
|
||||
{'os-reset_status': {'status': constants.STATUS_ERROR}})
|
||||
req.body = six.b(jsonutils.dumps(
|
||||
{'os-reset_status': {'status': constants.STATUS_ERROR}}))
|
||||
# attach admin context to request
|
||||
req.environ['manila.context'] = self.admin_context
|
||||
resp = req.get_response(app())
|
||||
@ -72,8 +73,8 @@ class AdminActionsTest(test.TestCase):
|
||||
req.method = 'POST'
|
||||
req.headers['content-type'] = 'application/json'
|
||||
# request changing status to available
|
||||
req.body = jsonutils.dumps(
|
||||
{'os-reset_status': {'status': constants.STATUS_AVAILABLE}})
|
||||
req.body = six.b(jsonutils.dumps(
|
||||
{'os-reset_status': {'status': constants.STATUS_AVAILABLE}}))
|
||||
# non-admin context
|
||||
req.environ['manila.context'] = self.member_context
|
||||
resp = req.get_response(app())
|
||||
@ -90,7 +91,8 @@ class AdminActionsTest(test.TestCase):
|
||||
req.method = 'POST'
|
||||
req.headers['content-type'] = 'application/json'
|
||||
# malformed request body
|
||||
req.body = jsonutils.dumps({'os-reset_status': {'x-status': 'bad'}})
|
||||
req.body = six.b(jsonutils.dumps(
|
||||
{'os-reset_status': {'x-status': 'bad'}}))
|
||||
# attach admin context to request
|
||||
req.environ['manila.context'] = self.admin_context
|
||||
resp = req.get_response(app())
|
||||
@ -107,7 +109,8 @@ class AdminActionsTest(test.TestCase):
|
||||
req.method = 'POST'
|
||||
req.headers['content-type'] = 'application/json'
|
||||
# 'invalid' is not a valid status
|
||||
req.body = jsonutils.dumps({'os-reset_status': {'status': 'invalid'}})
|
||||
req.body = six.b(jsonutils.dumps(
|
||||
{'os-reset_status': {'status': 'invalid'}}))
|
||||
# attach admin context to request
|
||||
req.environ['manila.context'] = self.admin_context
|
||||
resp = req.get_response(app())
|
||||
@ -124,8 +127,8 @@ class AdminActionsTest(test.TestCase):
|
||||
req.method = 'POST'
|
||||
req.headers['content-type'] = 'application/json'
|
||||
# malformed request body
|
||||
req.body = jsonutils.dumps(
|
||||
{'os-reset_status': {'status': constants.STATUS_AVAILABLE}})
|
||||
req.body = six.b(jsonutils.dumps(
|
||||
{'os-reset_status': {'status': constants.STATUS_AVAILABLE}}))
|
||||
# attach admin context to request
|
||||
req.environ['manila.context'] = self.admin_context
|
||||
resp = req.get_response(app())
|
||||
@ -148,8 +151,8 @@ class AdminActionsTest(test.TestCase):
|
||||
req.method = 'POST'
|
||||
req.headers['content-type'] = 'application/json'
|
||||
# request status of 'error'
|
||||
req.body = jsonutils.dumps(
|
||||
{'os-reset_status': {'status': constants.STATUS_ERROR}})
|
||||
req.body = six.b(jsonutils.dumps(
|
||||
{'os-reset_status': {'status': constants.STATUS_ERROR}}))
|
||||
# attach admin context to request
|
||||
req.environ['manila.context'] = self.admin_context
|
||||
resp = req.get_response(app())
|
||||
@ -171,8 +174,8 @@ class AdminActionsTest(test.TestCase):
|
||||
req.method = 'POST'
|
||||
req.headers['content-type'] = 'application/json'
|
||||
# 'attaching' is not a valid status for snapshots
|
||||
req.body = jsonutils.dumps({'os-reset_status': {'status':
|
||||
'attaching'}})
|
||||
req.body = six.b(jsonutils.dumps(
|
||||
{'os-reset_status': {'status': 'attaching'}}))
|
||||
# attach admin context to request
|
||||
req.environ['manila.context'] = self.admin_context
|
||||
resp = req.get_response(app())
|
||||
@ -187,7 +190,7 @@ class AdminActionsTest(test.TestCase):
|
||||
req = webob.Request.blank('/v1/fake/shares/%s/action' % share['id'])
|
||||
req.method = 'POST'
|
||||
req.headers['content-type'] = 'application/json'
|
||||
req.body = jsonutils.dumps({'os-force_delete': {}})
|
||||
req.body = six.b(jsonutils.dumps({'os-force_delete': {}}))
|
||||
req.environ['manila.context'] = self.admin_context
|
||||
resp = req.get_response(app())
|
||||
self.assertEqual(resp.status_int, 202)
|
||||
@ -201,7 +204,7 @@ class AdminActionsTest(test.TestCase):
|
||||
req = webob.Request.blank('/v1/fake/shares/%s/action' % share['id'])
|
||||
req.method = 'POST'
|
||||
req.headers['content-type'] = 'application/json'
|
||||
req.body = jsonutils.dumps({'os-force_delete': {}})
|
||||
req.body = six.b(jsonutils.dumps({'os-force_delete': {}}))
|
||||
req.environ['manila.context'] = self.member_context
|
||||
resp = req.get_response(app())
|
||||
self.assertEqual(resp.status_int, 403)
|
||||
@ -216,7 +219,7 @@ class AdminActionsTest(test.TestCase):
|
||||
req = webob.Request.blank(path)
|
||||
req.method = 'POST'
|
||||
req.headers['content-type'] = 'application/json'
|
||||
req.body = jsonutils.dumps({'os-force_delete': {}})
|
||||
req.body = six.b(jsonutils.dumps({'os-force_delete': {}}))
|
||||
req.environ['manila.context'] = self.admin_context
|
||||
resp = req.get_response(app())
|
||||
self.assertEqual(resp.status_int, 202)
|
||||
@ -231,7 +234,7 @@ class AdminActionsTest(test.TestCase):
|
||||
req = webob.Request.blank(path)
|
||||
req.method = 'POST'
|
||||
req.headers['content-type'] = 'application/json'
|
||||
req.body = jsonutils.dumps({'os-force_delete': {}})
|
||||
req.body = six.b(jsonutils.dumps({'os-force_delete': {}}))
|
||||
req.environ['manila.context'] = self.member_context
|
||||
resp = req.get_response(app())
|
||||
self.assertEqual(resp.status_int, 403)
|
||||
|
@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
import webob
|
||||
import webob.dec
|
||||
import webob.exc
|
||||
@ -89,7 +90,7 @@ class TestFaults(test.TestCase):
|
||||
resp = req.get_response(raiser)
|
||||
self.assertEqual(resp.content_type, "application/json")
|
||||
self.assertEqual(resp.status_int, 404)
|
||||
self.assertTrue('whut?' in resp.body)
|
||||
self.assertTrue(six.b('whut?') in resp.body)
|
||||
|
||||
def test_raise_403(self):
|
||||
"""Ensure the ability to raise :class:`Fault` in WSGI-ified methods."""
|
||||
@ -101,8 +102,8 @@ class TestFaults(test.TestCase):
|
||||
resp = req.get_response(raiser)
|
||||
self.assertEqual(resp.content_type, "application/json")
|
||||
self.assertEqual(resp.status_int, 403)
|
||||
self.assertTrue('resizeNotAllowed' not in resp.body)
|
||||
self.assertTrue('forbidden' in resp.body)
|
||||
self.assertTrue(six.b('resizeNotAllowed') not in resp.body)
|
||||
self.assertTrue(six.b('forbidden') in resp.body)
|
||||
|
||||
def test_fault_has_status_int(self):
|
||||
"""Ensure the status_int is set correctly on faults."""
|
||||
|
@ -1,5 +1,6 @@
|
||||
import ddt
|
||||
import inspect
|
||||
import six
|
||||
import webob
|
||||
|
||||
from manila.api.openstack import wsgi
|
||||
@ -12,13 +13,13 @@ from manila.tests.api import fakes
|
||||
class RequestTest(test.TestCase):
|
||||
def test_content_type_missing(self):
|
||||
request = wsgi.Request.blank('/tests/123', method='POST')
|
||||
request.body = "<body />"
|
||||
request.body = six.b("<body />")
|
||||
self.assertEqual(None, request.get_content_type())
|
||||
|
||||
def test_content_type_unsupported(self):
|
||||
request = wsgi.Request.blank('/tests/123', method='POST')
|
||||
request.headers["Content-Type"] = "text/html"
|
||||
request.body = "asdf<br />"
|
||||
request.body = six.b("asdf<br />")
|
||||
self.assertRaises(exception.InvalidContentType,
|
||||
request.get_content_type)
|
||||
|
||||
@ -154,10 +155,10 @@ class DictSerializerTest(test.TestCase):
|
||||
class JSONDictSerializerTest(test.TestCase):
|
||||
def test_json(self):
|
||||
input_dict = dict(servers=dict(a=(2, 3)))
|
||||
expected_json = '{"servers":{"a":[2,3]}}'
|
||||
expected_json = six.b('{"servers":{"a":[2,3]}}')
|
||||
serializer = wsgi.JSONDictSerializer()
|
||||
result = serializer.serialize(input_dict)
|
||||
result = result.replace('\n', '').replace(' ', '')
|
||||
result = result.replace(six.b('\n'),six.b('')).replace(six.b(' '),six.b(''))
|
||||
self.assertEqual(result, expected_json)
|
||||
|
||||
|
||||
@ -199,7 +200,7 @@ class ResourceTest(test.TestCase):
|
||||
req = webob.Request.blank('/tests')
|
||||
app = fakes.TestRouter(Controller())
|
||||
response = req.get_response(app)
|
||||
self.assertEqual(response.body, 'off')
|
||||
self.assertEqual(response.body, six.b('off'))
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
def test_resource_not_authorized(self):
|
||||
@ -313,7 +314,7 @@ class ResourceTest(test.TestCase):
|
||||
|
||||
request = wsgi.Request.blank('/', method='POST')
|
||||
request.headers['Content-Type'] = 'application/none'
|
||||
request.body = 'foo'
|
||||
request.body = six.b('foo')
|
||||
|
||||
content_type, body = resource.get_body(request)
|
||||
self.assertEqual(content_type, None)
|
||||
@ -328,7 +329,7 @@ class ResourceTest(test.TestCase):
|
||||
resource = wsgi.Resource(controller)
|
||||
|
||||
request = wsgi.Request.blank('/', method='POST')
|
||||
request.body = 'foo'
|
||||
request.body = six.b('foo')
|
||||
|
||||
content_type, body = resource.get_body(request)
|
||||
self.assertEqual(content_type, None)
|
||||
@ -344,7 +345,7 @@ class ResourceTest(test.TestCase):
|
||||
|
||||
request = wsgi.Request.blank('/', method='POST')
|
||||
request.headers['Content-Type'] = 'application/json'
|
||||
request.body = ''
|
||||
request.body = six.b('')
|
||||
|
||||
content_type, body = resource.get_body(request)
|
||||
self.assertEqual(content_type, None)
|
||||
@ -360,11 +361,11 @@ class ResourceTest(test.TestCase):
|
||||
|
||||
request = wsgi.Request.blank('/', method='POST')
|
||||
request.headers['Content-Type'] = 'application/json'
|
||||
request.body = 'foo'
|
||||
request.body = six.b('foo')
|
||||
|
||||
content_type, body = resource.get_body(request)
|
||||
self.assertEqual(content_type, 'application/json')
|
||||
self.assertEqual(body, 'foo')
|
||||
self.assertEqual(body, six.b('foo'))
|
||||
|
||||
def test_deserialize_badtype(self):
|
||||
class Controller(object):
|
||||
@ -429,7 +430,6 @@ class ResourceTest(test.TestCase):
|
||||
controller = Controller()
|
||||
resource = wsgi.Resource(controller)
|
||||
self.assertEqual({}, resource.wsgi_actions)
|
||||
|
||||
extended = ControllerExtended()
|
||||
resource.register_actions(extended)
|
||||
self.assertEqual({'fooAction': extended._action_foo,
|
||||
@ -792,15 +792,15 @@ class ResponseObjectTest(test.TestCase):
|
||||
def test_serialize(self):
|
||||
class JSONSerializer(object):
|
||||
def serialize(self, obj):
|
||||
return 'json'
|
||||
return six.b('json')
|
||||
|
||||
class XMLSerializer(object):
|
||||
def serialize(self, obj):
|
||||
return 'xml'
|
||||
return six.b('xml')
|
||||
|
||||
class AtomSerializer(object):
|
||||
def serialize(self, obj):
|
||||
return 'atom'
|
||||
return six.b('atom')
|
||||
|
||||
robj = wsgi.ResponseObject({}, code=202,
|
||||
json=JSONSerializer,
|
||||
@ -817,7 +817,7 @@ class ResponseObjectTest(test.TestCase):
|
||||
self.assertEqual(response.headers['X-header1'], 'header1')
|
||||
self.assertEqual(response.headers['X-header2'], 'header2')
|
||||
self.assertEqual(response.status_int, 202)
|
||||
self.assertEqual(response.body, mtype)
|
||||
self.assertEqual(response.body, six.b(mtype))
|
||||
|
||||
|
||||
class ValidBodyTest(test.TestCase):
|
||||
|
@ -22,6 +22,7 @@ Test WSGI basics and provide some helper functions for other WSGI tests.
|
||||
from manila import test
|
||||
|
||||
import routes
|
||||
import six
|
||||
import webob
|
||||
|
||||
from manila import wsgi
|
||||
@ -36,11 +37,11 @@ class Test(test.TestCase):
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
start_response("200", [("X-Test", "checking")])
|
||||
return ['Test result']
|
||||
return [six.b('Test result')]
|
||||
|
||||
application = wsgi.Debug(Application())
|
||||
result = webob.Request.blank('/').get_response(application)
|
||||
self.assertEqual(result.body, "Test result")
|
||||
self.assertEqual(result.body, six.b("Test result"))
|
||||
|
||||
def test_router(self):
|
||||
|
||||
|
@ -533,7 +533,7 @@ class WsgiLimiterTest(BaseLimitTestSuite):
|
||||
|
||||
def _request_data(self, verb, path):
|
||||
"""Get data describing a limit request verb/path."""
|
||||
return jsonutils.dumps({"verb": verb, "path": path})
|
||||
return six.b(jsonutils.dumps({"verb": verb, "path": path}))
|
||||
|
||||
def _request(self, verb, url, username=None):
|
||||
"""Send request.
|
||||
@ -599,9 +599,9 @@ class FakeHttplibSocket(object):
|
||||
|
||||
def __init__(self, response_string):
|
||||
"""Initialize new `FakeHttplibSocket`."""
|
||||
self._buffer = six.StringIO(response_string)
|
||||
self._buffer = six.BytesIO(six.b(response_string))
|
||||
|
||||
def makefile(self, _mode, _other):
|
||||
def makefile(self, _mode, _other=None):
|
||||
"""Returns the socket's internal buffer."""
|
||||
return self._buffer
|
||||
|
||||
@ -628,7 +628,7 @@ class FakeHttplibConnection(object):
|
||||
req.method = method
|
||||
req.headers = headers
|
||||
req.host = self.host
|
||||
req.body = body
|
||||
req.body = six.b(body)
|
||||
|
||||
resp = str(req.get_response(self.app))
|
||||
resp = "HTTP/1.0 %s" % resp
|
||||
@ -709,12 +709,11 @@ class WsgiLimiterProxyTest(BaseLimitTestSuite):
|
||||
"""Forbidden request test."""
|
||||
delay = self.proxy.check_for_delay("GET", "/delayed")
|
||||
self.assertEqual(delay, (None, None))
|
||||
|
||||
delay, error = self.proxy.check_for_delay("GET", "/delayed")
|
||||
error = error.strip()
|
||||
|
||||
expected = ("60.00", "403 Forbidden\n\nOnly 1 GET request(s) can be "
|
||||
"made to /delayed every minute.")
|
||||
expected = ("60.00", six.b("403 Forbidden\n\nOnly 1 GET request(s) "
|
||||
"can be made to /delayed every minute."))
|
||||
|
||||
self.assertEqual((delay, error), expected)
|
||||
|
||||
|
@ -18,6 +18,7 @@ import uuid
|
||||
import ddt
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
import webob
|
||||
|
||||
from manila.api.v1 import share_metadata
|
||||
@ -198,7 +199,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
req.method = 'POST'
|
||||
req.content_type = "application/json"
|
||||
body = {"metadata": {"key9": "value9"}}
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.body = six.b(jsonutils.dumps(body))
|
||||
res_dict = self.controller.create(req, self.req_id, body)
|
||||
self.assertEqual(body, res_dict)
|
||||
|
||||
@ -218,7 +219,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key1')
|
||||
req.method = 'PUT'
|
||||
body = {"meta": {"": "value1"}}
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.body = six.b(jsonutils.dumps(body))
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
@ -230,7 +231,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key1')
|
||||
req.method = 'PUT'
|
||||
body = {"meta": {("a" * 260): "value1"}}
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.body = six.b(jsonutils.dumps(body))
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
@ -249,7 +250,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
req.method = 'POST'
|
||||
req.content_type = "application/json"
|
||||
body = {"metadata": {"key9": "value9"}}
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.body = six.b(jsonutils.dumps(body))
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller.create, req, self.req_id, body)
|
||||
|
||||
@ -265,7 +266,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
'key99': 'value99',
|
||||
},
|
||||
}
|
||||
req.body = jsonutils.dumps(expected)
|
||||
req.body = six.b(jsonutils.dumps(expected))
|
||||
res_dict = self.controller.update_all(req, self.req_id, expected)
|
||||
|
||||
self.assertEqual(expected, res_dict)
|
||||
@ -277,7 +278,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
req.method = 'PUT'
|
||||
req.content_type = "application/json"
|
||||
expected = {'metadata': {}}
|
||||
req.body = jsonutils.dumps(expected)
|
||||
req.body = six.b(jsonutils.dumps(expected))
|
||||
res_dict = self.controller.update_all(req, self.req_id, expected)
|
||||
|
||||
self.assertEqual(expected, res_dict)
|
||||
@ -289,7 +290,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
req.method = 'PUT'
|
||||
req.content_type = "application/json"
|
||||
expected = {'meta': {}}
|
||||
req.body = jsonutils.dumps(expected)
|
||||
req.body = six.b(jsonutils.dumps(expected))
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.update_all, req, self.req_id,
|
||||
@ -306,7 +307,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
req.method = 'PUT'
|
||||
req.content_type = "application/json"
|
||||
expected = {'metadata': metadata}
|
||||
req.body = jsonutils.dumps(expected)
|
||||
req.body = six.b(jsonutils.dumps(expected))
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.update_all, req, self.req_id,
|
||||
@ -318,7 +319,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
req.method = 'PUT'
|
||||
req.content_type = "application/json"
|
||||
body = {'metadata': {'key10': 'value10'}}
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.body = six.b(jsonutils.dumps(body))
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller.update_all, req, '100', body)
|
||||
@ -329,7 +330,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key1')
|
||||
req.method = 'PUT'
|
||||
body = {"meta": {"key1": "value1"}}
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.body = six.b(jsonutils.dumps(body))
|
||||
req.headers["content-type"] = "application/json"
|
||||
res_dict = self.controller.update(req, self.req_id, 'key1', body)
|
||||
expected = {'meta': {'key1': 'value1'}}
|
||||
@ -341,7 +342,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/shares/asdf/metadata/key1')
|
||||
req.method = 'PUT'
|
||||
body = {"meta": {"key1": "value1"}}
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.body = six.b(jsonutils.dumps(body))
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
@ -365,7 +366,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key1')
|
||||
req.method = 'PUT'
|
||||
body = {"meta": {"": "value1"}}
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.body = six.b(jsonutils.dumps(body))
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
@ -377,7 +378,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key1')
|
||||
req.method = 'PUT'
|
||||
body = {"meta": {("a" * 260): "value1"}}
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.body = six.b(jsonutils.dumps(body))
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
@ -390,7 +391,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key1')
|
||||
req.method = 'PUT'
|
||||
body = {"meta": {"key1": ("a" * 1025)}}
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.body = six.b(jsonutils.dumps(body))
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
@ -403,7 +404,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key1')
|
||||
req.method = 'PUT'
|
||||
body = {"meta": {"key1": "value1", "key2": "value2"}}
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.body = six.b(jsonutils.dumps(body))
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
@ -416,7 +417,7 @@ class ShareMetaDataTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank(self.url + '/bad')
|
||||
req.method = 'PUT'
|
||||
body = {"meta": {"key1": "value1"}}
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.body = six.b(jsonutils.dumps(body))
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
@ -432,18 +433,18 @@ class ShareMetaDataTest(test.TestCase):
|
||||
|
||||
# test for long key
|
||||
data = {"metadata": {"a" * 260: "value1"}}
|
||||
req.body = jsonutils.dumps(data)
|
||||
req.body = six.b(jsonutils.dumps(data))
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.create, req, self.req_id, data)
|
||||
|
||||
# test for long value
|
||||
data = {"metadata": {"key": "v" * 1025}}
|
||||
req.body = jsonutils.dumps(data)
|
||||
req.body = six.b(jsonutils.dumps(data))
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.create, req, self.req_id, data)
|
||||
|
||||
# test for empty key.
|
||||
data = {"metadata": {"": "value1"}}
|
||||
req.body = jsonutils.dumps(data)
|
||||
req.body = six.b(jsonutils.dumps(data))
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.create, req, self.req_id, data)
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import six
|
||||
|
||||
from manila.tests.integrated import integrated_helpers
|
||||
|
||||
@ -35,4 +36,4 @@ class ExtensionsTest(integrated_helpers._IntegratedTestBase):
|
||||
response = self.api.api_request('/foxnsocks')
|
||||
foxnsocks = response.read()
|
||||
LOG.debug("foxnsocks: %s" % foxnsocks)
|
||||
self.assertEqual('Try to say this Mr. Knox, sir...', foxnsocks)
|
||||
self.assertEqual(six.b('Try to say this Mr. Knox, sir...'), foxnsocks)
|
||||
|
@ -36,7 +36,7 @@ class FakeSchedulerOptions(scheduler_options.SchedulerOptions):
|
||||
# For overrides ...
|
||||
self._time_now = now
|
||||
self._file_now = file_now
|
||||
self._file_data = filedata
|
||||
self._file_data = six.b(filedata)
|
||||
|
||||
self.file_was_loaded = False
|
||||
|
||||
@ -45,7 +45,12 @@ class FakeSchedulerOptions(scheduler_options.SchedulerOptions):
|
||||
|
||||
def _get_file_handle(self, filename):
|
||||
self.file_was_loaded = True
|
||||
return six.StringIO(self._file_data)
|
||||
if six.PY2:
|
||||
import StringIO
|
||||
return StringIO.StringIO(self._file_data)
|
||||
else:
|
||||
import io
|
||||
return io.BytesIO(self._file_data)
|
||||
|
||||
def _get_time_now(self):
|
||||
return self._time_now
|
||||
|
@ -20,6 +20,7 @@ from lxml import doctestcompare
|
||||
import mock
|
||||
from oslo_log import log
|
||||
from oslo_utils import units
|
||||
import six
|
||||
|
||||
from manila.common import constants as const
|
||||
import manila.db
|
||||
@ -1167,6 +1168,10 @@ class EMCMock(mock.Mock):
|
||||
except StopIteration:
|
||||
return True
|
||||
|
||||
if not isinstance(expect, six.binary_type):
|
||||
expect = six.b(expect)
|
||||
if not isinstance(actual, six.binary_type):
|
||||
actual = six.b(actual)
|
||||
if not CHECKER.check_output(expect, actual, PARSE_XML):
|
||||
raise AssertionError(
|
||||
'Mismatch error.\nExpected: %r\n'
|
||||
|
@ -21,6 +21,7 @@ import time
|
||||
import ddt
|
||||
import mock
|
||||
from oslo_log import log
|
||||
import six
|
||||
|
||||
from manila import exception
|
||||
from manila.share.drivers.netapp.dataontap.client import api as netapp_api
|
||||
@ -1387,7 +1388,7 @@ class NetAppClientCmodeTestCase(test.TestCase):
|
||||
self.client.configure_ldap(fake.LDAP_SECURITY_SERVICE)
|
||||
|
||||
config_name = hashlib.md5(
|
||||
fake.LDAP_SECURITY_SERVICE['id']).hexdigest()
|
||||
six.b(fake.LDAP_SECURITY_SERVICE['id'])).hexdigest()
|
||||
|
||||
ldap_client_create_args = {
|
||||
'ldap-client-config': config_name,
|
||||
|
@ -133,7 +133,7 @@ class TestWSGIServer(test.TestCase):
|
||||
server.start()
|
||||
|
||||
response = urllib.request.urlopen('http://127.0.0.1:%d/' % server.port)
|
||||
self.assertEqual(greetings, response.read())
|
||||
self.assertEqual(six.b(greetings), response.read())
|
||||
|
||||
# Verify provided parameters to eventlet.spawn func
|
||||
eventlet.spawn.assert_called_once_with(
|
||||
@ -247,11 +247,11 @@ class ExceptionTest(test.TestCase):
|
||||
|
||||
api = self._wsgi_app(fail)
|
||||
resp = webob.Request.blank('/').get_response(api)
|
||||
self.assertTrue('{"computeFault' in resp.body, resp.body)
|
||||
self.assertIn('{"computeFault', six.text_type(resp.body), resp.body)
|
||||
expected = ('ExceptionWithSafety: some explanation' if expose else
|
||||
'The server has either erred or is incapable '
|
||||
'of performing the requested operation.')
|
||||
self.assertTrue(expected in resp.body, resp.body)
|
||||
self.assertIn(expected, six.text_type(resp.body), resp.body)
|
||||
self.assertEqual(resp.status_int, 500, resp.body)
|
||||
|
||||
def test_safe_exceptions_are_described_in_faults(self):
|
||||
@ -267,7 +267,7 @@ class ExceptionTest(test.TestCase):
|
||||
|
||||
api = self._wsgi_app(fail)
|
||||
resp = webob.Request.blank('/').get_response(api)
|
||||
self.assertTrue(msg in resp.body, resp.body)
|
||||
self.assertIn(msg, six.text_type(resp.body), resp.body)
|
||||
self.assertEqual(resp.status_int, exception_type.code, resp.body)
|
||||
|
||||
if hasattr(exception_type, 'headers'):
|
||||
|
@ -456,7 +456,7 @@ class Debug(Middleware):
|
||||
"""Iterator that prints the contents of a wrapper string."""
|
||||
print(('*' * 40) + ' BODY')
|
||||
for part in app_iter:
|
||||
sys.stdout.write(part)
|
||||
sys.stdout.write(part.decode())
|
||||
sys.stdout.flush()
|
||||
yield part
|
||||
print()
|
||||
|
Loading…
x
Reference in New Issue
Block a user