2015-01-07 13:19:12 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2018-05-28 21:13:12 +00:00
|
|
|
:codeauthor: Rupesh Tare <rupesht@saltstack.com>
|
2015-01-07 13:19:12 +00:00
|
|
|
'''
|
|
|
|
|
2015-01-08 19:44:34 +00:00
|
|
|
# Import Python libs
|
2018-01-21 20:08:08 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2017-02-19 15:35:30 +00:00
|
|
|
import os.path
|
2015-01-08 19:44:34 +00:00
|
|
|
|
2015-01-07 13:19:12 +00:00
|
|
|
# Import Salt Testing Libs
|
2017-02-19 15:35:30 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import TestCase, skipIf
|
|
|
|
from tests.support.mock import (
|
2015-01-07 13:19:12 +00:00
|
|
|
MagicMock,
|
|
|
|
patch,
|
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON
|
|
|
|
)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.modules.devmap as devmap
|
2015-01-07 13:19:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-02-19 15:35:30 +00:00
|
|
|
class DevMapTestCase(TestCase, LoaderModuleMockMixin):
|
2015-01-07 13:19:12 +00:00
|
|
|
'''
|
|
|
|
Test cases for salt.modules.devmap
|
|
|
|
'''
|
2017-03-22 12:12:36 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {devmap: {}}
|
2017-02-19 15:35:30 +00:00
|
|
|
|
2015-01-07 13:19:12 +00:00
|
|
|
def test_multipath_list(self):
|
|
|
|
'''
|
|
|
|
Test for Device-Mapper Multipath list
|
|
|
|
'''
|
|
|
|
mock = MagicMock(return_value='A')
|
|
|
|
with patch.dict(devmap.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertEqual(devmap.multipath_list(), ['A'])
|
|
|
|
|
|
|
|
def test_multipath_flush(self):
|
|
|
|
'''
|
|
|
|
Test for Device-Mapper Multipath flush
|
|
|
|
'''
|
|
|
|
mock = MagicMock(return_value=False)
|
|
|
|
with patch.object(os.path, 'exists', mock):
|
|
|
|
self.assertEqual(devmap.multipath_flush('device'),
|
|
|
|
'device does not exist')
|
|
|
|
|
|
|
|
mock = MagicMock(return_value=True)
|
|
|
|
with patch.object(os.path, 'exists', mock):
|
|
|
|
mock = MagicMock(return_value='A')
|
|
|
|
with patch.dict(devmap.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertEqual(devmap.multipath_flush('device'), ['A'])
|