2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2016-05-09 11:06:44 -06:00
|
|
|
Integration tests for timezone module
|
|
|
|
|
2016-05-12 15:40:37 -06:00
|
|
|
Linux and Solaris are supported
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2024-02-27 10:24:22 +00:00
|
|
|
|
2025-01-07 20:34:01 -07:00
|
|
|
import subprocess
|
|
|
|
|
2021-01-30 09:03:57 +00:00
|
|
|
import pytest
|
2022-07-20 10:42:30 +01:00
|
|
|
|
2025-01-11 01:41:50 +00:00
|
|
|
import salt.utils.platform
|
2017-04-03 17:04:09 +01:00
|
|
|
from tests.support.case import ModuleCase
|
2018-07-26 16:44:55 -04:00
|
|
|
|
2020-04-02 20:10:20 -05:00
|
|
|
try:
|
2018-07-26 16:44:55 -04:00
|
|
|
import tzlocal # pylint: disable=unused-import
|
2020-04-02 20:10:20 -05:00
|
|
|
|
2018-07-31 18:20:35 -04:00
|
|
|
HAS_TZLOCAL = True
|
|
|
|
except ImportError:
|
|
|
|
HAS_TZLOCAL = False
|
2016-05-09 11:06:44 -06:00
|
|
|
|
|
|
|
|
2025-01-07 20:34:01 -07:00
|
|
|
def _check_systemctl():
|
|
|
|
if not hasattr(_check_systemctl, "memo"):
|
2025-01-11 01:41:50 +00:00
|
|
|
if not salt.utils.platform.is_linux():
|
|
|
|
_check_systemctl.memo = False
|
|
|
|
else:
|
|
|
|
proc = subprocess.run(["timedatectl"], capture_output=True, check=False)
|
|
|
|
_check_systemctl.memo = b"No such file or directory" in proc.stderr
|
2025-01-07 20:34:01 -07:00
|
|
|
return _check_systemctl.memo
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(_check_systemctl(), reason="systemctl degraded")
|
2017-04-03 17:04:09 +01:00
|
|
|
class TimezoneLinuxModuleTest(ModuleCase):
|
2016-05-09 11:06:44 -06:00
|
|
|
def setUp(self):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2016-05-09 11:06:44 -06:00
|
|
|
Set up Linux test environment
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2016-05-09 11:06:44 -06:00
|
|
|
ret_grain = self.run_function("grains.item", ["kernel"])
|
|
|
|
if "Linux" not in ret_grain["kernel"]:
|
|
|
|
self.skipTest("For Linux only")
|
2021-01-30 08:44:39 +00:00
|
|
|
super().setUp()
|
2016-05-09 11:06:44 -06:00
|
|
|
|
|
|
|
def test_get_hwclock(self):
|
2016-05-12 15:40:37 -06:00
|
|
|
timescale = ["UTC", "localtime"]
|
2016-05-09 11:06:44 -06:00
|
|
|
ret = self.run_function("timezone.get_hwclock")
|
2016-05-12 15:40:37 -06:00
|
|
|
self.assertIn(ret, timescale)
|
|
|
|
|
|
|
|
|
2025-01-07 20:34:01 -07:00
|
|
|
@pytest.mark.skipif(_check_systemctl(), reason="systemctl degraded")
|
2017-04-03 17:04:09 +01:00
|
|
|
class TimezoneSolarisModuleTest(ModuleCase):
|
2016-05-12 15:40:37 -06:00
|
|
|
def setUp(self):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2016-05-12 15:40:37 -06:00
|
|
|
Set up Solaris test environment
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2016-05-12 15:40:37 -06:00
|
|
|
ret_grain = self.run_function("grains.item", ["os_family"])
|
|
|
|
if "Solaris" not in ret_grain["os_family"]:
|
|
|
|
self.skipTest("For Solaris only")
|
2021-01-30 08:44:39 +00:00
|
|
|
super().setUp()
|
2016-05-12 15:40:37 -06:00
|
|
|
|
|
|
|
def test_get_hwclock(self):
|
|
|
|
timescale = ["UTC", "localtime"]
|
|
|
|
ret = self.run_function("timezone.get_hwclock")
|
|
|
|
self.assertIn(ret, timescale)
|
2018-07-26 16:44:55 -04:00
|
|
|
|
|
|
|
|
2022-12-04 13:08:39 +00:00
|
|
|
@pytest.mark.skip_unless_on_windows
|
2018-07-26 16:44:55 -04: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)
|
|
|
|
|
2021-01-30 09:03:57 +00:00
|
|
|
@pytest.mark.destructive_test
|
2018-07-26 16:44:55 -04:00
|
|
|
def test_get_zone(self):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2018-07-26 16:44:55 -04:00
|
|
|
test timezone.set_zone, get_zone and zone_compare
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2018-07-26 16:44:55 -04:00
|
|
|
|
|
|
|
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):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2018-07-26 16:44:55 -04:00
|
|
|
test timezone.get_offset
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2018-07-26 16:44:55 -04:00
|
|
|
ret = self.run_function("timezone.get_offset")
|
|
|
|
self.assertIn("-", ret)
|