2015-01-28 05:58:15 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
|
|
|
'''
|
|
|
|
|
2015-01-30 15:24:42 +00:00
|
|
|
# Import Python libs
|
2018-01-21 20:08:08 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2015-01-30 15:24:42 +00:00
|
|
|
|
2015-01-28 05:58:15 +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-28 05:58:15 +00:00
|
|
|
MagicMock,
|
|
|
|
patch,
|
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON
|
|
|
|
)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.modules.drbd as drbd
|
2015-01-28 05:58:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-02-19 15:35:30 +00:00
|
|
|
class DrbdTestCase(TestCase, LoaderModuleMockMixin):
|
2015-01-28 05:58:15 +00:00
|
|
|
'''
|
|
|
|
Test cases for salt.modules.drbd
|
|
|
|
'''
|
2017-03-22 12:12:36 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {drbd: {}}
|
|
|
|
|
2015-01-28 05:58:15 +00:00
|
|
|
# 'overview' function tests: 1
|
|
|
|
|
|
|
|
def test_overview(self):
|
|
|
|
'''
|
|
|
|
Test if it shows status of the DRBD devices
|
|
|
|
'''
|
|
|
|
ret = {'connection state': 'True',
|
|
|
|
'device': 'Stack',
|
|
|
|
'fs': 'None',
|
|
|
|
'local disk state': 'UpToDate',
|
|
|
|
'local role': 'master',
|
|
|
|
'minor number': 'Salt',
|
|
|
|
'mountpoint': 'True',
|
|
|
|
'partner disk state': 'UpToDate',
|
|
|
|
'partner role': 'minion',
|
|
|
|
'percent': '888',
|
|
|
|
'remains': '666',
|
|
|
|
'total size': '50',
|
|
|
|
'used': '50'}
|
|
|
|
mock = MagicMock(return_value='Salt:Stack True master/minion \
|
|
|
|
UpToDate/UpToDate True None 50 50 666 888')
|
|
|
|
with patch.dict(drbd.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertDictEqual(drbd.overview(), ret)
|
|
|
|
|
|
|
|
ret = {'connection state': 'True',
|
|
|
|
'device': 'Stack',
|
|
|
|
'local disk state': 'UpToDate',
|
|
|
|
'local role': 'master',
|
|
|
|
'minor number': 'Salt',
|
|
|
|
'partner disk state': 'partner',
|
|
|
|
'partner role': 'minion',
|
|
|
|
'synched': '5050',
|
|
|
|
'synchronisation: ': 'syncbar'}
|
|
|
|
mock = MagicMock(return_value='Salt:Stack True master/minion \
|
|
|
|
UpToDate/partner syncbar None 50 50')
|
|
|
|
with patch.dict(drbd.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertDictEqual(drbd.overview(), ret)
|