From 6bff01dbde949b4b391a4fae0abb94005f075143 Mon Sep 17 00:00:00 2001 From: Adriano Rosso Date: Mon, 24 Aug 2015 14:13:30 -0300 Subject: [PATCH] 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 --- cinder/tests/unit/test_hitachi_hnas_iscsi.py | 21 ++++++++++++++++++ cinder/volume/drivers/hitachi/hnas_iscsi.py | 23 +++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/cinder/tests/unit/test_hitachi_hnas_iscsi.py b/cinder/tests/unit/test_hitachi_hnas_iscsi.py index 36189a277..8a22ac867 100644 --- a/cinder/tests/unit/test_hitachi_hnas_iscsi.py +++ b/cinder/tests/unit/test_hitachi_hnas_iscsi.py @@ -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) diff --git a/cinder/volume/drivers/hitachi/hnas_iscsi.py b/cinder/volume/drivers/hitachi/hnas_iscsi.py index 158b87c78..f38f6ccaf 100644 --- a/cinder/volume/drivers/hitachi/hnas_iscsi.py +++ b/cinder/volume/drivers/hitachi/hnas_iscsi.py @@ -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'], -- 2.45.2