Remove ansible-test --tox delegation option.
Use the --venv option instead. This option was only available when running from source to test the ansible/ansible repository. This will have no effect on testing collections or running from an installed version of Ansible. Also update docs to reference the --venv option instead of the --tox option.
This commit is contained in:
parent
0aa59ce9ab
commit
4f51b7d323
11 changed files with 35 additions and 152 deletions
5
changelogs/fragments/ansible-test-remove-tox-option.yml
Normal file
5
changelogs/fragments/ansible-test-remove-tox-option.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
minor_changes:
|
||||
- ansible-test no longer provides a ``--tox`` option.
|
||||
Use the ``--venv`` option instead.
|
||||
This only affects testing the Ansible source.
|
||||
The feature was never available for Ansible Collections or when running from an Ansible install.
|
|
@ -259,7 +259,7 @@ You can run through Ansible's sanity checks in a container:
|
|||
``$ ansible-test sanity -v --docker --python 2.7 MODULE_NAME``
|
||||
|
||||
Note that this example requires Docker to be installed and running. If you'd rather not use a
|
||||
container for this, you can choose to use ``--tox`` instead of ``--docker``.
|
||||
container for this, you can choose to use ``--venv`` instead of ``--docker``.
|
||||
|
||||
Unit tests
|
||||
----------
|
||||
|
|
|
@ -149,7 +149,7 @@ following commands:
|
|||
.. code-block:: shell
|
||||
|
||||
source hacking/env-setup
|
||||
ansible-test units --tox --python 3.7 '.*vmware.*'
|
||||
ansible-test units --venv --python 3.7 '.*vmware.*'
|
||||
|
||||
Code style and best practice
|
||||
============================
|
||||
|
|
|
@ -43,10 +43,9 @@ Environment Variables
|
|||
When using environment variables to manipulate tests there some limitations to keep in mind. Environment variables are:
|
||||
|
||||
* Not propagated from the host to the test environment when using the ``--docker`` or ``--remote`` options.
|
||||
* Not exposed to the test environment unless whitelisted in ``test/runner/lib/util.py`` in the ``common_environment`` function.
|
||||
* Not exposed to the test environment when using the ``--tox`` option unless whitelisted in ``test/runner/tox.ini`` by the ``passenv`` definition.
|
||||
* Not exposed to the test environment unless whitelisted in ``test/lib/ansible_test/_internal/util.py`` in the ``common_environment`` function.
|
||||
|
||||
Example: ``ANSIBLE_KEEP_REMOTE_FILES=1`` can be set when running ``ansible-test integration --tox``. However, using the ``--docker`` option would
|
||||
Example: ``ANSIBLE_KEEP_REMOTE_FILES=1`` can be set when running ``ansible-test integration --venv``. However, using the ``--docker`` option would
|
||||
require running ``ansible-test shell`` to gain access to the Docker environment. Once at the shell prompt, the environment variable could be set
|
||||
and the tests executed. This is useful for debugging tests inside a container by following the
|
||||
:ref:`Debugging AnsibleModule-based modules <debugging_ansiblemodule_based_modules>` instructions.
|
||||
|
@ -57,7 +56,7 @@ Interactive Shell
|
|||
Use the ``ansible-test shell`` command to get an interactive shell in the same environment used to run tests. Examples:
|
||||
|
||||
* ``ansible-test shell --docker`` - Open a shell in the default docker container.
|
||||
* ``ansible-test shell --tox 3.6`` - Open a shell in the Python 3.6 ``tox`` environment.
|
||||
* ``ansible-test shell --venv --python 3.6`` - Open a shell in a Python 3.6 virtual environment.
|
||||
|
||||
|
||||
Code Coverage
|
||||
|
@ -68,12 +67,13 @@ be written. Online reports are available but only cover the ``devel`` branch (s
|
|||
:ref:`developing_testing`). For new code local reports are needed.
|
||||
|
||||
Add the ``--coverage`` option to any test command to collect code coverage data. If you
|
||||
aren't using the ``--tox`` or ``--docker`` options which create an isolated python
|
||||
aren't using the ``--venv`` or ``--docker`` options which create an isolated python
|
||||
environment then you may have to use the ``--requirements`` option to ensure that the
|
||||
correct version of the coverage module is installed::
|
||||
|
||||
ansible-test coverage erase
|
||||
ansible-test units --coverage apt
|
||||
ansible-test integration --coverage aws_lambda --tox --requirements
|
||||
ansible-test integration --coverage aws_lambda
|
||||
ansible-test coverage html
|
||||
|
||||
|
||||
|
|
|
@ -29,25 +29,25 @@ The Ansible unit tests can be run across the whole code base by doing:
|
|||
|
||||
cd /path/to/ansible/source
|
||||
source hacking/env-setup
|
||||
ansible-test units --tox
|
||||
ansible-test units --docker -v
|
||||
|
||||
Against a single file by doing:
|
||||
|
||||
.. code:: shell
|
||||
|
||||
ansible-test units --tox apt
|
||||
ansible-test units --docker -v apt
|
||||
|
||||
Or against a specific Python version by doing:
|
||||
|
||||
.. code:: shell
|
||||
|
||||
ansible-test units --tox --python 2.7 apt
|
||||
ansible-test units --docker -v --python 2.7 apt
|
||||
|
||||
If you are running unit tests against things other than modules, such as module utilities, specify the whole file path:
|
||||
|
||||
.. code:: shell
|
||||
|
||||
ansible-test units --tox test/units/module_utils/basic/test_imports.py
|
||||
ansible-test units --docker -v test/units/module_utils/basic/test_imports.py
|
||||
|
||||
For advanced usage see the online help::
|
||||
|
||||
|
@ -61,26 +61,26 @@ in your pull request.
|
|||
Installing dependencies
|
||||
=======================
|
||||
|
||||
``ansible-test`` has a number of dependencies. For ``units`` tests we suggest using ``tox``.
|
||||
If you are running ``ansible-test`` with the ``--docker`` or ``--venv`` option you do not need to install dependencies manually.
|
||||
|
||||
The dependencies can be installed using the ``--requirements`` argument, which will
|
||||
Otherwise you can install dependencies using the ``--requirements`` option, which will
|
||||
install all the required dependencies needed for unit tests. For example:
|
||||
|
||||
.. code:: shell
|
||||
|
||||
ansible-test units --tox --python 2.7 --requirements apache2_module
|
||||
ansible-test units --python 2.7 --requirements apache2_module
|
||||
|
||||
|
||||
.. note:: tox version requirement
|
||||
The list of unit test requirements can be found at `test/units/requirements.txt
|
||||
<https://github.com/ansible/ansible/tree/devel/test/units/requirements.txt>`_.
|
||||
|
||||
When using ``ansible-test`` with ``--tox`` requires tox >= 2.5.0
|
||||
This does not include the list of unit test requirements for ``ansible-test`` itself,
|
||||
which can be found at `test/lib/ansible_test/_data/requirements/units.txt
|
||||
<https://github.com/ansible/ansible/tree/devel/test/lib/ansible_test/_data/requirements/units.txt>`_.
|
||||
|
||||
|
||||
The full list of requirements can be found at `test/lib/ansible_test/_data/requirements
|
||||
<https://github.com/ansible/ansible/tree/devel/test/lib/ansible_test/_data/requirements>`_. Requirements
|
||||
files are named after their respective commands. See also the `constraints
|
||||
See also the `constraints
|
||||
<https://github.com/ansible/ansible/blob/devel/test/lib/ansible_test/_data/requirements/constraints.txt>`_
|
||||
applicable to all commands.
|
||||
applicable to all test commands.
|
||||
|
||||
|
||||
Extending unit tests
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
[tox]
|
||||
skipsdist = True
|
||||
minversion = 2.5.0
|
||||
|
||||
[testenv]
|
||||
changedir = {toxinidir}/../../
|
||||
commands = {posargs}
|
||||
passenv = HOME LC_ALL SHIPPABLE* ANSIBLE_KEEP_REMOTE_FILES LDFLAGS CFLAGS
|
||||
args_are_paths = False
|
||||
deps = setuptools == 35.0.2
|
||||
wheel < 0.30.0 ; python_version < '2.7'
|
|
@ -288,7 +288,7 @@ def parse_args():
|
|||
|
||||
integration.add_argument('--allow-destructive',
|
||||
action='store_true',
|
||||
help='allow destructive tests (--local and --tox only)')
|
||||
help='allow destructive tests')
|
||||
|
||||
integration.add_argument('--allow-root',
|
||||
action='store_true',
|
||||
|
@ -484,13 +484,13 @@ def parse_args():
|
|||
action='store_true',
|
||||
help='direct to shell with no setup')
|
||||
|
||||
add_environments(shell, tox_version=True)
|
||||
add_environments(shell)
|
||||
add_extra_docker_options(shell)
|
||||
add_httptester_options(shell, argparse)
|
||||
|
||||
coverage_common = argparse.ArgumentParser(add_help=False, parents=[common])
|
||||
|
||||
add_environments(coverage_common, tox_version=True, tox_only=True)
|
||||
add_environments(coverage_common, isolated_delegation=False)
|
||||
|
||||
coverage = subparsers.add_parser('coverage',
|
||||
help='code coverage management and reporting')
|
||||
|
@ -629,11 +629,10 @@ def add_changes(parser, argparse):
|
|||
changes.add_argument('--changed-path', metavar='PATH', action='append', help=argparse.SUPPRESS)
|
||||
|
||||
|
||||
def add_environments(parser, tox_version=False, tox_only=False):
|
||||
def add_environments(parser, isolated_delegation=True):
|
||||
"""
|
||||
:type parser: argparse.ArgumentParser
|
||||
:type tox_version: bool
|
||||
:type tox_only: bool
|
||||
:type isolated_delegation: bool
|
||||
"""
|
||||
parser.add_argument('--requirements',
|
||||
action='store_true',
|
||||
|
@ -654,32 +653,7 @@ def add_environments(parser, tox_version=False, tox_only=False):
|
|||
action='store_true',
|
||||
help='run from ansible-test managed virtual environments')
|
||||
|
||||
if data_context().content.is_ansible:
|
||||
if tox_version:
|
||||
environments.add_argument('--tox',
|
||||
metavar='VERSION',
|
||||
nargs='?',
|
||||
default=None,
|
||||
const='.'.join(str(i) for i in sys.version_info[:2]),
|
||||
choices=SUPPORTED_PYTHON_VERSIONS,
|
||||
help='run from a tox virtualenv: %s' % ', '.join(SUPPORTED_PYTHON_VERSIONS))
|
||||
else:
|
||||
environments.add_argument('--tox',
|
||||
action='store_true',
|
||||
help='run from a tox virtualenv')
|
||||
|
||||
tox = parser.add_argument_group(title='tox arguments')
|
||||
|
||||
tox.add_argument('--tox-sitepackages',
|
||||
action='store_true',
|
||||
help='allow access to globally installed packages')
|
||||
else:
|
||||
environments.set_defaults(
|
||||
tox=None,
|
||||
tox_sitepackages=False,
|
||||
)
|
||||
|
||||
if tox_only:
|
||||
if not isolated_delegation:
|
||||
environments.set_defaults(
|
||||
docker=None,
|
||||
remote=None,
|
||||
|
|
|
@ -46,14 +46,7 @@ class EnvironmentConfig(CommonConfig):
|
|||
self.local = args.local is True
|
||||
self.venv = args.venv
|
||||
|
||||
if args.tox is True or args.tox is False or args.tox is None:
|
||||
self.tox = args.tox is True
|
||||
self.tox_args = 0
|
||||
self.python = args.python if 'python' in args else None # type: str
|
||||
else:
|
||||
self.tox = True
|
||||
self.tox_args = 1
|
||||
self.python = args.tox # type: str
|
||||
|
||||
self.docker = docker_qualify_image(args.docker) # type: str
|
||||
self.docker_raw = args.docker # type: str
|
||||
|
@ -68,8 +61,6 @@ class EnvironmentConfig(CommonConfig):
|
|||
if self.docker_seccomp is None:
|
||||
self.docker_seccomp = get_docker_completion().get(self.docker_raw, {}).get('seccomp', 'default')
|
||||
|
||||
self.tox_sitepackages = args.tox_sitepackages # type: bool
|
||||
|
||||
self.remote_stage = args.remote_stage # type: str
|
||||
self.remote_provider = args.remote_provider # type: str
|
||||
self.remote_aws_region = args.remote_aws_region # type: str
|
||||
|
@ -88,7 +79,7 @@ class EnvironmentConfig(CommonConfig):
|
|||
self.python_version = self.python or actual_major_minor
|
||||
self.python_interpreter = args.python_interpreter
|
||||
|
||||
self.delegate = self.tox or self.docker or self.remote or self.venv
|
||||
self.delegate = self.docker or self.remote or self.venv
|
||||
self.delegate_args = [] # type: t.List[str]
|
||||
|
||||
if self.delegate:
|
||||
|
|
|
@ -139,10 +139,6 @@ def delegate_command(args, exclude, require, integration_targets):
|
|||
delegate_venv(args, exclude, require, integration_targets)
|
||||
return True
|
||||
|
||||
if args.tox:
|
||||
delegate_tox(args, exclude, require, integration_targets)
|
||||
return True
|
||||
|
||||
if args.docker:
|
||||
delegate_docker(args, exclude, require, integration_targets)
|
||||
return True
|
||||
|
@ -154,71 +150,6 @@ def delegate_command(args, exclude, require, integration_targets):
|
|||
return False
|
||||
|
||||
|
||||
def delegate_tox(args, exclude, require, integration_targets):
|
||||
"""
|
||||
:type args: EnvironmentConfig
|
||||
:type exclude: list[str]
|
||||
:type require: list[str]
|
||||
:type integration_targets: tuple[IntegrationTarget]
|
||||
"""
|
||||
if args.python:
|
||||
versions = (args.python_version,)
|
||||
|
||||
if args.python_version not in SUPPORTED_PYTHON_VERSIONS:
|
||||
raise ApplicationError('tox does not support Python version %s' % args.python_version)
|
||||
else:
|
||||
versions = SUPPORTED_PYTHON_VERSIONS
|
||||
|
||||
if args.httptester:
|
||||
needs_httptester = sorted(target.name for target in integration_targets if 'needs/httptester/' in target.aliases)
|
||||
|
||||
if needs_httptester:
|
||||
display.warning('Use --docker or --remote to enable httptester for tests marked "needs/httptester": %s' % ', '.join(needs_httptester))
|
||||
|
||||
options = {
|
||||
'--tox': args.tox_args,
|
||||
'--tox-sitepackages': 0,
|
||||
}
|
||||
|
||||
for version in versions:
|
||||
tox = ['tox', '-c', os.path.join(ANSIBLE_TEST_DATA_ROOT, 'tox.ini'), '-e', 'py' + version.replace('.', '')]
|
||||
|
||||
if args.tox_sitepackages:
|
||||
tox.append('--sitepackages')
|
||||
|
||||
tox.append('--')
|
||||
|
||||
cmd = generate_command(args, None, ANSIBLE_BIN_PATH, data_context().content.root, options, exclude, require)
|
||||
|
||||
if not args.python:
|
||||
cmd += ['--python', version]
|
||||
|
||||
# newer versions of tox do not support older python versions and will silently fall back to a different version
|
||||
# passing this option will allow the delegated ansible-test to verify it is running under the expected python version
|
||||
# tox 3.0.0 dropped official python 2.6 support: https://tox.readthedocs.io/en/latest/changelog.html#v3-0-0-2018-04-02
|
||||
# tox 3.1.3 is the first version to support python 3.8 and later: https://tox.readthedocs.io/en/latest/changelog.html#v3-1-3-2018-08-03
|
||||
# tox 3.1.3 appears to still work with python 2.6, making it a good version to use when supporting all python versions we use
|
||||
# virtualenv 16.0.0 dropped python 2.6 support: https://virtualenv.pypa.io/en/latest/changes/#v16-0-0-2018-05-16
|
||||
cmd += ['--check-python', version]
|
||||
|
||||
if isinstance(args, TestConfig):
|
||||
if args.coverage and not args.coverage_label:
|
||||
cmd += ['--coverage-label', 'tox-%s' % version]
|
||||
|
||||
env = common_environment()
|
||||
|
||||
# temporary solution to permit ansible-test delegated to tox to provision remote resources
|
||||
optional = (
|
||||
'SHIPPABLE',
|
||||
'SHIPPABLE_BUILD_ID',
|
||||
'SHIPPABLE_JOB_NUMBER',
|
||||
)
|
||||
|
||||
env.update(pass_vars(required=[], optional=optional))
|
||||
|
||||
run_command(args, tox + cmd, env=env)
|
||||
|
||||
|
||||
def delegate_venv(args, # type: EnvironmentConfig
|
||||
exclude, # type: t.List[str]
|
||||
require, # type: t.List[str]
|
||||
|
|
|
@ -1603,10 +1603,6 @@ def get_integration_filter(args, targets):
|
|||
:type targets: tuple[IntegrationTarget]
|
||||
:rtype: list[str]
|
||||
"""
|
||||
if args.tox:
|
||||
# tox has the same exclusions as the local environment
|
||||
return get_integration_local_filter(args, targets)
|
||||
|
||||
if args.docker:
|
||||
return get_integration_docker_filter(args, targets)
|
||||
|
||||
|
|
|
@ -40,9 +40,6 @@ class UnversionedSource(SourceProvider):
|
|||
)
|
||||
|
||||
kill_sub_dir = {
|
||||
'test/runner': (
|
||||
'.tox',
|
||||
),
|
||||
'test': (
|
||||
'results',
|
||||
'cache',
|
||||
|
|
Loading…
Reference in a new issue