2016-05-09 17:06:44 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
Integration tests for timezone module
|
|
|
|
|
2016-05-12 21:40:37 +00:00
|
|
|
Linux and Solaris are supported
|
2016-05-09 17:06:44 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
# Import python libs
|
2018-01-19 20:59:53 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2016-05-09 17:06:44 +00:00
|
|
|
|
2018-07-26 20:44:55 +00:00
|
|
|
try:
|
2018-07-27 19:42:35 +00:00
|
|
|
import tzlocal # pylint: disable=unused-import
|
2018-07-26 20:44:55 +00:00
|
|
|
HAS_TZLOCAL = True
|
|
|
|
except ImportError:
|
|
|
|
HAS_TZLOCAL = False
|
|
|
|
|
2016-05-09 17:06:44 +00:00
|
|
|
# Import Salt Testing libs
|
2017-04-03 16:04:09 +00:00
|
|
|
from tests.support.case import ModuleCase
|
2018-07-26 20:44:55 +00:00
|
|
|
from tests.support.helpers import destructiveTest
|
|
|
|
from tests.support.unit import skipIf
|
|
|
|
|
|
|
|
# Import salt libs
|
2018-07-31 22:20:35 +00:00
|
|
|
import salt.utils.platform
|
2016-05-09 17:06:44 +00:00
|
|
|
|
|
|
|
|
2017-04-03 16:04:09 +00:00
|
|
|
class TimezoneLinuxModuleTest(ModuleCase):
|
2016-05-09 17:06:44 +00:00
|
|
|
def setUp(self):
|
|
|
|
'''
|
|
|
|
Set up Linux test environment
|
|
|
|
'''
|
|
|
|
ret_grain = self.run_function('grains.item', ['kernel'])
|
|
|
|
if 'Linux' not in ret_grain['kernel']:
|
|
|
|
self.skipTest('For Linux only')
|
2016-05-12 21:40:37 +00:00
|
|
|
super(TimezoneLinuxModuleTest, self).setUp()
|
2016-05-09 17:06:44 +00:00
|
|
|
|
|
|
|
def test_get_hwclock(self):
|
2016-05-12 21:40:37 +00:00
|
|
|
timescale = ['UTC', 'localtime']
|
2016-05-09 17:06:44 +00:00
|
|
|
ret = self.run_function('timezone.get_hwclock')
|
2016-05-12 21:40:37 +00:00
|
|
|
self.assertIn(ret, timescale)
|
|
|
|
|
|
|
|
|
2017-04-03 16:04:09 +00:00
|
|
|
class TimezoneSolarisModuleTest(ModuleCase):
|
2016-05-12 21:40:37 +00:00
|
|
|
def setUp(self):
|
|
|
|
'''
|
|
|
|
Set up Solaris test environment
|
|
|
|
'''
|
|
|
|
ret_grain = self.run_function('grains.item', ['os_family'])
|
|
|
|
if 'Solaris' not in ret_grain['os_family']:
|
|
|
|
self.skipTest('For Solaris only')
|
|
|
|
super(TimezoneSolarisModuleTest, self).setUp()
|
|
|
|
|
|
|
|
def test_get_hwclock(self):
|
|
|
|
timescale = ['UTC', 'localtime']
|
|
|
|
ret = self.run_function('timezone.get_hwclock')
|
|
|
|
self.assertIn(ret, timescale)
|
2018-07-26 20:44:55 +00:00
|
|
|
|
|
|
|
|
2018-07-31 22:20:35 +00:00
|
|
|
@skipIf(not salt.utils.platform.is_windows(), 'windows test only')
|
2018-07-26 20:44:55 +00:00
|
|
|
class TimezoneWindowsModuleTest(ModuleCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.pre = self.run_function('timezone.get_zone')
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
post = self.run_function('timezone.get_zone')
|
|
|
|
if self.pre != post:
|
|
|
|
self.run_function('timezone.set_zone', [self.pre])
|
|
|
|
|
|
|
|
def test_get_hwclock(self):
|
|
|
|
timescale = ['UTC', 'localtime']
|
|
|
|
ret = self.run_function('timezone.get_hwclock')
|
|
|
|
self.assertIn(ret, timescale)
|
|
|
|
|
|
|
|
@destructiveTest
|
|
|
|
def test_get_zone(self):
|
|
|
|
'''
|
|
|
|
test timezone.set_zone, get_zone and zone_compare
|
|
|
|
'''
|
|
|
|
|
|
|
|
zone = 'America/Inuvik' if not HAS_TZLOCAL else 'America/Denver'
|
|
|
|
|
|
|
|
# first set the zone
|
|
|
|
assert self.run_function('timezone.set_zone', [zone])
|
|
|
|
|
|
|
|
# check it set the correct zone
|
|
|
|
ret = self.run_function('timezone.get_zone')
|
|
|
|
assert zone in ret
|
|
|
|
|
|
|
|
# compare zones
|
|
|
|
assert self.run_function('timezone.zone_compare', [zone])
|
|
|
|
|
|
|
|
def test_get_offset(self):
|
|
|
|
'''
|
|
|
|
test timezone.get_offset
|
|
|
|
'''
|
|
|
|
ret = self.run_function('timezone.get_offset')
|
|
|
|
self.assertIn('-', ret)
|