mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Initial ansible-test implementation. (#18556)
This commit is contained in:
parent
d95eac16eb
commit
6bbd92e422
191 changed files with 5483 additions and 48 deletions
1
test/runner/injector/ansible
Symbolic link
1
test/runner/injector/ansible
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/ansible-console
Symbolic link
1
test/runner/injector/ansible-console
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/ansible-doc
Symbolic link
1
test/runner/injector/ansible-doc
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/ansible-galaxy
Symbolic link
1
test/runner/injector/ansible-galaxy
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/ansible-playbook
Symbolic link
1
test/runner/injector/ansible-playbook
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/ansible-pull
Symbolic link
1
test/runner/injector/ansible-pull
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/ansible-vault
Symbolic link
1
test/runner/injector/ansible-vault
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/cover
Symbolic link
1
test/runner/injector/cover
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/cover2
Symbolic link
1
test/runner/injector/cover2
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/cover2.4
Symbolic link
1
test/runner/injector/cover2.4
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/cover2.6
Symbolic link
1
test/runner/injector/cover2.6
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/cover2.7
Symbolic link
1
test/runner/injector/cover2.7
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/cover3
Symbolic link
1
test/runner/injector/cover3
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/cover3.5
Symbolic link
1
test/runner/injector/cover3.5
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
184
test/runner/injector/injector.py
Executable file
184
test/runner/injector/injector.py
Executable file
|
@ -0,0 +1,184 @@
|
|||
#!/usr/bin/env python
|
||||
"""Code coverage wrapper."""
|
||||
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
import errno
|
||||
import os
|
||||
import sys
|
||||
import pipes
|
||||
import logging
|
||||
import getpass
|
||||
|
||||
logger = logging.getLogger('injector') # pylint: disable=locally-disabled, invalid-name
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point."""
|
||||
formatter = logging.Formatter('%(asctime)s ' + str(os.getpid()) + ' %(levelname)s %(message)s')
|
||||
log_name = 'ansible-test-coverage.%s.log' % getpass.getuser()
|
||||
self_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
handler = logging.FileHandler(os.path.join('/tmp', log_name))
|
||||
handler.setFormatter(formatter)
|
||||
logger.addHandler(handler)
|
||||
|
||||
handler = logging.FileHandler(os.path.abspath(os.path.join(self_dir, '..', 'logs', log_name)))
|
||||
handler.setFormatter(formatter)
|
||||
logger.addHandler(handler)
|
||||
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
try:
|
||||
logger.debug('Self: %s', __file__)
|
||||
logger.debug('Arguments: %s', ' '.join(pipes.quote(c) for c in sys.argv))
|
||||
|
||||
if os.path.basename(__file__).startswith('runner'):
|
||||
args, env = runner()
|
||||
elif os.path.basename(__file__).startswith('cover'):
|
||||
args, env = cover()
|
||||
else:
|
||||
args, env = injector()
|
||||
|
||||
logger.debug('Run command: %s', ' '.join(pipes.quote(c) for c in args))
|
||||
|
||||
try:
|
||||
cwd = os.getcwd()
|
||||
except OSError as ex:
|
||||
if ex.errno != errno.EACCES:
|
||||
raise
|
||||
cwd = None
|
||||
|
||||
logger.debug('Working directory: %s', cwd or '?')
|
||||
|
||||
for key in sorted(env.keys()):
|
||||
logger.debug('%s=%s', key, env[key])
|
||||
|
||||
os.execvpe(args[0], args, env)
|
||||
except Exception as ex:
|
||||
logger.fatal(ex)
|
||||
raise
|
||||
|
||||
|
||||
def injector():
|
||||
"""
|
||||
:rtype: list[str], dict[str, str]
|
||||
"""
|
||||
self_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
command = os.path.basename(__file__)
|
||||
mode = os.environ.get('ANSIBLE_TEST_COVERAGE')
|
||||
version = os.environ.get('ANSIBLE_TEST_PYTHON_VERSION', '')
|
||||
executable = find_executable(command)
|
||||
|
||||
if mode in ('coverage', 'version'):
|
||||
if mode == 'coverage':
|
||||
args, env = coverage_command(self_dir, version)
|
||||
args += [executable]
|
||||
tool = 'cover'
|
||||
else:
|
||||
interpreter = find_executable('python' + version)
|
||||
args, env = [interpreter, executable], os.environ.copy()
|
||||
tool = 'runner'
|
||||
|
||||
if command in ('ansible', 'ansible-playbook', 'ansible-pull'):
|
||||
interpreter = find_executable(tool + version)
|
||||
args += ['--extra-vars', 'ansible_python_interpreter=' + interpreter]
|
||||
else:
|
||||
args, env = [executable], os.environ.copy()
|
||||
|
||||
args += sys.argv[1:]
|
||||
|
||||
return args, env
|
||||
|
||||
|
||||
def runner():
|
||||
"""
|
||||
:rtype: list[str], dict[str, str]
|
||||
"""
|
||||
command = os.path.basename(__file__)
|
||||
version = command.replace('runner', '')
|
||||
|
||||
interpreter = find_executable('python' + version)
|
||||
args, env = [interpreter], os.environ.copy()
|
||||
|
||||
args += sys.argv[1:]
|
||||
|
||||
return args, env
|
||||
|
||||
|
||||
def cover():
|
||||
"""
|
||||
:rtype: list[str], dict[str, str]
|
||||
"""
|
||||
self_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
command = os.path.basename(__file__)
|
||||
version = command.replace('cover', '')
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
executable = sys.argv[1]
|
||||
else:
|
||||
executable = ''
|
||||
|
||||
if os.path.basename(executable).startswith('ansible_module_'):
|
||||
args, env = coverage_command(self_dir, version)
|
||||
else:
|
||||
interpreter = find_executable('python' + version)
|
||||
args, env = [interpreter], os.environ.copy()
|
||||
|
||||
args += sys.argv[1:]
|
||||
|
||||
return args, env
|
||||
|
||||
|
||||
def coverage_command(self_dir, version):
|
||||
"""
|
||||
:type self_dir: str
|
||||
:type version: str
|
||||
:rtype: list[str], dict[str, str]
|
||||
"""
|
||||
executable = 'coverage'
|
||||
|
||||
if version:
|
||||
executable += '-%s' % version
|
||||
|
||||
args = [
|
||||
find_executable(executable),
|
||||
'run',
|
||||
'--append',
|
||||
'--rcfile',
|
||||
os.path.join(self_dir, '.coveragerc'),
|
||||
]
|
||||
|
||||
env = os.environ.copy()
|
||||
env['COVERAGE_FILE'] = os.path.abspath(os.path.join(self_dir, '..', 'output', 'coverage'))
|
||||
|
||||
return args, env
|
||||
|
||||
|
||||
def find_executable(executable):
|
||||
"""
|
||||
:type executable: str
|
||||
:rtype: str
|
||||
"""
|
||||
self = os.path.abspath(__file__)
|
||||
path = os.environ.get('PATH', os.defpath)
|
||||
seen_dirs = set()
|
||||
|
||||
for path_dir in path.split(os.pathsep):
|
||||
if path_dir in seen_dirs:
|
||||
continue
|
||||
|
||||
seen_dirs.add(path_dir)
|
||||
candidate = os.path.abspath(os.path.join(path_dir, executable))
|
||||
|
||||
if candidate == self:
|
||||
continue
|
||||
|
||||
if os.path.exists(candidate) and os.access(candidate, os.F_OK | os.X_OK):
|
||||
return candidate
|
||||
|
||||
raise Exception('Executable "%s" not found in path: %s' % (executable, path))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
1
test/runner/injector/pytest
Symbolic link
1
test/runner/injector/pytest
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/runner
Symbolic link
1
test/runner/injector/runner
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/runner2
Symbolic link
1
test/runner/injector/runner2
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/runner2.4
Symbolic link
1
test/runner/injector/runner2.4
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/runner2.6
Symbolic link
1
test/runner/injector/runner2.6
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/runner2.7
Symbolic link
1
test/runner/injector/runner2.7
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/runner3
Symbolic link
1
test/runner/injector/runner3
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
1
test/runner/injector/runner3.5
Symbolic link
1
test/runner/injector/runner3.5
Symbolic link
|
@ -0,0 +1 @@
|
|||
injector.py
|
Loading…
Add table
Add a link
Reference in a new issue