]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
FlashSystem reports error in _find_host_exhaustive()
authorEdwin Wang <edwin.wang@cn.ibm.com>
Thu, 19 Nov 2015 14:26:52 +0000 (08:26 -0600)
committerEdwin Wang <edwin.wang@cn.ibm.com>
Tue, 19 Jan 2016 00:54:07 +0000 (00:54 +0000)
While host was deleted by someone else, the deleted host still
existed in hosts. In _find_host_exhaustive(), all hosts would be
enumerated. Thus, 'lshost' command would fail in this situation.

In this fix,
* Adds hostname check before issue 'lshost' command for FC.
* Modifies map(lambda, x) to list comprehension for python 3
compatibility.
* Bump version to 1.0.7.

Change-Id: I989092e7aacbcd296717d4172035b3edd5b63348
Close-bug: 1505477

cinder/tests/unit/test_ibm_flashsystem.py
cinder/volume/drivers/ibm/flashsystem_common.py
cinder/volume/drivers/ibm/flashsystem_fc.py
cinder/volume/drivers/ibm/flashsystem_iscsi.py

index f5385c9570352a5a56dc68de1eac4afaf4a534bf..c076ec5eaaa879f697cfa495ddd8049cad73d7b1 100644 (file)
@@ -1202,6 +1202,13 @@ class FlashSystemDriverTestCase(test.TestCase):
         self.assertIsNone(self.driver._find_host_exhaustive(conn3,
                                                             [host1, host2]))
 
+        # case 2: hosts contains non-existent host info
+        with mock.patch.object(FlashSystemFakeDriver,
+                               '_ssh') as mock_ssh:
+            mock_ssh.return_value = ("pass", "")
+            self.driver._find_host_exhaustive(conn1, [host2])
+            self.assertFalse(mock_ssh.called)
+
         # clear environment
         self.driver._delete_host(host1)
         self.driver._delete_host(host2)
index bb06e3a5ed8c2a519b64c69f736a93265db51006..1f11031f4c2b0e0b41eb9e22608497fe2811edad 100644 (file)
@@ -75,10 +75,12 @@ class FlashSystemDriver(san.SanDriver):
     1.0.5 - Report capability of volume multiattach
     1.0.6 - Fix bug #1469581, add I/T mapping check in
             terminate_connection
+    1.0.7 - Fix bug #1505477, add host name check in
+            _find_host_exhaustive for FC
 
     """
 
-    VERSION = "1.0.6"
+    VERSION = "1.0.7"
 
     def __init__(self, *args, **kwargs):
         super(FlashSystemDriver, self).__init__(*args, **kwargs)
@@ -419,7 +421,7 @@ class FlashSystemDriver(san.SanDriver):
             'name' in header,
             '_get_host_from_connector', ssh_cmd, out, err)
         name_index = header.index('name')
-        hosts = map(lambda x: x.split('!')[name_index], host_lines)
+        hosts = [x.split('!')[name_index] for x in host_lines]
         hostname = self._find_host_exhaustive(connector, hosts)
 
         LOG.debug('leave: _get_host_from_connector: host %s.', hostname)
index f941d98c3b00ff3d7a7303c23a06d1fb30d6be98..9cd97b3a356b3832d594015da12b6475cb48529a 100644 (file)
@@ -32,7 +32,7 @@ from oslo_utils import excutils
 import six
 
 from cinder import exception
-from cinder.i18n import _, _LE, _LI
+from cinder.i18n import _, _LE, _LI, _LW
 from cinder import utils
 import cinder.volume.driver
 from cinder.volume.drivers.ibm import flashsystem_common as fscommon
@@ -67,10 +67,12 @@ class FlashSystemFCDriver(fscommon.FlashSystemDriver,
     1.0.5 - Report capability of volume multiattach
     1.0.6 - Fix bug #1469581, add I/T mapping check in
             terminate_connection
+    1.0.7 - Fix bug #1505477, add host name check in
+            _find_host_exhaustive for FC
 
     """
 
-    VERSION = "1.0.6"
+    VERSION = "1.0.7"
 
     def __init__(self, *args, **kwargs):
         super(FlashSystemFCDriver, self).__init__(*args, **kwargs)
@@ -133,19 +135,27 @@ class FlashSystemFCDriver(fscommon.FlashSystemDriver,
         return host_name
 
     def _find_host_exhaustive(self, connector, hosts):
-        for host in hosts:
+        hname = connector['host']
+        hnames = [ihost[0:ihost.rfind('-')] for ihost in hosts]
+        if hname in hnames:
+            host = hosts[hnames.index(hname)]
             ssh_cmd = ['svcinfo', 'lshost', '-delim', '!', host]
             out, err = self._ssh(ssh_cmd)
             self._assert_ssh_return(
                 out.strip(),
                 '_find_host_exhaustive', ssh_cmd, out, err)
-            for attr_line in out.split('\n'):
-                # If '!' not found, return the string and two empty strings
+            attr_lines = [attr_line for attr_line in out.split('\n')]
+            attr_parm = {}
+            for attr_line in attr_lines:
                 attr_name, foo, attr_val = attr_line.partition('!')
-                if (attr_name == 'WWPN' and
-                        'wwpns' in connector and attr_val.lower() in
-                        map(str.lower, map(str, connector['wwpns']))):
-                    return host
+                attr_parm[attr_name] = attr_val
+            if ('WWPN' in attr_parm.keys() and 'wwpns' in connector and
+                    attr_parm['WWPN'].lower() in
+                    map(str.lower, map(str, connector['wwpns']))):
+                return host
+        else:
+            LOG.warning(_LW('Host %(host)s was not found on backend storage.'),
+                        {'host': hname})
         return None
 
     def _get_conn_fc_wwpns(self):
index edec1082e32ab1fc967852742a8beddc517f408b..352deeeccc7c31da13bace4dd9ca773eb1bd86e2 100644 (file)
@@ -65,10 +65,12 @@ class FlashSystemISCSIDriver(fscommon.FlashSystemDriver,
     1.0.5 - Report capability of volume multiattach
     1.0.6 - Fix bug #1469581, add I/T mapping check in
             terminate_connection
+    1.0.7 - Fix bug #1505477, add host name check in
+            _find_host_exhaustive for FC
 
     """
 
-    VERSION = "1.0.6"
+    VERSION = "1.0.7"
 
     def __init__(self, *args, **kwargs):
         super(FlashSystemISCSIDriver, self).__init__(*args, **kwargs)