2016-03-10 23:51:53 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
integration tests for mac_softwareupdate
|
|
|
|
'''
|
|
|
|
|
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
|
2018-01-24 20:47:14 +00:00
|
|
|
from __future__ import absolute_import, unicode_literals, print_function
|
2016-03-10 23:51:53 +00:00
|
|
|
|
|
|
|
# Import Salt Testing libs
|
2017-04-04 17:57:27 +00:00
|
|
|
from tests.support.unit import skipIf
|
2017-04-03 16:04:09 +00:00
|
|
|
from tests.support.case import ModuleCase
|
2017-04-04 17:57:27 +00:00
|
|
|
from tests.support.helpers import destructiveTest, skip_if_not_root
|
2016-03-10 23:51:53 +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-10 23:51:53 +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('softwareupdate'), '\'softwareupdate\' binary not found in $PATH')
|
2017-04-03 16:04:09 +00:00
|
|
|
class MacSoftwareUpdateModuleTest(ModuleCase):
|
2016-03-10 23:51:53 +00:00
|
|
|
'''
|
|
|
|
Validate the mac_softwareupdate module
|
|
|
|
'''
|
2016-03-23 21:03:04 +00:00
|
|
|
IGNORED_LIST = []
|
|
|
|
SCHEDULE = False
|
|
|
|
CATALOG = ''
|
2016-03-10 23:51:53 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
'''
|
|
|
|
Get current settings
|
|
|
|
'''
|
2016-03-23 21:03:04 +00:00
|
|
|
self.IGNORED_LIST = self.run_function('softwareupdate.list_ignored')
|
|
|
|
self.SCHEDULE = self.run_function('softwareupdate.schedule')
|
|
|
|
self.CATALOG = self.run_function('softwareupdate.get_catalog')
|
2016-03-10 23:51:53 +00:00
|
|
|
|
|
|
|
super(MacSoftwareUpdateModuleTest, self).setUp()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
'''
|
|
|
|
Reset to original settings
|
|
|
|
'''
|
2016-03-23 21:03:04 +00:00
|
|
|
if self.IGNORED_LIST:
|
|
|
|
for item in self.IGNORED_LIST:
|
2016-03-10 23:51:53 +00:00
|
|
|
self.run_function('softwareupdate.ignore', [item])
|
|
|
|
else:
|
|
|
|
self.run_function('softwareupdate.reset_ignored')
|
|
|
|
|
2016-03-23 21:03:04 +00:00
|
|
|
self.run_function('softwareupdate.schedule', [self.SCHEDULE])
|
2016-03-10 23:51:53 +00:00
|
|
|
|
2016-03-23 21:03:04 +00:00
|
|
|
if self.CATALOG == 'Default':
|
2016-03-10 23:51:53 +00:00
|
|
|
self.run_function('softwareupdate.reset_catalog')
|
|
|
|
else:
|
2016-03-23 21:03:04 +00:00
|
|
|
self.run_function('softwareupdate.set_catalog', [self.CATALOG])
|
2016-03-10 23:51:53 +00:00
|
|
|
|
|
|
|
super(MacSoftwareUpdateModuleTest, self).tearDown()
|
|
|
|
|
2016-03-18 19:06:19 +00:00
|
|
|
def test_list_available(self):
|
2016-03-10 23:51:53 +00:00
|
|
|
'''
|
2016-03-18 19:06:19 +00:00
|
|
|
Test softwareupdate.list_available
|
2016-03-10 23:51:53 +00:00
|
|
|
'''
|
2016-03-18 19:06:19 +00:00
|
|
|
# Can't predict what will be returned, so can only test that the return
|
|
|
|
# is the correct type, dict
|
|
|
|
self.assertIsInstance(
|
|
|
|
self.run_function('softwareupdate.list_available'), dict)
|
2016-03-10 23:51:53 +00:00
|
|
|
|
|
|
|
@destructiveTest
|
|
|
|
def test_ignore(self):
|
|
|
|
'''
|
|
|
|
Test softwareupdate.ignore
|
|
|
|
Test softwareupdate.list_ignored
|
2016-03-18 19:53:40 +00:00
|
|
|
Test softwareupdate.reset_ignored
|
2016-03-10 23:51:53 +00:00
|
|
|
'''
|
2016-03-18 19:53:40 +00:00
|
|
|
# Test reset_ignored
|
2016-03-18 17:29:49 +00:00
|
|
|
self.assertTrue(self.run_function('softwareupdate.reset_ignored'))
|
2016-03-18 19:53:40 +00:00
|
|
|
self.assertEqual(self.run_function('softwareupdate.list_ignored'), [])
|
2016-03-10 23:51:53 +00:00
|
|
|
|
2016-03-18 19:53:40 +00:00
|
|
|
# Test ignore
|
|
|
|
self.assertTrue(
|
|
|
|
self.run_function('softwareupdate.ignore', ['spongebob']))
|
|
|
|
self.assertTrue(
|
|
|
|
self.run_function('softwareupdate.ignore', ['squidward']))
|
|
|
|
|
|
|
|
# Test list_ignored and verify ignore
|
|
|
|
self.assertIn(
|
|
|
|
'spongebob',
|
|
|
|
self.run_function('softwareupdate.list_ignored'))
|
|
|
|
self.assertIn(
|
|
|
|
'squidward',
|
|
|
|
self.run_function('softwareupdate.list_ignored'))
|
2016-03-10 23:51:53 +00:00
|
|
|
|
|
|
|
@destructiveTest
|
|
|
|
def test_schedule(self):
|
|
|
|
'''
|
2016-03-18 19:53:40 +00:00
|
|
|
Test softwareupdate.schedule_enable
|
|
|
|
Test softwareupdate.schedule_enabled
|
2016-03-10 23:51:53 +00:00
|
|
|
'''
|
2016-03-18 19:53:40 +00:00
|
|
|
# Test enable
|
|
|
|
self.assertTrue(
|
|
|
|
self.run_function('softwareupdate.schedule_enable', [True]))
|
|
|
|
self.assertTrue(self.run_function('softwareupdate.schedule_enabled'))
|
|
|
|
|
|
|
|
# Test disable in case it was already enabled
|
2016-03-18 20:53:26 +00:00
|
|
|
self.assertTrue(
|
2016-03-18 19:53:40 +00:00
|
|
|
self.run_function('softwareupdate.schedule_enable', [False]))
|
|
|
|
self.assertFalse(self.run_function('softwareupdate.schedule_enabled'))
|
2016-03-10 23:51:53 +00:00
|
|
|
|
|
|
|
@destructiveTest
|
2016-03-18 20:12:31 +00:00
|
|
|
def test_update(self):
|
2016-03-10 23:51:53 +00:00
|
|
|
'''
|
2016-03-18 19:53:40 +00:00
|
|
|
Test softwareupdate.update_all
|
2016-03-18 20:12:31 +00:00
|
|
|
Test softwareupdate.update
|
|
|
|
Test softwareupdate.update_available
|
2016-03-18 20:22:15 +00:00
|
|
|
|
|
|
|
Need to know the names of updates that are available to properly test
|
|
|
|
the update functions...
|
2016-03-10 23:51:53 +00:00
|
|
|
'''
|
2016-03-18 19:53:40 +00:00
|
|
|
# There's no way to know what the dictionary will contain, so all we can
|
|
|
|
# check is that the return is a dictionary
|
|
|
|
self.assertIsInstance(
|
|
|
|
self.run_function('softwareupdate.update_all'), dict)
|
2016-03-10 23:51:53 +00:00
|
|
|
|
2016-03-18 20:22:15 +00:00
|
|
|
# Test update_available
|
|
|
|
self.assertFalse(
|
|
|
|
self.run_function('softwareupdate.update_available', ['spongebob']))
|
|
|
|
|
2016-03-18 20:12:31 +00:00
|
|
|
# Test update not available
|
|
|
|
self.assertIn(
|
|
|
|
'Update not available',
|
|
|
|
self.run_function('softwareupdate.update', ['spongebob']))
|
|
|
|
|
2016-03-10 23:51:53 +00:00
|
|
|
def test_list_downloads(self):
|
|
|
|
'''
|
|
|
|
Test softwareupdate.list_downloads
|
|
|
|
'''
|
2016-03-18 20:22:15 +00:00
|
|
|
self.assertIsInstance(
|
|
|
|
self.run_function('softwareupdate.list_downloads'), list)
|
2016-03-10 23:51:53 +00:00
|
|
|
|
|
|
|
@destructiveTest
|
|
|
|
def test_download(self):
|
|
|
|
'''
|
|
|
|
Test softwareupdate.download
|
2016-03-18 20:29:21 +00:00
|
|
|
|
|
|
|
Need to know the names of updates that are available to properly test
|
|
|
|
the download function
|
2016-03-10 23:51:53 +00:00
|
|
|
'''
|
2016-03-18 20:29:21 +00:00
|
|
|
# Test update not available
|
|
|
|
self.assertIn(
|
|
|
|
'Update not available',
|
|
|
|
self.run_function('softwareupdate.download', ['spongebob']))
|
2016-03-10 23:51:53 +00:00
|
|
|
|
|
|
|
@destructiveTest
|
|
|
|
def test_download_all(self):
|
|
|
|
'''
|
|
|
|
Test softwareupdate.download_all
|
|
|
|
'''
|
2016-03-18 20:29:21 +00:00
|
|
|
self.assertIsInstance(
|
|
|
|
self.run_function('softwareupdate.download_all'), list)
|
2016-03-10 23:51:53 +00:00
|
|
|
|
|
|
|
@destructiveTest
|
|
|
|
def test_get_set_reset_catalog(self):
|
|
|
|
'''
|
|
|
|
Test softwareupdate.download_all
|
|
|
|
'''
|
2016-03-18 20:42:03 +00:00
|
|
|
# Reset the catalog
|
2016-03-10 23:51:53 +00:00
|
|
|
self.assertTrue(self.run_function('softwareupdate.reset_catalog'))
|
|
|
|
self.assertEqual(self.run_function('softwareupdate.get_catalog'),
|
|
|
|
'Default')
|
2016-03-18 20:42:03 +00:00
|
|
|
|
|
|
|
# Test setting and getting the catalog
|
2016-03-18 20:40:03 +00:00
|
|
|
self.assertTrue(
|
|
|
|
self.run_function('softwareupdate.set_catalog', ['spongebob']))
|
|
|
|
self.assertEqual(
|
|
|
|
self.run_function('softwareupdate.get_catalog'), 'spongebob')
|
2016-03-10 23:51:53 +00:00
|
|
|
|
2016-03-18 20:42:03 +00:00
|
|
|
# Test reset the catalog
|
|
|
|
self.assertTrue(self.run_function('softwareupdate.reset_catalog'))
|
|
|
|
self.assertEqual(self.run_function('softwareupdate.get_catalog'),
|
|
|
|
'Default')
|