2014-02-12 15:32:55 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2014-02-11 08:11:29 +00:00
|
|
|
|
2014-02-12 15:32:55 +00:00
|
|
|
# Import Salt Testing Libs
|
|
|
|
from salttesting.unit import skipIf, TestCase
|
|
|
|
from salttesting.helpers import ensure_in_syspath
|
|
|
|
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
|
|
|
ensure_in_syspath('../../')
|
2014-02-11 08:11:29 +00:00
|
|
|
|
2014-02-12 15:32:55 +00:00
|
|
|
# Import Salt Libs
|
|
|
|
import salt.modules.blockdev as blockdev
|
2014-02-11 08:11:29 +00:00
|
|
|
|
2014-02-12 15:32:55 +00:00
|
|
|
blockdev.__salt__ = {
|
|
|
|
'cmd.has_exec': MagicMock(return_value=True),
|
|
|
|
'config.option': MagicMock(return_value=None)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2014-02-11 08:11:29 +00:00
|
|
|
class TestBlockdevModule(TestCase):
|
|
|
|
def test_dump(self):
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(blockdev.__salt__, {'cmd.run_all': mock}):
|
|
|
|
blockdev.dump('/dev/sda')
|
|
|
|
mock.assert_called_once_with(
|
2014-02-12 15:32:55 +00:00
|
|
|
'blockdev --getro --getsz --getss --getpbsz --getiomin '
|
|
|
|
'--getioopt --getalignoff --getmaxsect --getsize '
|
2015-01-06 23:00:12 +00:00
|
|
|
'--getsize64 --getra --getfra /dev/sda',
|
2015-01-07 00:57:50 +00:00
|
|
|
python_shell=False
|
2014-02-11 08:11:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_wipe(self):
|
|
|
|
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch.dict(blockdev.__salt__, {'cmd.run_all': mock}):
|
|
|
|
blockdev.wipe('/dev/sda')
|
|
|
|
mock.assert_called_once_with(
|
2015-01-06 23:00:12 +00:00
|
|
|
'wipefs /dev/sda',
|
2015-01-07 00:57:50 +00:00
|
|
|
python_shell=False
|
2014-02-11 08:11:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_tune(self):
|
2014-02-12 15:32:55 +00:00
|
|
|
mock = MagicMock(return_value='712971264\n512\n512\n512\n0\n0\n88\n712971264\n365041287168\n512\n512')
|
2014-02-11 08:11:29 +00:00
|
|
|
with patch.dict(blockdev.__salt__, {'cmd.run': mock}):
|
2014-02-12 15:32:55 +00:00
|
|
|
mock_dump = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
|
|
|
with patch('salt.modules.blockdev.dump', mock_dump):
|
|
|
|
kwargs = {'read-ahead': 512, 'filesystem-read-ahead': 512}
|
|
|
|
blockdev.tune('/dev/sda', **kwargs)
|
|
|
|
mock.assert_called_once_with(
|
2015-01-06 23:00:12 +00:00
|
|
|
'blockdev --setra 512 --setfra 512 /dev/sda',
|
2015-01-07 00:57:50 +00:00
|
|
|
python_shell=False
|
2014-02-12 15:32:55 +00:00
|
|
|
)
|
2014-03-31 01:58:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(TestBlockdevModule, needs_daemon=False)
|