HNAS iSCSI manage does not work with spaces

Currently, HNAS iSCSI driver does not work when trying to manage a
volume that contains one or more space in the name.
This patch fixes this functionality and performs some other minor
adjustments.

Change-Id: I2ba6407478c293f20925171d80dcc8f97f2110c7
Closes-bug: #1500544
This commit is contained in:
Adriano Rosso 2015-08-24 14:13:30 -03:00
parent c7255b6af1
commit 6bff01dbde
2 changed files with 39 additions and 5 deletions

View File

@ -533,3 +533,24 @@ class HNASiSCSIDriverTest(test.TestCase):
self.assertRaises(exception.ManageExistingVolumeTypeMismatch,
self.driver.manage_existing, vol, existing_vol_ref)
m_get_extra_specs.assert_called_once_with('1')
def test_manage_existing_invalid_volume_name(self):
vol = _VOLUME.copy()
existing_vol_ref = {'source-name': 'fs2/t/est_volume'}
self.assertRaises(exception.ManageExistingInvalidReference,
self.driver.manage_existing, vol, existing_vol_ref)
def test_manage_existing_without_volume_name(self):
vol = _VOLUME.copy()
existing_vol_ref = {'source-name': 'fs2/'}
self.assertRaises(exception.ManageExistingInvalidReference,
self.driver.manage_existing, vol, existing_vol_ref)
def test_manage_existing_with_FS_and_spaces(self):
vol = _VOLUME.copy()
existing_vol_ref = {'source-name': 'fs2/ '}
self.assertRaises(exception.ManageExistingInvalidReference,
self.driver.manage_existing, vol, existing_vol_ref)

View File

@ -874,12 +874,19 @@ class HDSISCSIDriver(driver.ISCSIDriver):
:param vol_ref: existing volume to take under management
"""
vol_info = vol_ref.split('/')
vol_info = vol_ref.strip().split('/')
fs_label = vol_info[0]
vol_name = vol_info[1]
if len(vol_info) == 2 and '' not in vol_info:
fs_label = vol_info[0]
vol_name = vol_info[1]
return fs_label, vol_name
return fs_label, vol_name
else:
msg = (_("The reference to the volume in the backend should have "
"the format file_system/volume_name (volume_name cannot "
"contain '/')"))
raise exception.ManageExistingInvalidReference(
existing_ref=vol_ref, reason=msg)
def manage_existing_get_size(self, volume, existing_vol_ref):
"""Gets the size to manage_existing.
@ -902,6 +909,8 @@ class HDSISCSIDriver(driver.ISCSIDriver):
"Volume name: %(vol_name)s.",
{'fs_label': fs_label, 'vol_name': vol_name})
vol_name = "'{}'".format(vol_name)
lu_info = self.bend.get_existing_lu_info(self.config['hnas_cmd'],
self.config['mgmt_ip0'],
self.config['username'],
@ -920,7 +929,9 @@ class HDSISCSIDriver(driver.ISCSIDriver):
else:
raise exception.ManageExistingInvalidReference(
existing_ref=existing_vol_ref,
reason=_('Volume not found on configured storage backend.'))
reason=_('Volume not found on configured storage backend. '
'If your volume name contains "/", please rename it '
'and try to manage again.'))
def manage_existing(self, volume, existing_vol_ref):
"""Manages an existing volume.
@ -944,6 +955,8 @@ class HDSISCSIDriver(driver.ISCSIDriver):
self._check_pool_and_fs(volume, fs_label)
vol_name = "'{}'".format(vol_name)
self.bend.rename_existing_lu(self.config['hnas_cmd'],
self.config['mgmt_ip0'],
self.config['username'],