Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Backport 52150) mdadm_raid: Optionally ignore errors on examine. #55001

Merged
merged 4 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions salt/modules/mdadm_raid.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,25 @@ def assemble(name,
return __salt__['cmd.run'](cmd, python_shell=False)


def examine(device):
def examine(device, quiet=False):
'''
Show detail for a specified RAID component device

device
Device to examine, that is part of the RAID

quiet
If the device is not part of the RAID, do not show any error

CLI Example:

.. code-block:: bash

salt '*' raid.examine '/dev/sda1'
'''
res = __salt__['cmd.run_stdout']('mdadm -Y -E {0}'.format(device), output_loglevel='trace', python_shell=False)
res = __salt__['cmd.run_stdout']('mdadm -Y -E {0}'.format(device),
python_shell=False,
ignore_retcode=quiet)
ret = {}

for line in res.splitlines():
Expand Down
2 changes: 1 addition & 1 deletion salt/states/mdadm_raid.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def present(name,
if dev == 'missing' or not __salt__['file.access'](dev, 'f'):
missing.append(dev)
continue
superblock = __salt__['raid.examine'](dev)
superblock = __salt__['raid.examine'](dev, quiet=True)

if 'MD_UUID' in superblock:
uuid = superblock['MD_UUID']
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/modules/test_mdadm_raid.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,26 @@ def test_create_test_mode(self):
'--force -l 5 -e default -n 3 '
'/dev/sdb1 /dev/sdc1 /dev/sdd1'.split()), sorted(ret.split()))
assert not mock.called, 'test mode failed, cmd.run called'

def test_examine(self):
'''
Test for mdadm_raid.examine
'''
mock = MagicMock(return_value='ARRAY /dev/md/pool metadata=1.2 UUID=567da122:fb8e445e:55b853e0:81bd0a3e name=positron:pool')
with patch.dict(mdadm.__salt__, {'cmd.run_stdout': mock}):
self.assertEqual(mdadm.examine('/dev/md0'),
{
'ARRAY /dev/md/pool metadata': '1.2 UUID=567da122:fb8e445e:55b853e0:81bd0a3e name=positron:pool'
})
mock.assert_called_with('mdadm -Y -E /dev/md0', ignore_retcode=False,
python_shell=False)

def test_examine_quiet(self):
'''
Test for mdadm_raid.examine
'''
mock = MagicMock(return_value='')
with patch.dict(mdadm.__salt__, {'cmd.run_stdout': mock}):
self.assertEqual(mdadm.examine('/dev/md0', quiet=True), {})
mock.assert_called_with('mdadm -Y -E /dev/md0', ignore_retcode=True,
python_shell=False)