]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Port HP 3PAR driver to Python 3
authorVictor Stinner <vstinner@redhat.com>
Thu, 5 Nov 2015 15:22:11 +0000 (16:22 +0100)
committerVictor Stinner <vstinner@redhat.com>
Mon, 16 Nov 2015 08:58:21 +0000 (09:58 +0100)
* Use oslo_serialization.base64.encode_as_text() to get Unicode on
  Python 3.
* Replace sys.maxint with sys.maxsize, sys.maxint was removed in
  Python 3.
* test_hpe3par: use list(set()) to get FCWWNs is the right order. On
  Python 3, the hash function is randomized by default.
* test_hpe3par: fix client getWsApiVersion() to return a valid
  version. Before, the comparison between mock.Mock and int raised a
  TypeError.
* hpe_3par_common: set version to 3.0.2
* hpe_3par_iscsi: set version to 3.0.1
* tox.ini: add test_hpe3par to Python 3.4

Partial-Implements: blueprint cinder-python3
Change-Id: I2bed171c0db93b8ea83127a69a63c3bb2317b10b

cinder/tests/unit/test_hpe3par.py
cinder/volume/drivers/hpe/hpe_3par_common.py
cinder/volume/drivers/hpe/hpe_3par_iscsi.py
tests-py3.txt

index c201450afa17618c6a3b28d96e2f6b90956eb105..5597ae2a1bacfca69524d5e27f9cb12d9aeff08d 100644 (file)
@@ -544,6 +544,8 @@ class HPE3PARBaseDriver(object):
         # Configure the base constants, defaults etc...
         _m_client.configure_mock(**self.mock_client_conf)
 
+        _m_client.getWsApiVersion.return_value = self.wsapi_version_latest
+
         # If m_conf, drop those over the top of the base_conf.
         if m_conf is not None:
             _m_client.configure_mock(**m_conf)
@@ -4336,14 +4338,16 @@ class TestHPE3PARFCDriver(HPE3PARBaseDriver, test.TestCase):
                 common,
                 self.volume,
                 self.connector)
+            # On Python 3, hash is randomized, and so set() is used to get
+            # the expected order
+            fcwwns = list(set(('123456789054321', '123456789012345')))
             expected = [
                 mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
                 mock.call.getCPG(HPE3PAR_CPG),
                 mock.call.getHost('fakehost'),
-                mock.call.modifyHost(
-                    'fakehost', {
-                        'FCWWNs': ['123456789012345', '123456789054321'],
-                        'pathOperation': 1}),
+                mock.call.modifyHost('fakehost',
+                                     {'FCWWNs': fcwwns,
+                                      'pathOperation': 1}),
                 mock.call.getHost('fakehost')]
 
             mock_client.assert_has_calls(expected)
index 25a35eec63deab275e5c3972ba347f8842a6fffc..b7a3812f5e67500008cd0149746f9bd11f63c711 100644 (file)
@@ -35,7 +35,6 @@ array.
 """
 
 import ast
-import base64
 import json
 import math
 import pprint
@@ -43,6 +42,7 @@ import re
 import six
 import uuid
 
+from oslo_serialization import base64
 from oslo_utils import importutils
 
 hpe3parclient = importutils.try_import("hpe3parclient")
@@ -213,10 +213,11 @@ class HPE3PARCommon(object):
         2.0.53 - Fix volume size conversion. bug #1513158
         3.0.0 - Rebranded HP to HPE.
         3.0.1 - Fixed find_existing_vluns bug #1515033
+        3.0.2 - Python 3 support
 
     """
 
-    VERSION = "3.0.1"
+    VERSION = "3.0.2"
 
     stats = {}
 
@@ -786,7 +787,7 @@ class HPE3PARCommon(object):
     def _encode_name(self, name):
         uuid_str = name.replace("-", "")
         vol_uuid = uuid.UUID('urn:uuid:%s' % uuid_str)
-        vol_encoded = base64.b64encode(vol_uuid.bytes)
+        vol_encoded = base64.encode_as_text(vol_uuid.bytes)
 
         # 3par doesn't allow +, nor /
         vol_encoded = vol_encoded.replace('+', '.')
index a9fbe00c63350e075ec780369ffa126e49687b4a..35246128fcc7222b749371b525cef406efde2cdb 100644 (file)
@@ -100,10 +100,11 @@ class HPE3PARISCSIDriver(driver.TransferVD,
         2.0.22 - Update driver to use ABC metaclasses
         2.0.23 - Added update_migrated_volume. bug # 1492023
         3.0.0 - Rebranded HP to HPE.
+        3.0.1 - Python 3 support
 
     """
 
-    VERSION = "3.0.0"
+    VERSION = "3.0.1"
 
     def __init__(self, *args, **kwargs):
         super(HPE3PARISCSIDriver, self).__init__(*args, **kwargs)
@@ -719,7 +720,7 @@ class HPE3PARISCSIDriver(driver.TransferVD,
                     nsp_counts[nsp] = nsp_counts[nsp] + 1
 
         # identify key (nsp) of least used nsp
-        current_smallest_count = sys.maxint
+        current_smallest_count = sys.maxsize
         for (nsp, count) in nsp_counts.items():
             if count < current_smallest_count:
                 current_least_used_nsp = nsp
index 78d0fb85f9dc0a45fecfcceb9630506d64cbeaef..fe50c167986e3c50948c0e0e997a949736b6fcd2 100644 (file)
@@ -69,6 +69,7 @@ cinder.tests.unit.test_hitachi_hbsd_snm2_iscsi
 cinder.tests.unit.test_hitachi_hnas_backend
 cinder.tests.unit.test_hitachi_hnas_iscsi
 cinder.tests.unit.test_hitachi_hnas_nfs
+cinder.tests.unit.test_hpe3par
 cinder.tests.unit.test_hp_xp_fc
 cinder.tests.unit.test_hplefthand
 cinder.tests.unit.test_huawei_drivers