Merge "nimble: handle unicode strings in volume create"
This commit is contained in:
commit
d414feae98
@ -324,6 +324,43 @@ class NimbleDriverVolumeTestCase(NimbleDriverBaseTestCase):
|
||||
'iSCSI',
|
||||
False)
|
||||
|
||||
@mock.patch(NIMBLE_URLLIB2)
|
||||
@mock.patch(NIMBLE_CLIENT)
|
||||
@mock.patch.object(obj_volume.VolumeList, 'get_all_by_host',
|
||||
mock.Mock(return_value=[]))
|
||||
@mock.patch.object(volume_types, 'get_volume_type_extra_specs',
|
||||
mock.Mock(type_id=FAKE_TYPE_ID, return_value={
|
||||
'nimble:perfpol-name': 'default',
|
||||
'nimble:encryption': 'yes'}))
|
||||
@NimbleDriverBaseTestCase.client_mock_decorator(create_configuration(
|
||||
NIMBLE_SAN_LOGIN, NIMBLE_SAN_PASS, NIMBLE_MANAGEMENT_IP,
|
||||
'default', '*'))
|
||||
def test_create_volume_with_unicode(self):
|
||||
self.mock_client_service.get_vol_info.return_value = (
|
||||
FAKE_GET_VOL_INFO_RESPONSE)
|
||||
self.mock_client_service.get_netconfig.return_value = (
|
||||
FAKE_POSITIVE_NETCONFIG_RESPONSE)
|
||||
|
||||
self.assertEqual({
|
||||
'provider_location': '172.18.108.21:3260 iqn.test',
|
||||
'provider_auth': None},
|
||||
self.driver.create_volume({'name': 'testvolume',
|
||||
'size': 1,
|
||||
'volume_type_id': None,
|
||||
'display_name': u'unicode_name',
|
||||
'display_description': ''}))
|
||||
|
||||
self.mock_client_service.create_vol.assert_called_once_with(
|
||||
{'name': 'testvolume',
|
||||
'size': 1,
|
||||
'volume_type_id': None,
|
||||
'display_name': u'unicode_name',
|
||||
'display_description': ''},
|
||||
'default',
|
||||
False,
|
||||
'iSCSI',
|
||||
False)
|
||||
|
||||
@mock.patch(NIMBLE_URLLIB2)
|
||||
@mock.patch(NIMBLE_CLIENT)
|
||||
@mock.patch.object(obj_volume.VolumeList, 'get_all_by_host',
|
||||
|
@ -1098,6 +1098,12 @@ class NimbleRestAPIExecutor(object):
|
||||
{'name': response['name']})
|
||||
return response['name']
|
||||
|
||||
def _is_ascii(self, value):
|
||||
try:
|
||||
return all(ord(c) < 128 for c in value)
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
def _execute_create_vol(self, volume, pool_name, reserve, protocol,
|
||||
is_gst_enabled):
|
||||
"""Create volume
|
||||
@ -1109,9 +1115,20 @@ class NimbleRestAPIExecutor(object):
|
||||
volume_size = volume['size'] * units.Ki
|
||||
reserve_size = 100 if reserve else 0
|
||||
# Set volume description
|
||||
display_list = [getattr(volume, 'display_name', ''),
|
||||
getattr(volume, 'display_description', '')]
|
||||
description = ':'.join(filter(None, display_list))
|
||||
display_name = getattr(volume, 'display_name', '')
|
||||
display_description = getattr(volume, 'display_description', '')
|
||||
if self._is_ascii(display_name) and self._is_ascii(
|
||||
display_description):
|
||||
display_list = [getattr(volume, 'display_name', ''),
|
||||
getattr(volume, 'display_description', '')]
|
||||
description = ':'.join(filter(None, display_list))
|
||||
elif self._is_ascii(display_name):
|
||||
description = display_name
|
||||
elif self._is_ascii(display_description):
|
||||
description = display_description
|
||||
else:
|
||||
description = ""
|
||||
|
||||
# Limit description size to 254 characters
|
||||
description = description[:254]
|
||||
pool_id = self.get_pool_id(pool_name)
|
||||
|
Loading…
x
Reference in New Issue
Block a user