]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Remove error messages from multipath command output before parsing
authortsekiyam <tsekiyam@dhcp47-227.lab.bos.redhat.com>
Tue, 17 Mar 2015 23:59:08 +0000 (19:59 -0400)
committerTomoki Sekiyama <tomoki.sekiyama@hds.com>
Wed, 18 Mar 2015 19:10:21 +0000 (19:10 +0000)
This fixes an issue in _get_multipath_device_name() that fails to
parse the output from 'multipath -ll <device>' command when the
stdout contains error messages in addition to the expected output.

Change-Id: I498edd950627daca01eaf6343e6d742440ca4b04
Related-Bug: #1380742
Closes-Bug: #1433202

cinder/brick/initiator/connector.py
cinder/tests/brick/test_brick_connector.py

index 45a85c942f220ec71ee882ac5a0a541596f722ad..ba469d622532f2682fac131d87cb9b7aec8d1c51 100644 (file)
@@ -16,6 +16,7 @@
 import copy
 import os
 import platform
+import re
 import socket
 import time
 
@@ -40,6 +41,7 @@ LOG = logging.getLogger(__name__)
 
 synchronized = lockutils.synchronized_with_prefix('brick-')
 DEVICE_SCAN_ATTEMPTS_DEFAULT = 3
+MULTIPATH_ERROR_REGEX = re.compile("\w{3} \d+ \d\d:\d\d:\d\d \|.*$")
 
 
 def _check_multipathd_running(root_helper, enforce_multipath):
@@ -583,7 +585,7 @@ class ISCSIConnector(InitiatorConnector):
                                   device],
                                   check_exit_code=[0, 1])[0]
         mpath_line = [line for line in out.splitlines()
-                      if "scsi_id" not in line]  # ignore udev errors
+                      if not re.match(MULTIPATH_ERROR_REGEX, line)]
         if len(mpath_line) > 0 and len(mpath_line[0]) > 0:
             return "/dev/mapper/%s" % mpath_line[0].split(" ")[0]
 
index 61b59f8902d123ae3e674d43035cb3ec99a1e1b4..4a55cb5e15e4b9c1455a0356dc24b83a71454e09 100644 (file)
@@ -517,6 +517,23 @@ class ISCSIConnectorTestCase(ConnectorTestCase):
                          self.connector.
                          _get_multipath_device_name('/dev/md-1'))
 
+    @mock.patch.object(os.path, 'realpath', return_value='/dev/sda')
+    @mock.patch.object(connector.ISCSIConnector, '_run_multipath')
+    def test_get_multipath_device_name_with_error(self, mock_multipath,
+                                                  mock_realpath):
+        mock_multipath.return_value = [
+            "Mar 17 14:32:37 | sda: No fc_host device for 'host-1'\n"
+            "mpathb (36e00000000010001) dm-4 IET ,VIRTUAL-DISK\n"
+            "size=1.0G features='0' hwhandler='0' wp=rw\n"
+            "|-+- policy='service-time 0' prio=0 status=active\n"
+            "| `- 2:0:0:1 sda 8:0 active undef running\n"
+            "`-+- policy='service-time 0' prio=0 status=enabled\n"
+            "  `- 3:0:0:1 sdb 8:16 active undef running\n"]
+        expected = '/dev/mapper/mpathb'
+        self.assertEqual(expected,
+                         self.connector.
+                         _get_multipath_device_name('/dev/sda'))
+
     def test_get_iscsi_devices(self):
         paths = [('ip-10.0.0.1:3260-iscsi-iqn.2013-01.ro.'
                  'com.netapp:node.netapp02-lun-0')]