From: Victor Stinner Date: Mon, 29 Jun 2015 20:31:45 +0000 (+0200) Subject: Port huawei driver to Python 3 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=558e6bbb5cfd44a1ed1fc4f00c1d2e241c2f0411;p=openstack-build%2Fcinder-build.git Port huawei driver to Python 3 * On Python 3, encode text to UTF-8 before encoding it to base64 * On Python 3, decode encoded base64 from ASCII to get Unicode * Fix JSON in unit test: COUNT must be an integer, not a string * tox.ini: add cinder.tests.unit.test_huawei_18000 to Python 3.4 Blueprint cinder-python3 Change-Id: I8a2356e7faa98bf0a1a74fc15202866f5d5499a3 --- diff --git a/cinder/tests/unit/test_huawei_18000.py b/cinder/tests/unit/test_huawei_18000.py index 512afd75e..d5826db7c 100644 --- a/cinder/tests/unit/test_huawei_18000.py +++ b/cinder/tests/unit/test_huawei_18000.py @@ -422,7 +422,7 @@ class Fake18000Common(rest_common.RestCommon): if url == "lun/count?TYPE=11&ASSOCIATEOBJTYPE=256&"\ "ASSOCIATEOBJID=11": - data = """{"data":{"COUNT":"7"}, + data = """{"data":{"COUNT":7}, "error":{"code":0,"description":"0"}}""" if url == "lungroup/associate?TYPE=256&ASSOCIATEOBJTYPE=11&"\ diff --git a/cinder/volume/drivers/huawei/rest_common.py b/cinder/volume/drivers/huawei/rest_common.py index 0864d61f9..8ed1eec3e 100644 --- a/cinder/volume/drivers/huawei/rest_common.py +++ b/cinder/volume/drivers/huawei/rest_common.py @@ -285,6 +285,8 @@ class RestCommon(object): uuid_str = name.replace("-", "") vol_uuid = uuid.UUID('urn:uuid:%s' % uuid_str) vol_encoded = base64.urlsafe_b64encode(vol_uuid.bytes) + if six.PY3: + vol_encoded = vol_encoded.decode('ascii') newuuid = vol_encoded.replace("=", "") return newuuid @@ -1474,7 +1476,13 @@ class RestCommon(object): logininfo[key] = base64.b64decode(node_text[4:]) else: logininfo[key] = node_text - node.text = '!$$$' + base64.b64encode(node_text) + if six.PY3: + node_b64 = node_text.encode('utf-8') + node_b64 = base64.b64encode(node_b64) + node_b64 = node_b64.decode('ascii') + node.text = '!$$$' + node_b64 + else: + node.text = '!$$$' + base64.b64encode(node_text) need_encode = True if need_encode: self._change_file_mode(filename) diff --git a/tox.ini b/tox.ini index 144737a4a..bef73afc8 100644 --- a/tox.ini +++ b/tox.ini @@ -53,6 +53,7 @@ commands = cinder.tests.unit.test_hitachi_hbsd_snm2_iscsi \ cinder.tests.unit.test_hp_xp_fc \ cinder.tests.unit.test_hplefthand \ + cinder.tests.unit.test_huawei_18000 \ cinder.tests.unit.test_huawei_drivers_compatibility \ cinder.tests.unit.test_ibm_xiv_ds8k \ cinder.tests.unit.test_infortrend_cli \