from lxml import etree
import mock
-from six.moves import urllib
+import requests
from cinder import exception
from cinder import test
self.client = dothill.DotHillClient(self.ip, self.login, self.passwd,
self.protocol)
- @mock.patch('six.moves.urllib.request.urlopen')
- def test_login(self, mock_url_open):
+ @mock.patch('requests.get')
+ def test_login(self, mock_requests_get):
m = mock.Mock()
- m.read.side_effect = [resp_login]
- mock_url_open.return_value = m
+ m.text.encode.side_effect = [resp_login]
+ mock_requests_get.return_value = m
self.client.login()
self.assertEqual(session_key, self.client._session_key)
- m.read.side_effect = [resp_badlogin]
+ m.text.encode.side_effect = [resp_badlogin]
self.assertRaises(exception.DotHillAuthenticationError,
self.client.login)
arg2='val2')
self.assertEqual('http://10.0.0.1/api/path/arg2/val2/arg1/arg3', url)
- @mock.patch('six.moves.urllib.request.urlopen')
- def test_request(self, mock_url_open):
+ @mock.patch('requests.get')
+ def test_request(self, mock_requests_get):
self.client._session_key = session_key
m = mock.Mock()
- m.read.side_effect = [response_ok, malformed_xml,
- urllib.error.URLError("error")]
- mock_url_open.return_value = m
+ m.text.encode.side_effect = [response_ok, malformed_xml,
+ requests.exceptions.
+ RequestException("error")]
+ mock_requests_get.return_value = m
ret = self.client._request('/path')
self.assertTrue(type(ret) == etree._Element)
self.assertRaises(exception.DotHillConnectionError,
from lxml import etree
from oslo_log import log as logging
+import requests
import six
-from six.moves import urllib
from cinder import exception
from cinder.i18n import _LE
url = self._base_url + "/login/" + digest
try:
- xml = urllib.request.urlopen(url).read()
- except urllib.error.URLError:
+ xml = requests.get(url)
+ except requests.exceptions.RequestException:
raise exception.DotHillConnectionError
- self._get_auth_token(xml)
+ self._get_auth_token(xml.text.encode('utf8'))
if self._session_key is None:
raise exception.DotHillAuthenticationError
url = self._build_request_url(path, *args, **kargs)
headers = {'dataType': 'api', 'sessionKey': self._session_key}
- req = urllib.request.Request(url, headers=headers)
try:
- xml = urllib.request.urlopen(req).read()
- tree = etree.XML(xml)
+ xml = requests.get(url, headers=headers)
+ tree = etree.XML(xml.text.encode('utf8'))
except Exception:
raise exception.DotHillConnectionError
def logout(self):
url = self._base_url + '/exit'
try:
- urllib.request.urlopen(url)
+ requests.get(url)
return True
except Exception:
return False
fceec30e-98bc-4ce5-85ff-d7309cc17cc2
to
v_O7DDpi8TOWF_9cwnMF
-
- We convert the 128(32*4) bits of the uuid into a 24character long
+ We convert the 128(32*4) bits of the uuid into a 24 characters long
base64 encoded string. This still exceeds the limit of 20 characters
- so we truncate the name later.
+ in some models so we return 19 characters because the
+ _get_{vol,snap}_name functions prepend a character.
"""
uuid_str = name.replace("-", "")
vol_uuid = uuid.UUID('urn:uuid:%s' % uuid_str)
- vol_encoded = base64.b64encode(vol_uuid.bytes)
+ vol_encoded = base64.urlsafe_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
- vol_encoded = vol_encoded.replace('+', '.')
- # since we use http URLs to send paramters, '/' is not an acceptable
- # parameter
- vol_encoded = vol_encoded.replace('/', '_')
-
- # NOTE:we limit the size to 20 characters since the array
- # doesn't support more than that for now. Duplicates should happen very
- # rarely.
- # We return 19 chars here because the _get_{vol,snap}_name functions
- # prepend a character
return vol_encoded[:19]
def check_flags(self, options, required_flags):