#
"""Unit tests for OpenStack Cinder DotHill driver."""
-import urllib2
from lxml import etree
import mock
+from six.moves import urllib
from cinder import exception
from cinder import test
self.client = dothill.DotHillClient(self.ip, self.login, self.passwd,
self.protocol)
- @mock.patch('urllib2.urlopen')
+ @mock.patch('six.moves.urllib.request.urlopen')
def test_login(self, mock_url_open):
m = mock.Mock()
m.read.side_effect = [resp_login]
arg2='val2')
self.assertEqual('http://10.0.0.1/api/path/arg2/val2/arg1/arg3', url)
- @mock.patch('urllib2.urlopen')
+ @mock.patch('six.moves.urllib.request.urlopen')
def test_request(self, mock_url_open):
self.client._session_key = session_key
m = mock.Mock()
m.read.side_effect = [response_ok, malformed_xml,
- urllib2.URLError("error")]
+ urllib.error.URLError("error")]
mock_url_open.return_value = m
ret = self.client._request('/path')
self.assertTrue(type(ret) == etree._Element)
self.driver.iscsi_ips = ['10.0.0.11']
self.driver.initialize_iscsi_ports()
mock_iqns.side_effect = [['id2']]
- mock_portals.side_effect = {'10.0.0.11': 'Up', '10.0.0.12': 'Up'}
+ mock_portals.return_value = {'10.0.0.11': 'Up', '10.0.0.12': 'Up'}
self.assertRaises(exception.Invalid,
self.driver.initialize_connection, test_volume,
from hashlib import md5
import math
import time
-import urllib2
from lxml import etree
from oslo_log import log as logging
+import six
+from six.moves import urllib
from cinder import exception
from cinder.i18n import _LE
def login(self):
"""Authenticates the service on the device."""
- hash_ = md5("%s_%s" % (self._login, self._password))
+ hash_ = "%s_%s" % (self._login, self._password)
+ if six.PY3:
+ hash_ = hash_.encode('utf-8')
+ hash_ = md5(hash_)
digest = hash_.hexdigest()
url = self._base_url + "/login/" + digest
try:
- xml = urllib2.urlopen(url).read()
- except urllib2.URLError:
+ xml = urllib.request.urlopen(url).read()
+ except urllib.error.URLError:
raise exception.DotHillConnectionError
self._get_auth_token(xml)
url = self._build_request_url(path, *args, **kargs)
headers = {'dataType': 'api', 'sessionKey': self._session_key}
- req = urllib2.Request(url, headers=headers)
+ req = urllib.request.Request(url, headers=headers)
try:
- xml = urllib2.urlopen(req).read()
+ xml = urllib.request.urlopen(req).read()
tree = etree.XML(xml)
except Exception:
raise exception.DotHillConnectionError
def logout(self):
url = self._base_url + '/exit'
try:
- urllib2.urlopen(url)
+ urllib.request.urlopen(url)
return True
except Exception:
return False
uuid_str = name.replace("-", "")
vol_uuid = uuid.UUID('urn:uuid:%s' % uuid_str)
vol_encoded = base64.b64encode(vol_uuid.bytes)
+ if six.PY3:
+ vol_encoded = vol_encoded.decode('ascii')
vol_encoded = vol_encoded.replace('=', '')
# + is not a valid character for DotHill
self.client.delete_volume(volume_name)
except exception.DotHillRequestError as ex:
# if the volume wasn't found, ignore the error
- if 'The volume was not found on this system.' in ex:
+ if 'The volume was not found on this system.' in ex.args:
return
LOG.exception(_LE("Deletion of volume %s failed."), volume['id'])
raise exception.Invalid(ex)
self.client.delete_snapshot(snap_name)
except exception.DotHillRequestError as ex:
# if the volume wasn't found, ignore the error
- if 'The volume was not found on this system.' in ex:
+ if 'The volume was not found on this system.' in ex.args:
return
LOG.exception(_LE("Deleting snapshot %s failed"), snapshot['id'])
raise exception.Invalid(ex)
cinder.tests.unit.test_dellfc \
cinder.tests.unit.test_dellsc \
cinder.tests.unit.test_dellscapi \
+ cinder.tests.unit.test_dothill \
cinder.tests.unit.test_drbdmanagedrv \
cinder.tests.unit.test_emc_xtremio \
cinder.tests.unit.test_eqlx \