Multipath Device Action Being Parsed as Name

Whenever find_multipath_device() was being called on an action
it would include the action as part of the device name. This patch
creates a list of actions and checks that they aren't preceding
the device name before parsing the rest of the device information
in find_multipath_device().

This patch is based on the approach that was taken in Nova until
it was abandoned in favor of the change being made in os-brick
instead. The Change-Id for the Nova change:
I8f1f769bb15ec10054e2fd73c4cf621389014cf1

Change-Id: I12a10ba189e4987cdf07bebdadbac0d4587c01d1
Closes-Bug: 1466444
This commit is contained in:
Kendall Nelson 2015-11-05 15:47:53 +00:00
parent 06042d4620
commit 7900cf38c2
2 changed files with 41 additions and 0 deletions

View File

@ -32,6 +32,9 @@ LOG = logging.getLogger(__name__)
MULTIPATH_ERROR_REGEX = re.compile("\w{3} \d+ \d\d:\d\d:\d\d \|.*$")
MULTIPATH_WWID_REGEX = re.compile("\((?P<wwid>.+)\)")
MULTIPATH_DEVICE_ACTIONS = ['unchanged:', 'reject:', 'reload:',
'switchpg:', 'rename:', 'create:',
'resize:']
class LinuxSCSI(executor.Executor):
@ -272,6 +275,10 @@ class LinuxSCSI(executor.Executor):
if lines:
mdev_name = lines[0].split(" ")[0]
if mdev_name in MULTIPATH_DEVICE_ACTIONS:
mdev_name = lines[0].split(" ")[1]
mdev = '/dev/mapper/%s' % mdev_name
# Confirm that the device is present.

View File

@ -14,6 +14,7 @@
import os
import os.path
import textwrap
import time
import mock
@ -457,3 +458,36 @@ loop0 0"""
path)
self.assertEqual(4, mock_sleep.call_count)
def test_find_multipath_device_with_action(self):
def fake_execute(*cmd, **kwargs):
out = textwrap.dedent("""
create: 36005076303ffc48e0000000000000101 dm-2 IBM,2107900
size=1.0G features='1 queue_if_no_path' hwhandler='0'
wp=rw
`-+- policy='round-robin 0' prio=-1 status=active
|- 6:0:2:0 sdd 8:64 active undef running
`- 6:1:0:3 sdc 8:32 active undef running
""")
return out, None
self.linuxscsi._execute = fake_execute
info = self.linuxscsi.find_multipath_device('/dev/sdd')
LOG.error("Device info: %s" % info)
self.assertEqual('36005076303ffc48e0000000000000101', info['id'])
self.assertEqual('36005076303ffc48e0000000000000101', info['name'])
self.assertEqual('/dev/mapper/36005076303ffc48e0000000000000101',
info['device'])
self.assertEqual("/dev/sdd", info['devices'][0]['device'])
self.assertEqual("6", info['devices'][0]['host'])
self.assertEqual("0", info['devices'][0]['channel'])
self.assertEqual("2", info['devices'][0]['id'])
self.assertEqual("0", info['devices'][0]['lun'])
self.assertEqual("/dev/sdc", info['devices'][1]['device'])
self.assertEqual("6", info['devices'][1]['host'])
self.assertEqual("1", info['devices'][1]['channel'])
self.assertEqual("0", info['devices'][1]['id'])
self.assertEqual("3", info['devices'][1]['lun'])