]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Port huawei driver to Python 3
authorVictor Stinner <vstinner@redhat.com>
Mon, 29 Jun 2015 20:31:45 +0000 (22:31 +0200)
committerVictor Stinner <vstinner@redhat.com>
Mon, 29 Jun 2015 20:33:20 +0000 (22:33 +0200)
* 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

cinder/tests/unit/test_huawei_18000.py
cinder/volume/drivers/huawei/rest_common.py
tox.ini

index 512afd75ed0b0e1d114e8f921cf2cf10f7d61844..d5826db7ca1fdaab05ecdb7e469f0055ec80955e 100644 (file)
@@ -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&"\
index 0864d61f9606b5ebb05e375d77d4187249c79830..8ed1eec3e7c58b7ffefafe1a735de8e128ee1310 100644 (file)
@@ -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 144737a4ad56bfb204ac04f18dfb1f7a0770c745..bef73afc8c8c907f4f0a9cbf18b24997f30773d7 100644 (file)
--- 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 \