2015-05-18 15:55:03 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Rahul Handay <rahulha@saltstack.com>`
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import Python Libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-02-19 22:28:46 +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-05-18 15:55:03 +00:00
|
|
|
MagicMock,
|
|
|
|
patch,
|
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON
|
|
|
|
)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-02-19 22:28:46 +00:00
|
|
|
from salt.exceptions import CommandExecutionError
|
|
|
|
import salt.states.timezone as timezone
|
2015-05-18 15:55:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-02-19 22:28:46 +00:00
|
|
|
class TimezoneTestCase(TestCase, LoaderModuleMockMixin):
|
2015-05-18 15:55:03 +00:00
|
|
|
'''
|
|
|
|
Validate the timezone state
|
|
|
|
'''
|
2017-03-22 12:12:36 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {timezone: {}}
|
2017-02-19 22:28:46 +00:00
|
|
|
|
2015-05-18 15:55:03 +00:00
|
|
|
def test_system(self):
|
|
|
|
'''
|
|
|
|
Test to set the timezone for the system.
|
|
|
|
'''
|
|
|
|
ret = {'name': 'salt',
|
|
|
|
'changes': {},
|
|
|
|
'result': True,
|
|
|
|
'comment': ''}
|
|
|
|
mock = MagicMock(side_effect=[CommandExecutionError, True, True, True])
|
|
|
|
mock1 = MagicMock(side_effect=['local', 'localtime', 'localtime'])
|
|
|
|
mock2 = MagicMock(return_value=False)
|
|
|
|
with patch.dict(timezone.__salt__, {"timezone.zone_compare": mock,
|
|
|
|
"timezone.get_hwclock": mock1,
|
|
|
|
"timezone.set_hwclock": mock2}):
|
2015-12-18 12:54:04 +00:00
|
|
|
ret.update({'comment': "Unable to compare desired timezone"
|
2015-05-18 15:55:03 +00:00
|
|
|
" 'salt' to system timezone: ", 'result': False})
|
|
|
|
self.assertDictEqual(timezone.system('salt'), ret)
|
|
|
|
|
|
|
|
ret.update({'comment': 'Timezone salt already set,'
|
|
|
|
' UTC already set to salt', 'result': True})
|
|
|
|
self.assertDictEqual(timezone.system('salt'), ret)
|
|
|
|
|
|
|
|
with patch.dict(timezone.__opts__, {"test": True}):
|
|
|
|
ret.update({'comment': 'UTC needs to be set to True',
|
|
|
|
'result': None})
|
|
|
|
self.assertDictEqual(timezone.system('salt'), ret)
|
|
|
|
|
|
|
|
with patch.dict(timezone.__opts__, {"test": False}):
|
|
|
|
ret.update({'comment': 'Failed to set UTC to True',
|
|
|
|
'result': False})
|
|
|
|
self.assertDictEqual(timezone.system('salt'), ret)
|