2016-03-09 18:55:30 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2016-03-17 19:43:29 +00:00
|
|
|
Integration tests for mac_timezone
|
2016-03-22 21:57:14 +00:00
|
|
|
|
|
|
|
If using parallels, make sure Time sync is turned off. Otherwise, parallels will
|
|
|
|
keep changing your date/time settings while the tests are running. To turn off
|
|
|
|
Time sync do the following:
|
|
|
|
- Go to actions -> configure
|
|
|
|
- Select options at the top and 'More Options' on the left
|
|
|
|
- Set time to 'Do not sync'
|
2016-03-09 18:55:30 +00:00
|
|
|
'''
|
|
|
|
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
# Import Python libs
|
2016-03-09 18:55:30 +00:00
|
|
|
from __future__ import absolute_import
|
2016-03-22 20:16:09 +00:00
|
|
|
import datetime
|
2016-03-09 18:55:30 +00:00
|
|
|
|
|
|
|
# Import Salt Testing libs
|
2017-04-03 16:04:09 +00:00
|
|
|
from tests.support.case import ModuleCase
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf
|
2017-04-04 17:57:27 +00:00
|
|
|
from tests.support.helpers import destructiveTest, skip_if_not_root
|
2016-03-09 18:55:30 +00:00
|
|
|
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
# Import Salt libs
|
|
|
|
import salt.utils.path
|
|
|
|
import salt.utils.platform
|
2016-03-09 18:55:30 +00:00
|
|
|
|
|
|
|
|
2017-04-04 17:57:27 +00:00
|
|
|
@skip_if_not_root
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
@skipIf(not salt.utils.platform.is_darwin(), 'Test only available on macOS')
|
|
|
|
@skipIf(not salt.utils.path.which('systemsetup'), '\'systemsetup\' binary not found in $PATH')
|
2017-04-03 16:04:09 +00:00
|
|
|
class MacTimezoneModuleTest(ModuleCase):
|
2016-03-09 18:55:30 +00:00
|
|
|
'''
|
|
|
|
Validate the mac_timezone module
|
|
|
|
'''
|
2016-03-23 21:22:04 +00:00
|
|
|
USE_NETWORK_TIME = False
|
|
|
|
TIME_SERVER = 'time.apple.com'
|
|
|
|
TIME_ZONE = ''
|
|
|
|
CURRENT_DATE = ''
|
|
|
|
CURRENT_TIME = ''
|
2016-03-09 18:55:30 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
'''
|
|
|
|
Get current settings
|
|
|
|
'''
|
2016-03-23 21:22:04 +00:00
|
|
|
self.USE_NETWORK_TIME = self.run_function('timezone.get_using_network_time')
|
|
|
|
self.TIME_SERVER = self.run_function('timezone.get_time_server')
|
|
|
|
self.TIME_ZONE = self.run_function('timezone.get_zone')
|
|
|
|
self.CURRENT_DATE = self.run_function('timezone.get_date')
|
|
|
|
self.CURRENT_TIME = self.run_function('timezone.get_time')
|
2016-03-17 19:43:29 +00:00
|
|
|
|
|
|
|
self.run_function('timezone.set_using_network_time', [False])
|
2016-03-22 21:57:14 +00:00
|
|
|
self.run_function('timezone.set_zone', ['America/Denver'])
|
2016-03-09 20:01:13 +00:00
|
|
|
|
2016-03-09 18:55:30 +00:00
|
|
|
def tearDown(self):
|
|
|
|
'''
|
|
|
|
Reset to original settings
|
|
|
|
'''
|
2016-03-23 21:22:04 +00:00
|
|
|
self.run_function('timezone.set_time_server', [self.TIME_SERVER])
|
|
|
|
self.run_function('timezone.set_using_network_time',
|
|
|
|
[self.USE_NETWORK_TIME])
|
|
|
|
self.run_function('timezone.set_zone', [self.TIME_ZONE])
|
|
|
|
if not self.USE_NETWORK_TIME:
|
|
|
|
self.run_function('timezone.set_date', [self.CURRENT_DATE])
|
|
|
|
self.run_function('timezone.set_time', [self.CURRENT_TIME])
|
2016-03-09 20:01:13 +00:00
|
|
|
|
2016-09-07 21:00:35 +00:00
|
|
|
@skipIf(True, 'Skip until we can figure out why modifying the system clock causes ZMQ errors')
|
2016-03-22 00:25:27 +00:00
|
|
|
@destructiveTest
|
2016-03-09 18:55:30 +00:00
|
|
|
def test_get_set_date(self):
|
|
|
|
'''
|
|
|
|
Test timezone.get_date
|
|
|
|
Test timezone.set_date
|
|
|
|
'''
|
2016-03-17 19:43:29 +00:00
|
|
|
# Correct Functionality
|
|
|
|
self.assertTrue(self.run_function('timezone.set_date', ['2/20/2011']))
|
2016-03-09 18:55:30 +00:00
|
|
|
self.assertEqual(self.run_function('timezone.get_date'), '2/20/2011')
|
|
|
|
|
2016-03-17 19:43:29 +00:00
|
|
|
# Test bad date format
|
|
|
|
self.assertEqual(
|
|
|
|
self.run_function('timezone.set_date', ['13/12/2014']),
|
|
|
|
'ERROR executing \'timezone.set_date\': '
|
|
|
|
'Invalid Date/Time Format: 13/12/2014'
|
|
|
|
)
|
|
|
|
|
2016-03-22 20:00:06 +00:00
|
|
|
def test_get_time(self):
|
2016-03-09 18:55:30 +00:00
|
|
|
'''
|
|
|
|
Test timezone.get_time
|
2016-03-22 20:00:06 +00:00
|
|
|
'''
|
|
|
|
text_time = self.run_function('timezone.get_time')
|
2016-03-22 20:05:43 +00:00
|
|
|
self.assertNotEqual(text_time, 'Invalid Timestamp')
|
2016-03-22 20:00:06 +00:00
|
|
|
obj_date = datetime.datetime.strptime(text_time, '%H:%M:%S')
|
|
|
|
self.assertIsInstance(obj_date, datetime.date)
|
|
|
|
|
2016-09-07 21:00:35 +00:00
|
|
|
@skipIf(True, 'Skip until we can figure out why modifying the system clock causes ZMQ errors')
|
2016-03-22 20:00:06 +00:00
|
|
|
@destructiveTest
|
|
|
|
def test_set_time(self):
|
|
|
|
'''
|
2016-03-09 18:55:30 +00:00
|
|
|
Test timezone.set_time
|
|
|
|
'''
|
2016-03-17 19:43:29 +00:00
|
|
|
# Correct Functionality
|
|
|
|
self.assertTrue(self.run_function('timezone.set_time', ['3:14']))
|
2016-03-09 18:55:30 +00:00
|
|
|
|
2016-03-17 19:43:29 +00:00
|
|
|
# Test bad time format
|
|
|
|
self.assertEqual(
|
2016-03-17 19:50:20 +00:00
|
|
|
self.run_function('timezone.set_time', ['3:71']),
|
2016-03-17 19:43:29 +00:00
|
|
|
'ERROR executing \'timezone.set_time\': '
|
2016-03-22 20:00:06 +00:00
|
|
|
'Invalid Date/Time Format: 3:71')
|
2016-03-17 19:43:29 +00:00
|
|
|
|
2016-09-07 21:00:35 +00:00
|
|
|
@skipIf(True, 'Skip until we can figure out why modifying the system clock causes ZMQ errors')
|
2016-03-22 20:55:58 +00:00
|
|
|
@destructiveTest
|
2016-03-22 21:57:14 +00:00
|
|
|
def test_get_set_zone(self):
|
2016-03-22 20:55:58 +00:00
|
|
|
'''
|
2016-03-22 21:57:14 +00:00
|
|
|
Test timezone.get_zone
|
2016-03-09 18:55:30 +00:00
|
|
|
Test timezone.set_zone
|
|
|
|
'''
|
2016-03-17 19:43:29 +00:00
|
|
|
# Correct Functionality
|
2016-03-22 20:55:58 +00:00
|
|
|
self.assertTrue(
|
|
|
|
self.run_function('timezone.set_zone', ['Pacific/Wake']))
|
2016-03-22 21:57:14 +00:00
|
|
|
self.assertEqual(
|
|
|
|
self.run_function('timezone.get_zone'), 'Pacific/Wake')
|
2016-03-09 18:55:30 +00:00
|
|
|
|
2016-03-17 19:43:29 +00:00
|
|
|
# Test bad time zone
|
|
|
|
self.assertEqual(
|
|
|
|
self.run_function('timezone.set_zone', ['spongebob']),
|
2016-03-17 19:46:38 +00:00
|
|
|
'ERROR executing \'timezone.set_zone\': '
|
2016-03-17 19:43:29 +00:00
|
|
|
'Invalid Timezone: spongebob')
|
|
|
|
|
2016-09-07 21:00:35 +00:00
|
|
|
@skipIf(True, 'Skip until we can figure out why modifying the system clock causes ZMQ errors')
|
|
|
|
@destructiveTest
|
2016-03-09 18:55:30 +00:00
|
|
|
def test_get_offset(self):
|
|
|
|
'''
|
|
|
|
Test timezone.get_offset
|
|
|
|
'''
|
2016-03-22 21:57:14 +00:00
|
|
|
self.assertTrue(
|
|
|
|
self.run_function('timezone.set_zone', ['Pacific/Wake']))
|
|
|
|
self.assertIsInstance(self.run_function('timezone.get_offset'), str)
|
|
|
|
self.assertEqual(self.run_function('timezone.get_offset'), '+1200')
|
|
|
|
|
|
|
|
self.assertTrue(
|
|
|
|
self.run_function('timezone.set_zone', ['America/Los_Angeles']))
|
2016-03-22 20:55:58 +00:00
|
|
|
self.assertIsInstance(self.run_function('timezone.get_offset'), str)
|
2016-03-22 21:57:14 +00:00
|
|
|
self.assertEqual(self.run_function('timezone.get_offset'), '-0700')
|
2016-03-09 18:55:30 +00:00
|
|
|
|
2016-09-07 21:00:35 +00:00
|
|
|
@skipIf(True, 'Skip until we can figure out why modifying the system clock causes ZMQ errors')
|
2016-03-22 00:25:27 +00:00
|
|
|
@destructiveTest
|
2016-03-22 21:57:14 +00:00
|
|
|
def test_get_set_zonecode(self):
|
2016-03-09 18:55:30 +00:00
|
|
|
'''
|
|
|
|
Test timezone.get_zonecode
|
2016-03-22 21:57:14 +00:00
|
|
|
Test timezone.set_zonecode
|
2016-03-09 18:55:30 +00:00
|
|
|
'''
|
2016-03-22 21:57:14 +00:00
|
|
|
self.assertTrue(
|
|
|
|
self.run_function('timezone.set_zone', ['America/Los_Angeles']))
|
|
|
|
self.assertIsInstance(self.run_function('timezone.get_zonecode'), str)
|
|
|
|
self.assertEqual(self.run_function('timezone.get_zonecode'), 'PDT')
|
|
|
|
|
|
|
|
self.assertTrue(
|
|
|
|
self.run_function('timezone.set_zone', ['Pacific/Wake']))
|
2016-03-22 20:55:58 +00:00
|
|
|
self.assertIsInstance(self.run_function('timezone.get_zonecode'), str)
|
2016-03-22 21:57:14 +00:00
|
|
|
self.assertEqual(self.run_function('timezone.get_zonecode'), 'WAKT')
|
2016-03-09 18:55:30 +00:00
|
|
|
|
|
|
|
def test_list_zones(self):
|
|
|
|
'''
|
|
|
|
Test timezone.list_zones
|
|
|
|
'''
|
2016-03-22 21:26:35 +00:00
|
|
|
zones = self.run_function('timezone.list_zones')
|
2016-03-22 21:57:14 +00:00
|
|
|
self.assertIsInstance(self.run_function('timezone.list_zones'), list)
|
|
|
|
self.assertIn(
|
|
|
|
'America/Denver',
|
|
|
|
self.run_function('timezone.list_zones'))
|
|
|
|
self.assertIn(
|
|
|
|
'America/Los_Angeles',
|
|
|
|
self.run_function('timezone.list_zones'))
|
2016-03-09 20:01:13 +00:00
|
|
|
|
2016-09-07 21:00:35 +00:00
|
|
|
@skipIf(True, 'Skip until we can figure out why modifying the system clock causes ZMQ errors')
|
2016-03-22 21:16:38 +00:00
|
|
|
@destructiveTest
|
2016-03-09 20:01:13 +00:00
|
|
|
def test_zone_compare(self):
|
|
|
|
'''
|
|
|
|
Test timezone.zone_compare
|
|
|
|
'''
|
2016-03-22 20:55:58 +00:00
|
|
|
self.assertTrue(
|
2016-03-22 21:16:38 +00:00
|
|
|
self.run_function('timezone.set_zone', ['America/Denver']))
|
2016-03-22 20:55:58 +00:00
|
|
|
self.assertTrue(
|
|
|
|
self.run_function('timezone.zone_compare', ['America/Denver']))
|
2016-03-22 21:16:38 +00:00
|
|
|
self.assertFalse(
|
|
|
|
self.run_function('timezone.zone_compare', ['Pacific/Wake']))
|
2016-03-09 20:01:13 +00:00
|
|
|
|
2016-09-07 21:00:35 +00:00
|
|
|
@skipIf(True, 'Skip until we can figure out why modifying the system clock causes ZMQ errors')
|
2016-03-22 00:25:27 +00:00
|
|
|
@destructiveTest
|
2016-03-09 20:01:13 +00:00
|
|
|
def test_get_set_using_network_time(self):
|
|
|
|
'''
|
|
|
|
Test timezone.get_using_network_time
|
|
|
|
Test timezone.set_using_network_time
|
|
|
|
'''
|
2016-03-22 20:55:58 +00:00
|
|
|
self.assertTrue(
|
|
|
|
self.run_function('timezone.set_using_network_time', [True]))
|
2016-03-09 20:01:13 +00:00
|
|
|
self.assertTrue(self.run_function('timezone.get_using_network_time'))
|
|
|
|
|
2016-03-22 20:55:58 +00:00
|
|
|
self.assertTrue(
|
|
|
|
self.run_function('timezone.set_using_network_time', [False]))
|
2016-03-09 20:01:13 +00:00
|
|
|
self.assertFalse(self.run_function('timezone.get_using_network_time'))
|
|
|
|
|
2016-09-07 21:00:35 +00:00
|
|
|
@skipIf(True, 'Skip until we can figure out why modifying the system clock causes ZMQ errors')
|
2016-03-22 00:25:27 +00:00
|
|
|
@destructiveTest
|
2016-03-09 20:01:13 +00:00
|
|
|
def test_get_set_time_server(self):
|
|
|
|
'''
|
|
|
|
Test timezone.get_time_server
|
|
|
|
Test timezone.set_time_server
|
|
|
|
'''
|
2016-03-22 20:55:58 +00:00
|
|
|
self.assertTrue(
|
|
|
|
self.run_function('timezone.set_time_server', ['spongebob.com']))
|
|
|
|
self.assertEqual(
|
|
|
|
self.run_function('timezone.get_time_server'), 'spongebob.com')
|