Use timedatectl set-timezone to tzsetting

Fixed #26122
This commit is contained in:
Evgeny Vereshchagin 2015-08-08 04:48:37 +00:00
parent f65501fff4
commit e5eaf4686a
2 changed files with 17 additions and 3 deletions

View File

@ -109,6 +109,12 @@ def set_zone(timezone):
salt '*' timezone.set_zone 'America/Denver'
'''
if salt.utils.which('timedatectl'):
try:
__salt__['cmd.run']('timedatectl set-timezone {0}'.format(timezone))
except CommandExecutionError:
pass
if 'Solaris' in __grains__['os_family']:
zonepath = '/usr/share/lib/zoneinfo/{0}'.format(timezone)
else:

View File

@ -90,9 +90,9 @@ class TimezoneTestCase(TestCase):
'''
Test to unlinks, then symlinks /etc/localtime to the set timezone.
'''
ret = ('Zone does not exist: /usr/share/lib/zoneinfo/timezone')
mock = MagicMock(side_effect=[False, True, True])
with patch.dict(timezone.__grains__, {'os_family': 'Solaris'}):
def zone_checking_and_unlinking():
ret = ('Zone does not exist: /usr/share/lib/zoneinfo/timezone')
mock = MagicMock(side_effect=[False, True, True])
with patch.object(os.path, 'exists', mock):
self.assertEqual(timezone.set_zone('timezone'), ret)
@ -102,6 +102,14 @@ class TimezoneTestCase(TestCase):
MagicMock(return_value=None)}):
self.assertTrue(timezone.set_zone('timezone'))
with patch.dict(timezone.__grains__, {'os_family': 'Solaris'}):
with patch.object(salt.utils, 'which', return_value=False):
zone_checking_and_unlinking()
with patch.object(salt.utils, 'which', return_value=True):
with patch.dict(timezone.__salt__, {'cmd.run': MagicMock(return_value='')}):
zone_checking_and_unlinking()
def test_zone_compare(self):
'''
Test to checks the hash sum between the given timezone, and the