Port HP 3PAR driver to Python 3

* 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
This commit is contained in:
Victor Stinner 2015-11-05 16:22:11 +01:00
parent a61b0e6c22
commit 3e002b57c3
4 changed files with 16 additions and 9 deletions

View 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)

View 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('+', '.')

View 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

View 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