test_timezone.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # -*- coding: utf-8 -*-
  2. """
  3. Integration tests for timezone module
  4. Linux and Solaris are supported
  5. """
  6. # Import python libs
  7. from __future__ import absolute_import, print_function, unicode_literals
  8. # Import salt libs
  9. import salt.utils.platform
  10. # Import Salt Testing libs
  11. from tests.support.case import ModuleCase
  12. from tests.support.helpers import destructiveTest
  13. from tests.support.unit import skipIf
  14. try:
  15. import tzlocal # pylint: disable=unused-import
  16. HAS_TZLOCAL = True
  17. except ImportError:
  18. HAS_TZLOCAL = False
  19. class TimezoneLinuxModuleTest(ModuleCase):
  20. def setUp(self):
  21. """
  22. Set up Linux test environment
  23. """
  24. ret_grain = self.run_function("grains.item", ["kernel"])
  25. if "Linux" not in ret_grain["kernel"]:
  26. self.skipTest("For Linux only")
  27. super(TimezoneLinuxModuleTest, self).setUp()
  28. def test_get_hwclock(self):
  29. timescale = ["UTC", "localtime"]
  30. ret = self.run_function("timezone.get_hwclock")
  31. self.assertIn(ret, timescale)
  32. class TimezoneSolarisModuleTest(ModuleCase):
  33. def setUp(self):
  34. """
  35. Set up Solaris test environment
  36. """
  37. ret_grain = self.run_function("grains.item", ["os_family"])
  38. if "Solaris" not in ret_grain["os_family"]:
  39. self.skipTest("For Solaris only")
  40. super(TimezoneSolarisModuleTest, self).setUp()
  41. def test_get_hwclock(self):
  42. timescale = ["UTC", "localtime"]
  43. ret = self.run_function("timezone.get_hwclock")
  44. self.assertIn(ret, timescale)
  45. @skipIf(not salt.utils.platform.is_windows(), "windows test only")
  46. class TimezoneWindowsModuleTest(ModuleCase):
  47. def setUp(self):
  48. self.pre = self.run_function("timezone.get_zone")
  49. def tearDown(self):
  50. post = self.run_function("timezone.get_zone")
  51. if self.pre != post:
  52. self.run_function("timezone.set_zone", [self.pre])
  53. def test_get_hwclock(self):
  54. timescale = ["UTC", "localtime"]
  55. ret = self.run_function("timezone.get_hwclock")
  56. self.assertIn(ret, timescale)
  57. @destructiveTest
  58. def test_get_zone(self):
  59. """
  60. test timezone.set_zone, get_zone and zone_compare
  61. """
  62. zone = "America/Inuvik" if not HAS_TZLOCAL else "America/Denver"
  63. # first set the zone
  64. assert self.run_function("timezone.set_zone", [zone])
  65. # check it set the correct zone
  66. ret = self.run_function("timezone.get_zone")
  67. assert zone in ret
  68. # compare zones
  69. assert self.run_function("timezone.zone_compare", [zone])
  70. def test_get_offset(self):
  71. """
  72. test timezone.get_offset
  73. """
  74. ret = self.run_function("timezone.get_offset")
  75. self.assertIn("-", ret)