mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 21:31:26 -07:00
Run integration tests from temporary directory.
ci_complete
This commit is contained in:
parent
18c35b69fb
commit
b834b29e43
7 changed files with 327 additions and 43 deletions
|
@ -7,7 +7,6 @@ import os
|
|||
import collections
|
||||
import datetime
|
||||
import re
|
||||
import tempfile
|
||||
import time
|
||||
import textwrap
|
||||
import functools
|
||||
|
@ -55,6 +54,7 @@ from lib.util import (
|
|||
generate_pip_command,
|
||||
find_python,
|
||||
get_docker_completion,
|
||||
named_temporary_file,
|
||||
)
|
||||
|
||||
from lib.docker_util import (
|
||||
|
@ -108,6 +108,10 @@ from lib.metadata import (
|
|||
ChangeDescription,
|
||||
)
|
||||
|
||||
from lib.integration import (
|
||||
integration_test_environment,
|
||||
)
|
||||
|
||||
SUPPORTED_PYTHON_VERSIONS = (
|
||||
'2.6',
|
||||
'2.7',
|
||||
|
@ -1102,16 +1106,17 @@ def run_setup_targets(args, test_dir, target_names, targets_dict, targets_execut
|
|||
targets_executed.add(target_name)
|
||||
|
||||
|
||||
def integration_environment(args, target, cmd, test_dir, inventory_path):
|
||||
def integration_environment(args, target, cmd, test_dir, inventory_path, ansible_config):
|
||||
"""
|
||||
:type args: IntegrationConfig
|
||||
:type target: IntegrationTarget
|
||||
:type cmd: list[str]
|
||||
:type test_dir: str
|
||||
:type inventory_path: str
|
||||
:type ansible_config: str | None
|
||||
:rtype: dict[str, str]
|
||||
"""
|
||||
env = ansible_environment(args)
|
||||
env = ansible_environment(args, ansible_config=ansible_config)
|
||||
|
||||
if args.inject_httptester:
|
||||
env.update(dict(
|
||||
|
@ -1154,15 +1159,16 @@ def command_integration_script(args, target, test_dir, inventory_path):
|
|||
"""
|
||||
display.info('Running %s integration test script' % target.name)
|
||||
|
||||
cmd = ['./%s' % os.path.basename(target.script_path)]
|
||||
with integration_test_environment(args, target, inventory_path) as test_env:
|
||||
cmd = ['./%s' % os.path.basename(target.script_path)]
|
||||
|
||||
if args.verbosity:
|
||||
cmd.append('-' + ('v' * args.verbosity))
|
||||
if args.verbosity:
|
||||
cmd.append('-' + ('v' * args.verbosity))
|
||||
|
||||
env = integration_environment(args, target, cmd, test_dir, inventory_path)
|
||||
cwd = target.path
|
||||
env = integration_environment(args, target, cmd, test_dir, test_env.inventory_path, test_env.ansible_config)
|
||||
cwd = os.path.join(test_env.integration_dir, 'targets', target.name)
|
||||
|
||||
intercept_command(args, cmd, target_name=target.name, env=env, cwd=cwd)
|
||||
intercept_command(args, cmd, target_name=target.name, env=env, cwd=cwd)
|
||||
|
||||
|
||||
def command_integration_role(args, target, start_at_task, test_dir, inventory_path):
|
||||
|
@ -1175,8 +1181,6 @@ def command_integration_role(args, target, start_at_task, test_dir, inventory_pa
|
|||
"""
|
||||
display.info('Running %s integration test role' % target.name)
|
||||
|
||||
vars_file = 'integration_config.yml'
|
||||
|
||||
if isinstance(args, WindowsIntegrationConfig):
|
||||
hosts = 'windows'
|
||||
gather_facts = False
|
||||
|
@ -1199,46 +1203,39 @@ def command_integration_role(args, target, start_at_task, test_dir, inventory_pa
|
|||
- { role: %s }
|
||||
''' % (hosts, gather_facts, target.name)
|
||||
|
||||
inventory = os.path.relpath(inventory_path, 'test/integration')
|
||||
with integration_test_environment(args, target, inventory_path) as test_env:
|
||||
with named_temporary_file(args=args, directory=test_env.integration_dir, prefix='%s-' % target.name, suffix='.yml', content=playbook) as playbook_path:
|
||||
filename = os.path.basename(playbook_path)
|
||||
|
||||
if '/' in inventory:
|
||||
inventory = inventory_path
|
||||
display.info('>>> Playbook: %s\n%s' % (filename, playbook.strip()), verbosity=3)
|
||||
|
||||
with tempfile.NamedTemporaryFile(dir='test/integration', prefix='%s-' % target.name, suffix='.yml') as pb_fd:
|
||||
pb_fd.write(playbook.encode('utf-8'))
|
||||
pb_fd.flush()
|
||||
cmd = ['ansible-playbook', filename, '-i', test_env.inventory_path, '-e', '@%s' % test_env.vars_file]
|
||||
|
||||
filename = os.path.basename(pb_fd.name)
|
||||
if start_at_task:
|
||||
cmd += ['--start-at-task', start_at_task]
|
||||
|
||||
display.info('>>> Playbook: %s\n%s' % (filename, playbook.strip()), verbosity=3)
|
||||
if args.tags:
|
||||
cmd += ['--tags', args.tags]
|
||||
|
||||
cmd = ['ansible-playbook', filename, '-i', inventory, '-e', '@%s' % vars_file]
|
||||
if args.skip_tags:
|
||||
cmd += ['--skip-tags', args.skip_tags]
|
||||
|
||||
if start_at_task:
|
||||
cmd += ['--start-at-task', start_at_task]
|
||||
if args.diff:
|
||||
cmd += ['--diff']
|
||||
|
||||
if args.tags:
|
||||
cmd += ['--tags', args.tags]
|
||||
if isinstance(args, NetworkIntegrationConfig):
|
||||
if args.testcase:
|
||||
cmd += ['-e', 'testcase=%s' % args.testcase]
|
||||
|
||||
if args.skip_tags:
|
||||
cmd += ['--skip-tags', args.skip_tags]
|
||||
if args.verbosity:
|
||||
cmd.append('-' + ('v' * args.verbosity))
|
||||
|
||||
if args.diff:
|
||||
cmd += ['--diff']
|
||||
env = integration_environment(args, target, cmd, test_dir, test_env.inventory_path, test_env.ansible_config)
|
||||
cwd = test_env.integration_dir
|
||||
|
||||
if isinstance(args, NetworkIntegrationConfig):
|
||||
if args.testcase:
|
||||
cmd += ['-e', 'testcase=%s' % args.testcase]
|
||||
env['ANSIBLE_ROLES_PATH'] = os.path.abspath(os.path.join(test_env.integration_dir, 'targets'))
|
||||
|
||||
if args.verbosity:
|
||||
cmd.append('-' + ('v' * args.verbosity))
|
||||
|
||||
env = integration_environment(args, target, cmd, test_dir, inventory_path)
|
||||
cwd = 'test/integration'
|
||||
|
||||
env['ANSIBLE_ROLES_PATH'] = os.path.abspath('test/integration/targets')
|
||||
|
||||
intercept_command(args, cmd, target_name=target.name, env=env, cwd=cwd)
|
||||
intercept_command(args, cmd, target_name=target.name, env=env, cwd=cwd)
|
||||
|
||||
|
||||
def command_units(args):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue