]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
HNAS iSCSI manage does not work with spaces
authorAdriano Rosso <adriano.rosso@fit-tecnologia.org.br>
Mon, 24 Aug 2015 17:13:30 +0000 (14:13 -0300)
committerAdriano Rosso <adriano.rosso@fit-tecnologia.org.br>
Fri, 2 Oct 2015 13:14:01 +0000 (10:14 -0300)
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
cinder/volume/drivers/hitachi/hnas_iscsi.py

index 36189a277b175382f2c3ee19b4b12133cd7bdd18..8a22ac86740d67b0c828f518ce41131b353e021a 100644 (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)
index 158b87c787782aacd9cf251555a3d8daf41fefe3..f38f6ccaf2e5a4499158b3de74985d0edd7d3b66 100644 (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'],