2011-12-22 01:36:26 +00:00
|
|
|
#!/usr/bin/env python
|
2012-09-29 11:10:06 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2011-12-22 01:36:26 +00:00
|
|
|
'''
|
|
|
|
Discover all instances of unittest.TestCase in this directory.
|
|
|
|
'''
|
2015-01-07 01:15:56 +00:00
|
|
|
# pylint: disable=file-perms
|
|
|
|
|
2012-02-12 08:24:20 +00:00
|
|
|
# Import python libs
|
2014-11-21 19:05:13 +00:00
|
|
|
from __future__ import absolute_import, print_function
|
2012-02-12 08:24:20 +00:00
|
|
|
import os
|
2017-02-09 18:03:20 +00:00
|
|
|
import sys
|
2015-03-13 22:15:23 +00:00
|
|
|
import time
|
2012-08-11 00:28:49 +00:00
|
|
|
|
2017-02-26 14:20:41 +00:00
|
|
|
TESTS_DIR = os.path.dirname(os.path.normpath(os.path.abspath(__file__)))
|
|
|
|
if os.name == 'nt':
|
|
|
|
TESTS_DIR = TESTS_DIR.replace('\\', '\\\\')
|
|
|
|
CODE_DIR = os.path.dirname(TESTS_DIR)
|
2017-02-27 13:58:07 +00:00
|
|
|
|
|
|
|
# Let's inject CODE_DIR so salt is importable if not there already
|
|
|
|
if '' in sys.path:
|
|
|
|
sys.path.remove('')
|
|
|
|
if TESTS_DIR in sys.path:
|
|
|
|
sys.path.remove(TESTS_DIR)
|
|
|
|
if CODE_DIR in sys.path and sys.path[0] != CODE_DIR:
|
|
|
|
sys.path.remove(CODE_DIR)
|
|
|
|
if CODE_DIR not in sys.path:
|
|
|
|
sys.path.insert(0, CODE_DIR)
|
|
|
|
if TESTS_DIR not in sys.path:
|
|
|
|
sys.path.insert(1, TESTS_DIR)
|
2017-02-26 14:20:41 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
import tests
|
|
|
|
if not tests.__file__.startswith(CODE_DIR):
|
|
|
|
print('Found tests module not from salt in {}'.format(tests.__file__))
|
|
|
|
sys.modules.pop('tests')
|
|
|
|
module_dir = os.path.dirname(tests.__file__)
|
|
|
|
if module_dir in sys.path:
|
|
|
|
sys.path.remove(module_dir)
|
|
|
|
del tests
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
2012-08-11 00:28:49 +00:00
|
|
|
# Import salt libs
|
2017-02-26 14:20:41 +00:00
|
|
|
try:
|
|
|
|
from tests.support.paths import TMP, SYS_TMP_DIR, INTEGRATION_TEST_DIR
|
|
|
|
from tests.support.paths import CODE_DIR as SALT_ROOT
|
|
|
|
except ImportError as exc:
|
|
|
|
try:
|
|
|
|
import tests
|
|
|
|
print('Found tests module not from salt in {}'.format(tests.__file__))
|
|
|
|
except ImportError:
|
|
|
|
print('Unable to import salt test module')
|
2017-02-27 13:58:07 +00:00
|
|
|
print('PYTHONPATH:', os.environ.get('PYTHONPATH'))
|
|
|
|
print('Current sys.path:')
|
2017-02-26 14:20:41 +00:00
|
|
|
import pprint
|
|
|
|
pprint.pprint(sys.path)
|
|
|
|
raise exc
|
|
|
|
|
|
|
|
from tests.integration import TestDaemon # pylint: disable=W0403
|
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.utils.platform
|
2015-11-02 23:15:02 +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
|
|
|
if not salt.utils.platform.is_windows():
|
2015-11-02 23:15:02 +00:00
|
|
|
import resource
|
2013-06-24 22:53:59 +00:00
|
|
|
|
|
|
|
# Import Salt Testing libs
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.parser import PNUM, print_header
|
|
|
|
from tests.support.parser.cover import SaltCoverageTestingParser
|
2017-02-26 14:20:41 +00:00
|
|
|
|
2013-02-02 18:07:07 +00:00
|
|
|
XML_OUTPUT_DIR = os.environ.get(
|
2013-02-02 18:27:59 +00:00
|
|
|
'SALT_XML_TEST_REPORTS_DIR',
|
2013-02-02 18:07:07 +00:00
|
|
|
os.path.join(TMP, 'xml-test-reports')
|
|
|
|
)
|
2013-06-24 18:37:07 +00:00
|
|
|
HTML_OUTPUT_DIR = os.environ.get(
|
|
|
|
'SALT_HTML_TEST_REPORTS_DIR',
|
|
|
|
os.path.join(TMP, 'html-test-reports')
|
|
|
|
)
|
2012-10-02 12:04:22 +00:00
|
|
|
|
2015-07-28 11:07:04 +00:00
|
|
|
TEST_DIR = os.path.dirname(INTEGRATION_TEST_DIR)
|
2013-06-02 08:07:39 +00:00
|
|
|
try:
|
|
|
|
if SALT_ROOT:
|
|
|
|
os.chdir(SALT_ROOT)
|
2013-06-03 17:45:44 +00:00
|
|
|
except OSError as err:
|
2014-02-03 11:07:11 +00:00
|
|
|
print('Failed to change directory to salt\'s source: {0}'.format(err))
|
2013-06-02 08:07:39 +00:00
|
|
|
|
2016-03-03 23:53:29 +00:00
|
|
|
# Soft and hard limits on max open filehandles
|
|
|
|
MAX_OPEN_FILES = {
|
|
|
|
'integration': {
|
|
|
|
'soft_limit': 3072,
|
|
|
|
'hard_limit': 4096,
|
|
|
|
},
|
|
|
|
'unit': {
|
|
|
|
'soft_limit': 1024,
|
|
|
|
'hard_limit': 2048,
|
|
|
|
},
|
|
|
|
}
|
2012-04-04 16:58:11 +00:00
|
|
|
|
2016-02-24 08:02:04 +00:00
|
|
|
# Combine info from command line options and test suite directories. A test
|
|
|
|
# suite is a python package of test modules relative to the tests directory.
|
|
|
|
TEST_SUITES = {
|
|
|
|
'unit':
|
|
|
|
{'display_name': 'Unit',
|
|
|
|
'path': 'unit'},
|
2017-10-11 16:20:14 +00:00
|
|
|
'kitchen':
|
|
|
|
{'display_name': 'Kitchen',
|
|
|
|
'path': 'kitchen'},
|
2016-02-24 08:02:04 +00:00
|
|
|
'module':
|
|
|
|
{'display_name': 'Module',
|
|
|
|
'path': 'integration/modules'},
|
|
|
|
'state':
|
|
|
|
{'display_name': 'State',
|
|
|
|
'path': 'integration/states'},
|
|
|
|
'cli':
|
|
|
|
{'display_name': 'CLI',
|
|
|
|
'path': 'integration/cli'},
|
|
|
|
'client':
|
|
|
|
{'display_name': 'Client',
|
|
|
|
'path': 'integration/client'},
|
2017-04-19 20:13:52 +00:00
|
|
|
'ext_pillar':
|
|
|
|
{'display_name': 'External Pillar',
|
|
|
|
'path': 'integration/pillar'},
|
2017-03-22 19:11:22 +00:00
|
|
|
'grains':
|
|
|
|
{'display_name': 'Grains',
|
|
|
|
'path': 'integration/grains'},
|
2016-02-24 08:02:04 +00:00
|
|
|
'shell':
|
|
|
|
{'display_name': 'Shell',
|
|
|
|
'path': 'integration/shell'},
|
|
|
|
'runners':
|
|
|
|
{'display_name': 'Runners',
|
|
|
|
'path': 'integration/runners'},
|
|
|
|
'renderers':
|
|
|
|
{'display_name': 'Renderers',
|
|
|
|
'path': 'integration/renderers'},
|
2016-08-17 18:13:26 +00:00
|
|
|
'returners':
|
|
|
|
{'display_name': 'Returners',
|
|
|
|
'path': 'integration/returners'},
|
2017-11-10 15:58:38 +00:00
|
|
|
'ssh-int':
|
|
|
|
{'display_name': 'SSH Integration',
|
2017-11-09 20:17:25 +00:00
|
|
|
'path': 'integration/ssh'},
|
2017-10-24 14:33:53 +00:00
|
|
|
'spm':
|
|
|
|
{'display_name': 'SPM',
|
|
|
|
'path': 'integration/spm'},
|
2016-02-24 08:02:04 +00:00
|
|
|
'loader':
|
|
|
|
{'display_name': 'Loader',
|
|
|
|
'path': 'integration/loader'},
|
|
|
|
'outputter':
|
|
|
|
{'display_name': 'Outputter',
|
|
|
|
'path': 'integration/output'},
|
|
|
|
'fileserver':
|
|
|
|
{'display_name': 'Fileserver',
|
|
|
|
'path': 'integration/fileserver'},
|
|
|
|
'wheel':
|
|
|
|
{'display_name': 'Wheel',
|
|
|
|
'path': 'integration/wheel'},
|
|
|
|
'api':
|
|
|
|
{'display_name': 'NetAPI',
|
|
|
|
'path': 'integration/netapi'},
|
|
|
|
'cloud_provider':
|
|
|
|
{'display_name': 'Cloud Provider',
|
|
|
|
'path': 'integration/cloud/providers'},
|
2016-02-26 18:38:21 +00:00
|
|
|
'minion':
|
|
|
|
{'display_name': 'Minion',
|
2016-05-19 19:41:23 +00:00
|
|
|
'path': 'integration/minion'},
|
|
|
|
'reactor':
|
|
|
|
{'display_name': 'Reactor',
|
|
|
|
'path': 'integration/reactor'},
|
2017-05-05 21:32:16 +00:00
|
|
|
'proxy':
|
|
|
|
{'display_name': 'Proxy',
|
|
|
|
'path': 'integration/proxy'},
|
2017-05-24 17:59:35 +00:00
|
|
|
'external_api':
|
|
|
|
{'display_name': 'ExternalAPIs',
|
|
|
|
'path': 'integration/externalapi'},
|
2017-10-18 18:58:36 +00:00
|
|
|
'daemons':
|
2017-10-18 19:28:30 +00:00
|
|
|
{'display_name': 'Daemon',
|
2017-10-18 18:58:36 +00:00
|
|
|
'path': 'integration/daemons'},
|
2017-12-06 21:09:35 +00:00
|
|
|
'scheduler':
|
|
|
|
{'display_name': 'Scheduler',
|
|
|
|
'path': 'integration/scheduler'},
|
2016-02-24 08:02:04 +00:00
|
|
|
}
|
|
|
|
|
2012-02-12 08:24:20 +00:00
|
|
|
|
2013-06-25 12:18:11 +00:00
|
|
|
class SaltTestsuiteParser(SaltCoverageTestingParser):
|
2013-11-08 20:20:03 +00:00
|
|
|
support_docker_execution = True
|
2013-08-06 21:03:42 +00:00
|
|
|
support_destructive_tests_selection = True
|
2013-11-08 20:20:03 +00:00
|
|
|
source_code_basedir = SALT_ROOT
|
2013-01-30 20:10:45 +00:00
|
|
|
|
2017-05-05 21:32:16 +00:00
|
|
|
def _get_suites(self, include_unit=False, include_cloud_provider=False,
|
2017-10-11 16:20:14 +00:00
|
|
|
include_proxy=False, include_kitchen=False):
|
2016-02-24 08:02:04 +00:00
|
|
|
'''
|
|
|
|
Return a set of all test suites except unit and cloud provider tests
|
|
|
|
unless requested
|
|
|
|
'''
|
|
|
|
suites = set(TEST_SUITES.keys())
|
|
|
|
if not include_unit:
|
|
|
|
suites -= set(['unit'])
|
|
|
|
if not include_cloud_provider:
|
|
|
|
suites -= set(['cloud_provider'])
|
2017-05-05 21:32:16 +00:00
|
|
|
if not include_proxy:
|
|
|
|
suites -= set(['proxy'])
|
2017-10-11 16:20:14 +00:00
|
|
|
if not include_kitchen:
|
|
|
|
suites -= set(['kitchen'])
|
2016-02-24 08:02:04 +00:00
|
|
|
|
|
|
|
return suites
|
|
|
|
|
2017-05-05 21:32:16 +00:00
|
|
|
def _check_enabled_suites(self, include_unit=False,
|
2017-10-11 16:20:14 +00:00
|
|
|
include_cloud_provider=False,
|
|
|
|
include_proxy=False,
|
|
|
|
include_kitchen=False):
|
2016-02-24 08:02:04 +00:00
|
|
|
'''
|
|
|
|
Query whether test suites have been enabled
|
|
|
|
'''
|
|
|
|
suites = self._get_suites(include_unit=include_unit,
|
2017-05-05 21:32:16 +00:00
|
|
|
include_cloud_provider=include_cloud_provider,
|
2017-10-11 16:20:14 +00:00
|
|
|
include_proxy=include_proxy,
|
|
|
|
include_kitchen=include_kitchen)
|
2016-02-24 08:02:04 +00:00
|
|
|
|
|
|
|
return any([getattr(self.options, suite) for suite in suites])
|
|
|
|
|
2017-05-05 21:32:16 +00:00
|
|
|
def _enable_suites(self, include_unit=False, include_cloud_provider=False,
|
2017-10-11 16:20:14 +00:00
|
|
|
include_proxy=False, include_kitchen=False):
|
2016-02-24 08:02:04 +00:00
|
|
|
'''
|
|
|
|
Enable test suites for current test run
|
|
|
|
'''
|
|
|
|
suites = self._get_suites(include_unit=include_unit,
|
2017-05-05 21:32:16 +00:00
|
|
|
include_cloud_provider=include_cloud_provider,
|
2017-10-11 16:20:14 +00:00
|
|
|
include_proxy=include_proxy,
|
|
|
|
include_kitchen=include_kitchen)
|
2016-02-24 08:02:04 +00:00
|
|
|
|
|
|
|
for suite in suites:
|
|
|
|
setattr(self.options, suite, True)
|
|
|
|
|
2013-06-24 18:37:07 +00:00
|
|
|
def setup_additional_options(self):
|
|
|
|
self.add_option(
|
|
|
|
'--sysinfo',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Print some system information.'
|
2013-01-30 20:42:30 +00:00
|
|
|
)
|
2014-06-11 21:34:53 +00:00
|
|
|
self.add_option(
|
|
|
|
'--transport',
|
|
|
|
default='zeromq',
|
2015-07-20 22:56:00 +00:00
|
|
|
choices=('zeromq', 'raet', 'tcp'),
|
|
|
|
help=('Select which transport to run the integration tests with, '
|
|
|
|
'zeromq, raet, or tcp. Default: %default')
|
|
|
|
)
|
2015-03-13 19:18:54 +00:00
|
|
|
self.add_option(
|
2015-03-13 22:15:23 +00:00
|
|
|
'--interactive',
|
2015-03-13 19:18:54 +00:00
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Do not run any tests. Simply start the daemons.'
|
|
|
|
)
|
2016-02-24 08:08:48 +00:00
|
|
|
self.output_options_group.add_option(
|
|
|
|
'--no-colors',
|
|
|
|
'--no-colours',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Disable colour printing.'
|
|
|
|
)
|
2012-08-25 13:21:19 +00:00
|
|
|
|
2013-06-24 18:37:07 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'-m',
|
|
|
|
'--module',
|
|
|
|
'--module-tests',
|
|
|
|
dest='module',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run tests for modules'
|
|
|
|
)
|
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'-S',
|
|
|
|
'--state',
|
|
|
|
'--state-tests',
|
|
|
|
dest='state',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run tests for states'
|
|
|
|
)
|
2014-07-09 21:16:13 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'-C',
|
|
|
|
'--cli',
|
|
|
|
'--cli-tests',
|
2014-07-09 23:41:26 +00:00
|
|
|
dest='cli',
|
2014-07-09 21:16:13 +00:00
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run tests for cli'
|
|
|
|
)
|
2013-06-24 18:37:07 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'-c',
|
|
|
|
'--client',
|
|
|
|
'--client-tests',
|
|
|
|
dest='client',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run tests for client'
|
|
|
|
)
|
2017-04-19 20:13:52 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'-I',
|
|
|
|
'--ext-pillar',
|
|
|
|
'--ext-pillar-tests',
|
|
|
|
dest='ext_pillar',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run ext_pillar tests'
|
|
|
|
)
|
2016-02-23 03:55:32 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'-G',
|
|
|
|
'--grains',
|
|
|
|
'--grains-tests',
|
|
|
|
dest='grains',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run tests for grains'
|
|
|
|
)
|
2013-06-24 18:37:07 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'-s',
|
|
|
|
'--shell',
|
2016-04-25 20:57:33 +00:00
|
|
|
'--shell-tests',
|
2013-06-24 18:37:07 +00:00
|
|
|
dest='shell',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run shell tests'
|
|
|
|
)
|
2014-08-28 16:53:22 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'-r',
|
|
|
|
'--runners',
|
2016-04-25 20:57:33 +00:00
|
|
|
'--runner-tests',
|
2014-08-28 16:53:22 +00:00
|
|
|
dest='runners',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run salt/runners/*.py tests'
|
2013-06-24 18:37:07 +00:00
|
|
|
)
|
2015-11-25 17:14:46 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'-R',
|
|
|
|
'--renderers',
|
2016-04-25 20:57:33 +00:00
|
|
|
'--renderer-tests',
|
2015-11-25 17:14:46 +00:00
|
|
|
dest='renderers',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run salt/renderers/*.py tests'
|
|
|
|
)
|
2016-05-19 19:41:23 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'--reactor',
|
|
|
|
dest='reactor',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run salt/reactor/*.py tests'
|
|
|
|
)
|
2016-02-23 20:44:00 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'--minion',
|
|
|
|
'--minion-tests',
|
|
|
|
dest='minion',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run tests for minion'
|
|
|
|
)
|
2016-08-08 23:01:02 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'--returners',
|
|
|
|
dest='returners',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run salt/returners/*.py tests'
|
|
|
|
)
|
2017-10-24 14:33:53 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'--spm',
|
|
|
|
dest='spm',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run spm integration tests'
|
|
|
|
)
|
2013-10-26 17:57:00 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'-l',
|
|
|
|
'--loader',
|
2016-04-25 20:57:33 +00:00
|
|
|
'--loader-tests',
|
|
|
|
dest='loader',
|
2013-10-26 17:57:00 +00:00
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run loader tests'
|
|
|
|
)
|
2013-06-24 18:37:07 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'-u',
|
|
|
|
'--unit',
|
|
|
|
'--unit-tests',
|
|
|
|
dest='unit',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run unit tests'
|
|
|
|
)
|
2017-10-11 16:20:14 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'-k',
|
|
|
|
'--kitchen',
|
|
|
|
'--kitchen-tests',
|
|
|
|
dest='kitchen',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run kitchen tests'
|
|
|
|
)
|
2014-06-03 23:15:46 +00:00
|
|
|
self.test_selection_group.add_option(
|
2016-04-25 20:57:33 +00:00
|
|
|
'--fileserver',
|
2014-06-03 23:15:46 +00:00
|
|
|
'--fileserver-tests',
|
|
|
|
dest='fileserver',
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help='Run Fileserver tests'
|
|
|
|
)
|
2014-08-27 15:34:44 +00:00
|
|
|
self.test_selection_group.add_option(
|
2014-08-28 16:53:22 +00:00
|
|
|
'-w',
|
2014-08-27 15:34:44 +00:00
|
|
|
'--wheel',
|
2016-04-25 20:57:33 +00:00
|
|
|
'--wheel-tests',
|
|
|
|
dest='wheel',
|
2014-08-27 15:34:44 +00:00
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='Run wheel tests'
|
|
|
|
)
|
2014-05-12 18:10:11 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'-o',
|
|
|
|
'--outputter',
|
2016-04-25 20:57:33 +00:00
|
|
|
'--outputter-tests',
|
|
|
|
dest='outputter',
|
2014-05-12 18:10:11 +00:00
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='Run outputter tests'
|
|
|
|
)
|
2014-06-10 02:17:41 +00:00
|
|
|
self.test_selection_group.add_option(
|
2016-02-24 08:09:10 +00:00
|
|
|
'--cloud-provider',
|
2014-06-10 02:17:41 +00:00
|
|
|
'--cloud-provider-tests',
|
2016-02-24 08:09:10 +00:00
|
|
|
dest='cloud_provider',
|
2014-06-10 02:17:41 +00:00
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help=('Run cloud provider tests. These tests create and delete '
|
|
|
|
'instances on cloud providers. Must provide valid credentials '
|
|
|
|
'in salt/tests/integration/files/conf/cloud.*.d to run tests.')
|
|
|
|
)
|
2014-05-10 13:12:04 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'--ssh',
|
2016-04-25 20:57:33 +00:00
|
|
|
'--ssh-tests',
|
|
|
|
dest='ssh',
|
2014-05-10 13:12:04 +00:00
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='Run salt-ssh tests. These tests will spin up a temporary '
|
|
|
|
'SSH server on your machine. In certain environments, this '
|
2014-05-12 22:38:16 +00:00
|
|
|
'may be insecure! Default: False'
|
2014-05-10 13:12:04 +00:00
|
|
|
)
|
2017-11-10 15:58:38 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'--ssh-int',
|
|
|
|
dest='ssh-int',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='Run salt-ssh integration tests. Requires to be run with --ssh'
|
|
|
|
'to spin up the SSH server on your machine.'
|
|
|
|
)
|
2014-06-19 11:58:52 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'-A',
|
2016-04-25 20:57:33 +00:00
|
|
|
'--api',
|
2014-06-19 11:58:52 +00:00
|
|
|
'--api-tests',
|
|
|
|
dest='api',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='Run salt-api tests'
|
|
|
|
)
|
2017-05-05 21:32:16 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'-P',
|
|
|
|
'--proxy',
|
|
|
|
'--proxy-tests',
|
|
|
|
dest='proxy',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='Run salt-proxy tests'
|
|
|
|
)
|
2017-05-24 17:59:35 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'--external',
|
|
|
|
'--external-api',
|
|
|
|
'--external-api-tests',
|
|
|
|
dest='external_api',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='Run venafi runner tests'
|
|
|
|
)
|
2017-10-18 18:58:36 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'--daemons',
|
|
|
|
'--daemon-tests',
|
|
|
|
dest='daemons',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
2017-10-18 22:02:17 +00:00
|
|
|
help='Run salt/daemons/*.py tests'
|
2017-10-18 18:58:36 +00:00
|
|
|
)
|
2017-12-06 21:09:35 +00:00
|
|
|
self.test_selection_group.add_option(
|
|
|
|
'--scheduler',
|
|
|
|
dest='scheduler',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='Run scheduler integration tests'
|
|
|
|
)
|
2017-05-05 21:32:16 +00:00
|
|
|
|
2013-06-24 18:37:07 +00:00
|
|
|
def validate_options(self):
|
2017-05-24 17:59:35 +00:00
|
|
|
if self.options.cloud_provider or self.options.external_api:
|
2014-06-10 18:25:04 +00:00
|
|
|
# Turn on expensive tests execution
|
|
|
|
os.environ['EXPENSIVE_TESTS'] = 'True'
|
|
|
|
|
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
|
|
|
# This fails even with salt.utils.platform imported in the global
|
|
|
|
# scope, unless we import it again here.
|
|
|
|
import salt.utils.platform
|
|
|
|
if salt.utils.platform.is_windows():
|
2017-01-30 22:25:31 +00:00
|
|
|
import salt.utils.win_functions
|
|
|
|
current_user = salt.utils.win_functions.get_current_user()
|
|
|
|
if current_user == 'SYSTEM':
|
|
|
|
is_admin = True
|
|
|
|
else:
|
|
|
|
is_admin = salt.utils.win_functions.is_admin(current_user)
|
|
|
|
else:
|
|
|
|
is_admin = os.geteuid() == 0
|
|
|
|
|
2013-06-25 12:24:32 +00:00
|
|
|
if self.options.coverage and any((
|
2016-02-25 04:56:20 +00:00
|
|
|
self.options.name,
|
2017-06-20 21:32:55 +00:00
|
|
|
not is_admin,
|
2016-02-25 04:56:20 +00:00
|
|
|
not self.options.run_destructive)) \
|
|
|
|
and self._check_enabled_suites(include_unit=True):
|
2013-06-24 18:37:07 +00:00
|
|
|
self.error(
|
2013-06-25 12:18:11 +00:00
|
|
|
'No sense in generating the tests coverage report when '
|
|
|
|
'not running the full test suite, including the '
|
|
|
|
'destructive tests, as \'root\'. It would only produce '
|
|
|
|
'incorrect results.'
|
2012-10-02 12:04:22 +00:00
|
|
|
)
|
2013-06-24 18:37:07 +00:00
|
|
|
|
2016-02-25 04:56:20 +00:00
|
|
|
# When no tests are specifically enumerated on the command line, setup
|
|
|
|
# a default run: +unit -cloud_provider
|
|
|
|
if not self.options.name and not \
|
2017-05-05 21:32:16 +00:00
|
|
|
self._check_enabled_suites(include_unit=True,
|
|
|
|
include_cloud_provider=True,
|
2017-10-11 16:20:14 +00:00
|
|
|
include_proxy=True,
|
|
|
|
include_kitchen=True):
|
2016-02-25 04:56:20 +00:00
|
|
|
self._enable_suites(include_unit=True)
|
2013-06-24 18:37:07 +00:00
|
|
|
|
2013-06-25 12:18:11 +00:00
|
|
|
self.start_coverage(
|
|
|
|
branch=True,
|
2013-06-26 20:16:39 +00:00
|
|
|
source=[os.path.join(SALT_ROOT, 'salt')],
|
2013-06-25 12:18:11 +00:00
|
|
|
)
|
2013-06-24 18:37:07 +00:00
|
|
|
|
2017-02-09 18:03:20 +00:00
|
|
|
# Print out which version of python this test suite is running on
|
|
|
|
print(' * Python Version: {0}'.format(' '.join(sys.version.split())))
|
|
|
|
|
2014-06-12 23:59:55 +00:00
|
|
|
# Transplant configuration
|
|
|
|
TestDaemon.transplant_configs(transport=self.options.transport)
|
|
|
|
|
2014-06-14 13:03:38 +00:00
|
|
|
def post_execution_cleanup(self):
|
2014-06-14 13:08:53 +00:00
|
|
|
SaltCoverageTestingParser.post_execution_cleanup(self)
|
2014-06-14 13:03:38 +00:00
|
|
|
if self.options.clean:
|
|
|
|
TestDaemon.clean()
|
|
|
|
|
2016-02-25 04:56:20 +00:00
|
|
|
def run_integration_suite(self, path='', display_name=''):
|
2013-06-24 18:37:07 +00:00
|
|
|
'''
|
|
|
|
Run an integration test suite
|
|
|
|
'''
|
2016-02-25 04:56:20 +00:00
|
|
|
full_path = os.path.join(TEST_DIR, path)
|
2017-02-17 02:35:42 +00:00
|
|
|
return self.run_suite(full_path, display_name, suffix='test_*.py')
|
2013-06-24 18:37:07 +00:00
|
|
|
|
2015-03-13 22:15:23 +00:00
|
|
|
def start_daemons_only(self):
|
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
|
|
|
if not salt.utils.platform.is_windows():
|
2016-03-03 23:53:29 +00:00
|
|
|
self.set_filehandle_limits('integration')
|
2015-03-13 22:15:23 +00:00
|
|
|
try:
|
|
|
|
print_header(
|
|
|
|
' * Setting up Salt daemons for interactive use',
|
|
|
|
top=False, width=getattr(self.options, 'output_columns', PNUM)
|
|
|
|
)
|
|
|
|
except TypeError:
|
|
|
|
print_header(' * Setting up Salt daemons for interactive use', top=False)
|
|
|
|
|
|
|
|
with TestDaemon(self):
|
|
|
|
print_header(' * Salt daemons started')
|
|
|
|
master_conf = TestDaemon.config('master')
|
|
|
|
minion_conf = TestDaemon.config('minion')
|
2017-05-05 21:32:16 +00:00
|
|
|
proxy_conf = TestDaemon.config('proxy')
|
2016-07-07 18:27:48 +00:00
|
|
|
sub_minion_conf = TestDaemon.config('sub_minion')
|
2015-03-13 22:15:23 +00:00
|
|
|
syndic_conf = TestDaemon.config('syndic')
|
|
|
|
syndic_master_conf = TestDaemon.config('syndic_master')
|
|
|
|
|
2016-07-08 22:21:27 +00:00
|
|
|
print_header(' * Syndic master configuration values (MoM)', top=False)
|
|
|
|
print('interface: {0}'.format(syndic_master_conf['interface']))
|
|
|
|
print('publish port: {0}'.format(syndic_master_conf['publish_port']))
|
|
|
|
print('return port: {0}'.format(syndic_master_conf['ret_port']))
|
|
|
|
print('\n')
|
|
|
|
|
|
|
|
print_header(' * Syndic configuration values', top=True)
|
|
|
|
print('interface: {0}'.format(syndic_conf['interface']))
|
|
|
|
print('syndic master: {0}'.format(syndic_conf['syndic_master']))
|
|
|
|
print('syndic master port: {0}'.format(syndic_conf['syndic_master_port']))
|
|
|
|
print('\n')
|
|
|
|
|
2015-03-13 22:15:23 +00:00
|
|
|
print_header(' * Master configuration values', top=True)
|
|
|
|
print('interface: {0}'.format(master_conf['interface']))
|
|
|
|
print('publish port: {0}'.format(master_conf['publish_port']))
|
|
|
|
print('return port: {0}'.format(master_conf['ret_port']))
|
|
|
|
print('\n')
|
|
|
|
|
|
|
|
print_header(' * Minion configuration values', top=True)
|
|
|
|
print('interface: {0}'.format(minion_conf['interface']))
|
2016-07-07 23:27:47 +00:00
|
|
|
print('master: {0}'.format(minion_conf['master']))
|
2016-07-07 18:27:48 +00:00
|
|
|
print('master port: {0}'.format(minion_conf['master_port']))
|
2016-07-11 22:15:28 +00:00
|
|
|
if minion_conf['ipc_mode'] == 'tcp':
|
|
|
|
print('tcp pub port: {0}'.format(minion_conf['tcp_pub_port']))
|
|
|
|
print('tcp pull port: {0}'.format(minion_conf['tcp_pull_port']))
|
2016-07-07 18:27:48 +00:00
|
|
|
print('\n')
|
|
|
|
|
|
|
|
print_header(' * Sub Minion configuration values', top=True)
|
|
|
|
print('interface: {0}'.format(sub_minion_conf['interface']))
|
2016-07-07 23:27:47 +00:00
|
|
|
print('master: {0}'.format(sub_minion_conf['master']))
|
2016-07-07 18:27:48 +00:00
|
|
|
print('master port: {0}'.format(sub_minion_conf['master_port']))
|
2016-07-11 22:15:28 +00:00
|
|
|
if sub_minion_conf['ipc_mode'] == 'tcp':
|
|
|
|
print('tcp pub port: {0}'.format(sub_minion_conf['tcp_pub_port']))
|
|
|
|
print('tcp pull port: {0}'.format(sub_minion_conf['tcp_pull_port']))
|
2016-07-07 18:27:48 +00:00
|
|
|
print('\n')
|
|
|
|
|
2017-05-05 21:32:16 +00:00
|
|
|
print_header(' * Proxy Minion configuration values', top=True)
|
|
|
|
print('interface: {0}'.format(proxy_conf['interface']))
|
|
|
|
print('master: {0}'.format(proxy_conf['master']))
|
|
|
|
print('master port: {0}'.format(proxy_conf['master_port']))
|
|
|
|
if minion_conf['ipc_mode'] == 'tcp':
|
|
|
|
print('tcp pub port: {0}'.format(proxy_conf['tcp_pub_port']))
|
|
|
|
print('tcp pull port: {0}'.format(proxy_conf['tcp_pull_port']))
|
|
|
|
print('\n')
|
|
|
|
|
2015-03-13 22:15:23 +00:00
|
|
|
print_header(' Your client configuration is at {0}'.format(TestDaemon.config_location()))
|
2016-07-08 16:52:04 +00:00
|
|
|
print('To access the minion: salt -c {0} minion test.ping'.format(TestDaemon.config_location()))
|
2015-03-13 22:15:23 +00:00
|
|
|
|
|
|
|
while True:
|
|
|
|
time.sleep(1)
|
|
|
|
|
2016-03-03 23:53:29 +00:00
|
|
|
def set_filehandle_limits(self, limits='integration'):
|
|
|
|
'''
|
|
|
|
Set soft and hard limits on open file handles at required thresholds
|
|
|
|
for integration tests or unit tests
|
|
|
|
'''
|
|
|
|
# Get current limits
|
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
|
|
|
if salt.utils.platform.is_windows():
|
2017-02-17 20:52:27 +00:00
|
|
|
import win32file
|
|
|
|
prev_hard = win32file._getmaxstdio()
|
|
|
|
prev_soft = 512
|
|
|
|
else:
|
|
|
|
prev_soft, prev_hard = resource.getrlimit(resource.RLIMIT_NOFILE)
|
2016-03-03 23:53:29 +00:00
|
|
|
|
|
|
|
# Get required limits
|
|
|
|
min_soft = MAX_OPEN_FILES[limits]['soft_limit']
|
|
|
|
min_hard = MAX_OPEN_FILES[limits]['hard_limit']
|
|
|
|
|
|
|
|
# Check minimum required limits
|
|
|
|
set_limits = False
|
|
|
|
if prev_soft < min_soft:
|
|
|
|
soft = min_soft
|
|
|
|
set_limits = True
|
|
|
|
else:
|
|
|
|
soft = prev_soft
|
|
|
|
|
|
|
|
if prev_hard < min_hard:
|
|
|
|
hard = min_hard
|
|
|
|
set_limits = True
|
|
|
|
else:
|
|
|
|
hard = prev_hard
|
|
|
|
|
|
|
|
# Increase limits
|
|
|
|
if set_limits:
|
2015-03-13 22:15:23 +00:00
|
|
|
print(
|
2016-03-03 23:53:29 +00:00
|
|
|
' * Max open files settings is too low (soft: {0}, hard: {1}) '
|
|
|
|
'for running the tests'.format(prev_soft, prev_hard)
|
2015-03-13 22:15:23 +00:00
|
|
|
)
|
|
|
|
print(
|
2016-03-03 23:53:29 +00:00
|
|
|
' * Trying to raise the limits to soft: '
|
|
|
|
'{0}, hard: {1}'.format(soft, hard)
|
2015-03-13 22:15:23 +00:00
|
|
|
)
|
|
|
|
try:
|
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
|
|
|
if salt.utils.platform.is_windows():
|
2017-02-17 20:52:27 +00:00
|
|
|
hard = 2048 if hard > 2048 else hard
|
|
|
|
win32file._setmaxstdio(hard)
|
|
|
|
else:
|
|
|
|
resource.setrlimit(resource.RLIMIT_NOFILE, (soft, hard))
|
2015-03-13 22:15:23 +00:00
|
|
|
except Exception as err:
|
|
|
|
print(
|
2016-03-03 23:53:29 +00:00
|
|
|
'ERROR: Failed to raise the max open files settings -> '
|
2015-03-13 22:15:23 +00:00
|
|
|
'{0}'.format(err)
|
|
|
|
)
|
|
|
|
print('Please issue the following command on your console:')
|
2016-03-03 23:53:29 +00:00
|
|
|
print(' ulimit -n {0}'.format(soft))
|
2015-03-13 22:15:23 +00:00
|
|
|
self.exit()
|
|
|
|
finally:
|
|
|
|
print('~' * getattr(self.options, 'output_columns', PNUM))
|
|
|
|
|
2013-06-24 18:37:07 +00:00
|
|
|
def run_integration_tests(self):
|
|
|
|
'''
|
|
|
|
Execute the integration tests suite
|
|
|
|
'''
|
2013-08-21 09:47:18 +00:00
|
|
|
named_tests = []
|
|
|
|
named_unit_test = []
|
2013-11-08 20:20:03 +00:00
|
|
|
|
|
|
|
if self.options.name:
|
|
|
|
for test in self.options.name:
|
2017-10-11 16:20:14 +00:00
|
|
|
if test.startswith(('tests.unit.', 'unit.', 'test.kitchen.', 'kitchen.')):
|
2013-11-08 20:20:03 +00:00
|
|
|
named_unit_test.append(test)
|
|
|
|
continue
|
|
|
|
named_tests.append(test)
|
2013-08-21 09:47:18 +00:00
|
|
|
|
2017-10-11 16:20:14 +00:00
|
|
|
if (self.options.unit or self.options.kitchen or named_unit_test) and not named_tests and not \
|
2016-02-25 04:56:20 +00:00
|
|
|
self._check_enabled_suites(include_cloud_provider=True):
|
|
|
|
# We're either not running any integration test suites, or we're
|
|
|
|
# only running unit tests by passing --unit or by passing only
|
|
|
|
# `unit.<whatever>` to --name. We don't need the tests daemon
|
|
|
|
# running
|
2013-06-24 18:37:07 +00:00
|
|
|
return [True]
|
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
|
|
|
if not salt.utils.platform.is_windows():
|
2016-03-03 23:53:29 +00:00
|
|
|
self.set_filehandle_limits('integration')
|
2014-01-14 15:25:07 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
print_header(
|
2014-02-09 00:21:18 +00:00
|
|
|
' * Setting up Salt daemons to execute tests',
|
2014-01-14 15:25:07 +00:00
|
|
|
top=False, width=getattr(self.options, 'output_columns', PNUM)
|
|
|
|
)
|
|
|
|
except TypeError:
|
2014-02-09 00:21:18 +00:00
|
|
|
print_header(' * Setting up Salt daemons to execute tests', top=False)
|
2013-06-24 18:37:07 +00:00
|
|
|
|
|
|
|
status = []
|
2016-02-25 04:56:20 +00:00
|
|
|
# Return an empty status if no tests have been enabled
|
2017-05-05 21:32:16 +00:00
|
|
|
if not self._check_enabled_suites(include_cloud_provider=True, include_proxy=True) and not self.options.name:
|
2013-06-24 18:37:07 +00:00
|
|
|
return status
|
2013-08-12 10:46:58 +00:00
|
|
|
|
2013-06-24 18:37:07 +00:00
|
|
|
with TestDaemon(self):
|
|
|
|
if self.options.name:
|
|
|
|
for name in self.options.name:
|
2017-03-02 19:11:37 +00:00
|
|
|
if os.path.isfile(name):
|
|
|
|
if not name.endswith('.py'):
|
|
|
|
continue
|
|
|
|
if name.startswith(os.path.join('tests', 'unit')):
|
|
|
|
continue
|
|
|
|
results = self.run_suite(os.path.dirname(name),
|
|
|
|
name,
|
|
|
|
suffix=os.path.basename(name),
|
|
|
|
load_from_name=False)
|
|
|
|
status.append(results)
|
|
|
|
continue
|
2017-03-03 12:38:00 +00:00
|
|
|
if name.startswith(('tests.unit.', 'unit.')):
|
2013-08-21 09:47:18 +00:00
|
|
|
continue
|
2017-02-17 02:35:42 +00:00
|
|
|
results = self.run_suite('', name, suffix='test_*.py', load_from_name=True)
|
2013-06-24 18:37:07 +00:00
|
|
|
status.append(results)
|
2016-02-25 04:56:20 +00:00
|
|
|
for suite in TEST_SUITES:
|
|
|
|
if suite != 'unit' and getattr(self.options, suite):
|
|
|
|
status.append(self.run_integration_suite(**TEST_SUITES[suite]))
|
2013-06-24 18:37:07 +00:00
|
|
|
return status
|
2012-10-04 23:52:00 +00:00
|
|
|
|
2013-06-24 18:37:07 +00:00
|
|
|
def run_unit_tests(self):
|
|
|
|
'''
|
|
|
|
Execute the unit tests
|
|
|
|
'''
|
2013-08-21 09:47:18 +00:00
|
|
|
named_unit_test = []
|
2013-11-08 20:20:03 +00:00
|
|
|
if self.options.name:
|
|
|
|
for test in self.options.name:
|
2017-03-03 12:38:00 +00:00
|
|
|
if not test.startswith(('tests.unit.', 'unit.')):
|
2013-11-08 20:20:03 +00:00
|
|
|
continue
|
|
|
|
named_unit_test.append(test)
|
2013-08-21 09:47:18 +00:00
|
|
|
|
|
|
|
if not self.options.unit and not named_unit_test:
|
2013-07-04 23:53:41 +00:00
|
|
|
# We are not explicitly running the unit tests and none of the
|
|
|
|
# names passed to --name is a unit test.
|
2013-06-24 18:37:07 +00:00
|
|
|
return [True]
|
2013-07-04 23:53:41 +00:00
|
|
|
|
2013-06-24 18:37:07 +00:00
|
|
|
status = []
|
2013-08-12 10:46:58 +00:00
|
|
|
if self.options.unit:
|
2016-03-03 19:53:17 +00:00
|
|
|
# MacOS needs more open filehandles for running unit test suite
|
2016-03-03 23:53:29 +00:00
|
|
|
self.set_filehandle_limits('unit')
|
2016-03-03 19:53:17 +00:00
|
|
|
|
2013-08-12 10:46:58 +00:00
|
|
|
results = self.run_suite(
|
2017-02-17 02:35:42 +00:00
|
|
|
os.path.join(TEST_DIR, 'unit'), 'Unit', suffix='test_*.py'
|
2013-08-12 10:46:58 +00:00
|
|
|
)
|
|
|
|
status.append(results)
|
|
|
|
# We executed ALL unittests, we can skip running unittests by name
|
2015-01-07 00:55:28 +00:00
|
|
|
# below
|
2013-08-12 10:46:58 +00:00
|
|
|
return status
|
|
|
|
|
2013-08-21 09:47:18 +00:00
|
|
|
for name in named_unit_test:
|
|
|
|
results = self.run_suite(
|
2017-02-17 02:35:42 +00:00
|
|
|
os.path.join(TEST_DIR, 'unit'), name, suffix='test_*.py', load_from_name=True
|
2013-08-21 09:47:18 +00:00
|
|
|
)
|
|
|
|
status.append(results)
|
2013-06-24 18:37:07 +00:00
|
|
|
return status
|
2012-09-30 09:40:06 +00:00
|
|
|
|
2017-10-12 02:40:44 +00:00
|
|
|
def run_kitchen_tests(self):
|
|
|
|
'''
|
|
|
|
Execute the kitchen tests
|
|
|
|
'''
|
|
|
|
named_kitchen_test = []
|
|
|
|
if self.options.name:
|
|
|
|
for test in self.options.name:
|
|
|
|
if not test.startswith(('tests.kitchen.', 'kitchen.')):
|
|
|
|
continue
|
|
|
|
named_kitchen_test.append(test)
|
|
|
|
|
|
|
|
if not self.options.kitchen and not named_kitchen_test:
|
|
|
|
# We are not explicitly running the unit tests and none of the
|
|
|
|
# names passed to --name is a unit test.
|
|
|
|
return [True]
|
|
|
|
|
|
|
|
status = []
|
|
|
|
if self.options.kitchen:
|
|
|
|
results = self.run_suite(
|
|
|
|
os.path.join(TEST_DIR, 'kitchen'), 'Kitchen', suffix='test_*.py'
|
|
|
|
)
|
|
|
|
status.append(results)
|
|
|
|
# We executed ALL unittests, we can skip running unittests by name
|
|
|
|
# below
|
|
|
|
return status
|
|
|
|
|
|
|
|
for name in named_kitchen_test:
|
|
|
|
results = self.run_suite(
|
|
|
|
os.path.join(TEST_DIR, 'kitchen'), name, suffix='test_*.py', load_from_name=True
|
|
|
|
)
|
|
|
|
status.append(results)
|
|
|
|
return status
|
|
|
|
|
2013-06-24 18:37:07 +00:00
|
|
|
|
2018-01-29 14:47:54 +00:00
|
|
|
def main(**kwargs):
|
2013-06-24 18:37:07 +00:00
|
|
|
'''
|
|
|
|
Parse command line options for running specific tests
|
|
|
|
'''
|
2014-07-10 18:51:10 +00:00
|
|
|
try:
|
|
|
|
parser = SaltTestsuiteParser(
|
|
|
|
TEST_DIR,
|
|
|
|
xml_output_dir=XML_OUTPUT_DIR,
|
2016-05-31 19:06:42 +00:00
|
|
|
tests_logfile=os.path.join(SYS_TMP_DIR, 'salt-runtests.log')
|
2014-07-10 18:51:10 +00:00
|
|
|
)
|
|
|
|
parser.parse_args()
|
|
|
|
|
2018-01-29 14:47:54 +00:00
|
|
|
# Override parser options (helpful when importing runtests.py and
|
|
|
|
# running from within a REPL). Using kwargs.items() to avoid importing
|
|
|
|
# six, as this feature will rarely be used.
|
|
|
|
for key, val in kwargs.items():
|
|
|
|
setattr(parser.options, key, val)
|
|
|
|
|
2014-07-10 18:51:10 +00:00
|
|
|
overall_status = []
|
2015-03-13 22:15:23 +00:00
|
|
|
if parser.options.interactive:
|
|
|
|
parser.start_daemons_only()
|
2014-07-10 18:51:10 +00:00
|
|
|
status = parser.run_integration_tests()
|
|
|
|
overall_status.extend(status)
|
|
|
|
status = parser.run_unit_tests()
|
|
|
|
overall_status.extend(status)
|
2017-10-12 02:40:44 +00:00
|
|
|
status = parser.run_kitchen_tests()
|
|
|
|
overall_status.extend(status)
|
2014-07-10 18:51:10 +00:00
|
|
|
false_count = overall_status.count(False)
|
|
|
|
|
|
|
|
if false_count > 0:
|
|
|
|
parser.finalize(1)
|
|
|
|
parser.finalize(0)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print('\nCaught keyboard interrupt. Exiting.\n')
|
|
|
|
exit(0)
|
2013-06-24 18:37:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|