From c93ba4230dd5e4e623cf6317df17deaa562d08c3 Mon Sep 17 00:00:00 2001 From: tsekiyam Date: Tue, 17 Mar 2015 19:59:08 -0400 Subject: [PATCH] Remove error messages from multipath command output before parsing This fixes an issue in _get_multipath_device_name() that fails to parse the output from 'multipath -ll ' 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 | 4 +++- cinder/tests/brick/test_brick_connector.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cinder/brick/initiator/connector.py b/cinder/brick/initiator/connector.py index 45a85c942..ba469d622 100644 --- a/cinder/brick/initiator/connector.py +++ b/cinder/brick/initiator/connector.py @@ -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] diff --git a/cinder/tests/brick/test_brick_connector.py b/cinder/tests/brick/test_brick_connector.py index 61b59f890..4a55cb5e1 100644 --- a/cinder/tests/brick/test_brick_connector.py +++ b/cinder/tests/brick/test_brick_connector.py @@ -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')] -- 2.45.2