def ansible_environment(args): """ :type args: CommonConfig :rtype: dict[str, str] """ env = common_environment() path = env['PATH'] ansible_path = os.path.join(os.getcwd(), 'bin') if not path.startswith(ansible_path + os.pathsep): path = ansible_path + os.pathsep + path ansible = dict( ANSIBLE_FORCE_COLOR='%s' % 'true' if args.color else 'false', ANSIBLE_DEPRECATION_WARNINGS='false', ANSIBLE_CONFIG='/dev/null', ANSIBLE_HOST_KEY_CHECKING='false', PYTHONPATH=os.path.abspath('lib'), PAGER='/bin/cat', PATH=path, ) env.update(ansible) return env
def ansible_environment(args, color=True): """ :type args: CommonConfig :type color: bool :rtype: dict[str, str] """ env = common_environment() path = env['PATH'] ansible_path = os.path.join(os.getcwd(), 'bin') if not path.startswith(ansible_path + os.pathsep): path = ansible_path + os.pathsep + path ansible = dict( ANSIBLE_FORCE_COLOR='%s' % 'true' if args.color and color else 'false', ANSIBLE_DEPRECATION_WARNINGS='false', ANSIBLE_HOST_KEY_CHECKING='false', PYTHONPATH=os.path.abspath('lib'), PAGER='/bin/cat', PATH=path, ) if os.path.isfile('test/integration/%s.cfg' % args.command): ansible_config = os.path.abspath('test/integration/%s.cfg' % args.command) ansible['ANSIBLE_CONFIG'] = ansible_config env.update(ansible) if args.debug: env.update(dict(ANSIBLE_DEBUG='true')) return env
def docker_environment(): """ :rtype: dict[str, str] """ env = common_environment() env.update(dict((key, os.environ[key]) for key in os.environ if key.startswith('DOCKER_'))) return env
def command_coverage_report(args): """ :type args: CoverageReportConfig """ output_files = command_coverage_combine(args) for output_file in output_files: if args.group_by or args.stub: display.info( '>>> Coverage Group: %s' % ' '.join(os.path.basename(output_file).split('=')[1:])) options = [] if args.show_missing: options.append('--show-missing') if args.include: options.extend(['--include', args.include]) if args.omit: options.extend(['--omit', args.omit]) env = common_environment() env.update(dict(COVERAGE_FILE=output_file)) run_command(args, env=env, cmd=['coverage', 'report'] + options)
def ansible_environment(args): """ :type args: CommonConfig :rtype: dict[str, str] """ env = common_environment() path = env["PATH"] ansible_path = os.path.join(os.getcwd(), "bin") if not path.startswith(ansible_path + os.pathsep): path = ansible_path + os.pathsep + path ansible = dict( ANSIBLE_FORCE_COLOR="%s" % "true" if args.color else "false", ANSIBLE_DEPRECATION_WARNINGS="false", ANSIBLE_CONFIG="/dev/null", PYTHONPATH=os.path.abspath("lib"), PAGER="/bin/cat", PATH=path, ) env.update(ansible) return env
def intercept_command(args, cmd, capture=False, env=None, data=None, cwd=None, python_version=None): """ :type args: TestConfig :type cmd: collections.Iterable[str] :type capture: bool :type env: dict[str, str] | None :type data: str | None :type cwd: str | None :type python_version: str | None :rtype: str | None, str | None """ if not env: env = common_environment() cmd = list(cmd) escaped_cmd = ' '.join(pipes.quote(c) for c in cmd) inject_path = get_coverage_path(args) env['PATH'] = inject_path + os.pathsep + env['PATH'] env['ANSIBLE_TEST_COVERAGE'] = 'coverage' if args.coverage else 'version' env['ANSIBLE_TEST_PYTHON_VERSION'] = python_version or args.python_version env['ANSIBLE_TEST_CMD'] = escaped_cmd return run_command(args, cmd, capture=capture, env=env, data=data, cwd=cwd)
def ansible_environment(args, color=True, ansible_config=None): """ :type args: CommonConfig :type color: bool :type ansible_config: str | None :rtype: dict[str, str] """ env = common_environment() path = env['PATH'] ansible_path = os.path.join(os.getcwd(), 'bin') if not path.startswith(ansible_path + os.path.pathsep): path = ansible_path + os.path.pathsep + path if ansible_config: pass elif isinstance(args, IntegrationConfig): ansible_config = 'tests/integration/%s.cfg' % args.command else: #ansible_config = 'test/%s/ansible.cfg' % args.command ansible_config = os.path.join( os.path.dirname(ansible_test.__file__), 'lib', args.command, 'ansible.cfg' ) if not args.explain and not os.path.exists(ansible_config): raise ApplicationError('Configuration not found: %s' % ansible_config) ansible = dict( ANSIBLE_PYTHON_MODULE_RLIMIT_NOFILE=str(SOFT_RLIMIT_NOFILE), ANSIBLE_FORCE_COLOR='%s' % 'true' if args.color and color else 'false', ANSIBLE_DEPRECATION_WARNINGS='false', ANSIBLE_HOST_KEY_CHECKING='false', ANSIBLE_RETRY_FILES_ENABLED='false', ANSIBLE_CONFIG=os.path.abspath(ansible_config), ANSIBLE_LIBRARY='/dev/null', PYTHONPATH=os.path.abspath('lib'), PAGER='/bin/cat', PATH=path, ) env.update(ansible) if args.debug: logdir = os.path.abspath('tests/results/logs') if not os.path.exists(logdir): os.makedirs(logdir) logfile = os.path.join(logdir, 'debug.log') env.update(dict( ANSIBLE_DEBUG='true', ANSIBLE_LOG_PATH=logfile), ) return env
def ansible_environment(args, color=True, ansible_config=None): """ :type args: CommonConfig :type color: bool :type ansible_config: str | None :rtype: dict[str, str] """ env = common_environment() path = env['PATH'] ansible_path = os.path.join(ANSIBLE_ROOT, 'bin') if not path.startswith(ansible_path + os.path.pathsep): path = ansible_path + os.path.pathsep + path if ansible_config: pass elif isinstance(args, IntegrationConfig): ansible_config = os.path.join(ANSIBLE_ROOT, 'test/integration/%s.cfg' % args.command) else: ansible_config = os.path.join(ANSIBLE_ROOT, 'test/%s/ansible.cfg' % args.command) if not args.explain and not os.path.exists(ansible_config): raise ApplicationError('Configuration not found: %s' % ansible_config) ansible = dict( ANSIBLE_PYTHON_MODULE_RLIMIT_NOFILE=str(SOFT_RLIMIT_NOFILE), ANSIBLE_FORCE_COLOR='%s' % 'true' if args.color and color else 'false', ANSIBLE_DEPRECATION_WARNINGS='false', ANSIBLE_HOST_KEY_CHECKING='false', ANSIBLE_RETRY_FILES_ENABLED='false', ANSIBLE_CONFIG=os.path.abspath(ansible_config), ANSIBLE_LIBRARY='/dev/null', PYTHONPATH=os.path.join(ANSIBLE_ROOT, 'lib'), PAGER='/bin/cat', PATH=path, ) env.update(ansible) if args.debug: env.update( dict( ANSIBLE_DEBUG='true', ANSIBLE_LOG_PATH=os.path.abspath( 'test/results/logs/debug.log'), )) if data_context().content.collection: env.update( dict(ANSIBLE_COLLECTIONS_PATHS=data_context().content.collection. root, )) return env
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', 'test/runner/tox.ini', '-e', 'py' + version.replace('.', '')] if args.tox_sitepackages: tox.append('--sitepackages') tox.append('--') cmd = generate_command(args, os.path.abspath('test/runner/test.py'), options, exclude, require) if not args.python: cmd += ['--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 command_coverage_xml(args): """ :type args: CoverageConfig """ output_files = command_coverage_combine(args) for output_file in output_files: xml_name = 'test/results/reports/%s.xml' % os.path.basename(output_file) env = common_environment() env.update(dict(COVERAGE_FILE=output_file)) run_command(args, env=env, cmd=['coverage', 'xml', '-o', xml_name])
def docker_environment(): """ :rtype: dict[str, str] """ env = common_environment() env.update( dict((key, os.environ[key]) for key in os.environ if key.startswith('DOCKER_'))) #env['PYTHONPATH'] = '/root/ansible' #import epdb; epdb.st() return env
def command_coverage_xml(args): """ :type args: CoverageConfig """ output_files = command_coverage_combine(args) for output_file in output_files: xml_name = 'test/results/reports/%s.xml' % os.path.basename(output_file) env = common_environment() env.update(dict(COVERAGE_FILE=output_file)) run_command(args, env=env, cmd=['coverage', 'xml', '-i', '-o', xml_name])
def delegate_tox(args, exclude, require): """ :type args: EnvironmentConfig :type exclude: list[str] :type require: list[str] """ if args.python: versions = args.python, if args.python not in SUPPORTED_PYTHON_VERSIONS: raise ApplicationError('tox does not support Python version %s' % args.python) else: versions = SUPPORTED_PYTHON_VERSIONS options = { '--tox': args.tox_args, '--tox-sitepackages': 0, } for version in versions: tox = [ 'tox', '-c', 'test/runner/tox.ini', '-e', 'py' + version.replace('.', '') ] if args.tox_sitepackages: tox.append('--sitepackages') tox.append('--') cmd = generate_command(args, os.path.abspath('test/runner/test.py'), options, exclude, require) if not args.python: cmd += ['--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 command_coverage_report(args): """ :type args: CoverageConfig """ output_files = command_coverage_combine(args) for output_file in output_files: if args.group_by or args.stub: display.info('>>> Coverage Group: %s' % ' '.join(os.path.basename(output_file).split('=')[1:])) env = common_environment() env.update(dict(COVERAGE_FILE=output_file)) run_command(args, env=env, cmd=['coverage', 'report'])
def intercept_command(args, cmd, target_name, env, capture=False, data=None, cwd=None, python_version=None, temp_path=None, module_coverage=True, virtualenv=None): """ :type args: TestConfig :type cmd: collections.Iterable[str] :type target_name: str :type env: dict[str, str] :type capture: bool :type data: str | None :type cwd: str | None :type python_version: str | None :type temp_path: str | None :type module_coverage: bool :type virtualenv: str | None :rtype: str | None, str | None """ if not env: env = common_environment() cmd = list(cmd) version = python_version or args.python_version interpreter = virtualenv or find_python(version) inject_path = os.path.join(INSTALL_ROOT, 'test/runner/injector') if not virtualenv: # injection of python into the path is required when not activating a virtualenv # otherwise scripts may find the wrong interpreter or possibly no interpreter python_path = get_python_path(args, interpreter) inject_path = python_path + os.path.pathsep + inject_path env['PATH'] = inject_path + os.path.pathsep + env['PATH'] env['ANSIBLE_TEST_PYTHON_VERSION'] = version env['ANSIBLE_TEST_PYTHON_INTERPRETER'] = interpreter if args.coverage: # add the necessary environment variables to enable code coverage collection env.update( get_coverage_environment(args, target_name, version, temp_path, module_coverage)) return run_command(args, cmd, capture=capture, env=env, data=data, cwd=cwd)
def intercept_command(args, cmd, target_name, capture=False, env=None, data=None, cwd=None, python_version=None, path=None): """ :type args: TestConfig :type cmd: collections.Iterable[str] :type target_name: str :type capture: bool :type env: dict[str, str] | None :type data: str | None :type cwd: str | None :type python_version: str | None :type path: str | None :rtype: str | None, str | None """ if not env: env = common_environment() cmd = list(cmd) inject_path = get_coverage_path(args) config_path = os.path.join(inject_path, 'injector.json') version = python_version or args.python_version interpreter = find_executable('python%s' % version, path=path) coverage_file = os.path.abspath( os.path.join( inject_path, '..', 'output', '%s=%s=%s=%s=coverage' % (args.command, target_name, args.coverage_label or 'local-%s' % version, 'python-%s' % version))) env['PATH'] = inject_path + os.pathsep + env['PATH'] env['ANSIBLE_TEST_PYTHON_VERSION'] = version env['ANSIBLE_TEST_PYTHON_INTERPRETER'] = interpreter config = dict( python_interpreter=interpreter, coverage_file=coverage_file if args.coverage else None, ) if not args.explain: with open(config_path, 'w') as config_fd: json.dump(config, config_fd, indent=4, sort_keys=True) return run_command(args, cmd, capture=capture, env=env, data=data, cwd=cwd)
def delegate_tox(args, exclude, require): """ :type args: EnvironmentConfig :type exclude: list[str] :type require: list[str] """ if args.python: versions = args.python, if args.python not in SUPPORTED_PYTHON_VERSIONS: raise ApplicationError('tox does not support Python version %s' % args.python) else: versions = SUPPORTED_PYTHON_VERSIONS options = { '--tox': args.tox_args, '--tox-sitepackages': 0, } for version in versions: tox = ['tox', '-c', 'test/runner/tox.ini', '-e', 'py' + version.replace('.', '')] if args.tox_sitepackages: tox.append('--sitepackages') tox.append('--') cmd = generate_command(args, os.path.abspath('test/runner/test.py'), options, exclude, require) if not args.python: cmd += ['--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 ansible_environment(args, color=True): """ :type args: CommonConfig :type color: bool :rtype: dict[str, str] """ env = common_environment() path = env['PATH'] ansible_path = os.path.join(os.getcwd(), 'bin') if not path.startswith(ansible_path + os.path.pathsep): path = ansible_path + os.path.pathsep + path if isinstance(args, IntegrationConfig): ansible_config = 'test/integration/%s.cfg' % args.command else: ansible_config = 'test/%s/ansible.cfg' % args.command if not os.path.exists(ansible_config): raise ApplicationError('Configuration not found: %s' % ansible_config) ansible = dict( ANSIBLE_FORCE_COLOR='%s' % 'true' if args.color and color else 'false', ANSIBLE_DEPRECATION_WARNINGS='false', ANSIBLE_HOST_KEY_CHECKING='false', ANSIBLE_RETRY_FILES_ENABLED='false', ANSIBLE_CONFIG=os.path.abspath(ansible_config), ANSIBLE_LIBRARY='/dev/null', PYTHONPATH=os.path.abspath('lib'), PAGER='/bin/cat', PATH=path, ) env.update(ansible) if args.debug: env.update( dict( ANSIBLE_DEBUG='true', ANSIBLE_LOG_PATH=os.path.abspath( 'test/results/logs/debug.log'), )) return env
def ansible_environment(args, color=True): """ :type args: CommonConfig :type color: bool :rtype: dict[str, str] """ env = common_environment() path = env['PATH'] ansible_path = os.path.join(os.getcwd(), 'bin') if not path.startswith(ansible_path + os.pathsep): path = ansible_path + os.pathsep + path if isinstance(args, IntegrationConfig): ansible_config = 'test/integration/%s.cfg' % args.command else: ansible_config = 'test/%s/ansible.cfg' % args.command if not os.path.exists(ansible_config): raise ApplicationError('Configuration not found: %s' % ansible_config) ansible = dict( ANSIBLE_FORCE_COLOR='%s' % 'true' if args.color and color else 'false', ANSIBLE_DEPRECATION_WARNINGS='false', ANSIBLE_HOST_KEY_CHECKING='false', ANSIBLE_CONFIG=os.path.abspath(ansible_config), PYTHONPATH=os.path.abspath('lib'), PAGER='/bin/cat', PATH=path, ) env.update(ansible) if args.debug: env.update(dict( ANSIBLE_DEBUG='true', ANSIBLE_LOG_PATH=os.path.abspath('test/results/logs/debug.log'), )) return env
def intercept_command(args, cmd, target_name, capture=False, env=None, data=None, cwd=None, python_version=None, path=None): """ :type args: TestConfig :type cmd: collections.Iterable[str] :type target_name: str :type capture: bool :type env: dict[str, str] | None :type data: str | None :type cwd: str | None :type python_version: str | None :type path: str | None :rtype: str | None, str | None """ if not env: env = common_environment() cmd = list(cmd) inject_path = get_coverage_path(args) config_path = os.path.join(inject_path, 'injector.json') version = python_version or args.python_version interpreter = find_executable('python%s' % version, path=path) coverage_file = os.path.abspath(os.path.join(inject_path, '..', 'output', '%s=%s=%s=%s=coverage' % ( args.command, target_name, args.coverage_label or 'local-%s' % version, 'python-%s' % version))) env['PATH'] = inject_path + os.pathsep + env['PATH'] env['ANSIBLE_TEST_PYTHON_VERSION'] = version env['ANSIBLE_TEST_PYTHON_INTERPRETER'] = interpreter config = dict( python_interpreter=interpreter, coverage_file=coverage_file if args.coverage else None, ) if not args.explain: with open(config_path, 'w') as config_fd: json.dump(config, config_fd, indent=4, sort_keys=True) return run_command(args, cmd, capture=capture, env=env, data=data, cwd=cwd)
def command_coverage_report(args): """ :type args: CoverageReportConfig """ output_files = command_coverage_combine(args) for output_file in output_files: if args.group_by or args.stub: display.info('>>> Coverage Group: %s' % ' '.join(os.path.basename(output_file).split('=')[1:])) options = [] if args.show_missing: options.append('--show-missing') if args.include: options.extend(['--include', args.include]) if args.omit: options.extend(['--omit', args.omit]) env = common_environment() env.update(dict(COVERAGE_FILE=output_file)) run_command(args, env=env, cmd=['coverage', 'report'] + options)
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', 'test/runner/tox.ini', '-e', 'py' + version.replace('.', '')] if args.tox_sitepackages: tox.append('--sitepackages') tox.append('--') cmd = generate_command(args, None, ANSIBLE_ROOT, 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)