Skip to content

Commit

Permalink
Merge pull request #54536 from garethgreenaway/2019_2_1_port_52589
Browse files Browse the repository at this point in the history
[master] Porting #52589 to master
  • Loading branch information
dwoz authored Nov 7, 2019
2 parents 336c792 + b33484e commit 920529e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion salt/states/blockdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,7 @@ def _checkblk(name):
Check if the blk exists and return its fstype if ok
'''

blk = __salt__['cmd.run']('blkid -o value -s TYPE {0}'.format(name))
blk = __salt__['cmd.run'](
['blkid', '-o', 'value', '-s', 'TYPE', name],
ignore_retcode=True)
return '' if not blk else blk
13 changes: 13 additions & 0 deletions tests/unit/states/test_blockdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from tests.support.mock import (
NO_MOCK,
NO_MOCK_REASON,
Mock,
MagicMock,
patch)

Expand Down Expand Up @@ -107,3 +108,15 @@ def test_formatted(self):
MagicMock(return_value=True)):
with patch.dict(blockdev.__opts__, {'test': False}):
self.assertDictEqual(blockdev.formatted(name), ret)

def test__checkblk(self):
'''
Confirm that we call cmd.run with ignore_retcode=True
'''
cmd_mock = Mock()
with patch.dict(blockdev.__salt__, {'cmd.run': cmd_mock}):
blockdev._checkblk('/dev/foo')

cmd_mock.assert_called_once_with(
['blkid', '-o', 'value', '-s', 'TYPE', '/dev/foo'],
ignore_retcode=True)

0 comments on commit 920529e

Please sign in to comment.