Merge "Software RAID: Detect component & holder disks in broken RAIDs"
This commit is contained in:
commit
6bcd935092
ironic_python_agent
@ -137,9 +137,8 @@ def _get_component_devices(raid_device):
|
||||
raise errors.SoftwareRAIDError(msg)
|
||||
|
||||
lines = out.splitlines()
|
||||
for line in lines:
|
||||
if 'active sync' not in line:
|
||||
continue
|
||||
# the first line contains the md device itself
|
||||
for line in lines[1:]:
|
||||
device = re.findall(r'/dev/\w+', line)
|
||||
component_devices += device
|
||||
|
||||
@ -168,9 +167,8 @@ def get_holder_disks(raid_device):
|
||||
raise errors.SoftwareRAIDError(msg)
|
||||
|
||||
lines = out.splitlines()
|
||||
for line in lines:
|
||||
if 'active sync' not in line:
|
||||
continue
|
||||
# the first line contains the md device itself
|
||||
for line in lines[1:]:
|
||||
device = re.findall(r'/dev/\D+', line)
|
||||
holder_disks += device
|
||||
|
||||
|
@ -610,8 +610,7 @@ IPv6 Static Address 2:
|
||||
Status: disabled
|
||||
"""
|
||||
|
||||
MDADM_DETAIL_OUTPUT = ("""
|
||||
/dev/md0:
|
||||
MDADM_DETAIL_OUTPUT = ("""/dev/md0:
|
||||
Version : 1.0
|
||||
Creation Time : Fri Feb 15 12:37:44 2019
|
||||
Raid Level : raid1
|
||||
@ -640,6 +639,25 @@ Consistency Policy : resync
|
||||
""")
|
||||
|
||||
|
||||
MDADM_DETAIL_OUTPUT_BROKEN_RAID0 = ("""/dev/md126:
|
||||
Version : 1.2
|
||||
Raid Level : raid0
|
||||
Total Devices : 1
|
||||
Persistence : Superblock is persistent
|
||||
|
||||
State : inactive
|
||||
Working Devices : 1
|
||||
|
||||
Name : prj6ogxgyzd:1
|
||||
UUID : b5e136c0:a7e379b7:db25e45d:4b63928b
|
||||
Events : 0
|
||||
|
||||
Number Major Minor RaidDevice
|
||||
|
||||
- 8 2 - /dev/sda2
|
||||
""")
|
||||
|
||||
|
||||
class FakeHardwareManager(hardware.GenericHardwareManager):
|
||||
def __init__(self, hardware_support):
|
||||
self._hardware_support = hardware_support
|
||||
@ -2703,6 +2721,14 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
component_devices = hardware._get_component_devices(raid_device.name)
|
||||
self.assertEqual(['/dev/vde1', '/dev/vdf1'], component_devices)
|
||||
|
||||
@mock.patch.object(utils, 'execute', autospec=True)
|
||||
def test__get_component_devices_broken_raid0(self, mocked_execute):
|
||||
mocked_execute.side_effect = [(MDADM_DETAIL_OUTPUT_BROKEN_RAID0, '')]
|
||||
raid_device = hardware.BlockDevice('/dev/md126', 'RAID-0',
|
||||
1073741824, True)
|
||||
component_devices = hardware._get_component_devices(raid_device.name)
|
||||
self.assertEqual(['/dev/sda2'], component_devices)
|
||||
|
||||
@mock.patch.object(utils, 'execute', autospec=True)
|
||||
def test_get_holder_disks(self, mocked_execute):
|
||||
mocked_execute.side_effect = [(MDADM_DETAIL_OUTPUT, '')]
|
||||
@ -2711,6 +2737,14 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
holder_disks = hardware.get_holder_disks(raid_device.name)
|
||||
self.assertEqual(['/dev/vde', '/dev/vdf'], holder_disks)
|
||||
|
||||
@mock.patch.object(utils, 'execute', autospec=True)
|
||||
def test_get_holder_disks_broken_raid0(self, mocked_execute):
|
||||
mocked_execute.side_effect = [(MDADM_DETAIL_OUTPUT_BROKEN_RAID0, '')]
|
||||
raid_device = hardware.BlockDevice('/dev/md126', 'RAID-0',
|
||||
1073741824, True)
|
||||
holder_disks = hardware.get_holder_disks(raid_device.name)
|
||||
self.assertEqual(['/dev/sda'], holder_disks)
|
||||
|
||||
@mock.patch.object(hardware, 'get_holder_disks', autospec=True)
|
||||
@mock.patch.object(hardware, '_get_component_devices', autospec=True)
|
||||
@mock.patch.object(hardware, 'list_all_block_devices', autospec=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user