2015-05-26 09:56:50 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
|
|
|
'''
|
|
|
|
# Import Python libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-03-22 16:42:17 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf, TestCase
|
|
|
|
from tests.support.mock import (
|
2015-05-26 09:56:50 +00:00
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON,
|
|
|
|
MagicMock,
|
|
|
|
patch)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.states.ntp as ntp
|
2015-05-26 09:56:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-03-22 16:42:17 +00:00
|
|
|
class NtpTestCase(TestCase, LoaderModuleMockMixin):
|
2015-05-26 09:56:50 +00:00
|
|
|
'''
|
|
|
|
Test cases for salt.states.ntp
|
|
|
|
'''
|
2017-03-22 16:42:17 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {ntp: {}}
|
|
|
|
|
2015-05-26 09:56:50 +00:00
|
|
|
# 'managed' function tests: 1
|
|
|
|
|
|
|
|
def test_managed(self):
|
|
|
|
'''
|
|
|
|
Test to manage NTP servers.
|
|
|
|
'''
|
|
|
|
name = 'coffee-script'
|
|
|
|
|
|
|
|
ret = {'name': name,
|
|
|
|
'result': False,
|
|
|
|
'comment': '',
|
|
|
|
'changes': {}}
|
|
|
|
|
|
|
|
mock_lst = MagicMock(return_value=[])
|
|
|
|
with patch.dict(ntp.__salt__, {'ntp.get_servers': mock_lst,
|
|
|
|
'ntp.set_servers': mock_lst}):
|
|
|
|
comt = ('NTP servers already configured as specified')
|
|
|
|
ret.update({'comment': comt, 'result': True})
|
|
|
|
self.assertDictEqual(ntp.managed(name, []), ret)
|
|
|
|
|
|
|
|
with patch.dict(ntp.__opts__, {'test': True}):
|
|
|
|
comt = ('NTP servers will be updated to: coffee-script')
|
|
|
|
ret.update({'comment': comt, 'result': None})
|
|
|
|
self.assertDictEqual(ntp.managed(name, [name]), ret)
|
|
|
|
|
|
|
|
with patch.dict(ntp.__opts__, {'test': False}):
|
|
|
|
comt = ('Failed to update NTP servers')
|
|
|
|
ret.update({'comment': comt, 'result': False})
|
|
|
|
self.assertDictEqual(ntp.managed(name, [name]), ret)
|