|
|
@ -318,9 +318,11 @@ def command_posix_integration(args):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
:type args: PosixIntegrationConfig
|
|
|
|
:type args: PosixIntegrationConfig
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
filename = 'test/integration/inventory'
|
|
|
|
|
|
|
|
|
|
|
|
all_targets = tuple(walk_posix_integration_targets(include_hidden=True))
|
|
|
|
all_targets = tuple(walk_posix_integration_targets(include_hidden=True))
|
|
|
|
internal_targets = command_integration_filter(args, all_targets)
|
|
|
|
internal_targets = command_integration_filter(args, all_targets)
|
|
|
|
command_integration_filtered(args, internal_targets, all_targets)
|
|
|
|
command_integration_filtered(args, internal_targets, all_targets, filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def command_network_integration(args):
|
|
|
|
def command_network_integration(args):
|
|
|
@ -381,7 +383,7 @@ def command_network_integration(args):
|
|
|
|
success = False
|
|
|
|
success = False
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
command_integration_filtered(args, internal_targets, all_targets)
|
|
|
|
command_integration_filtered(args, internal_targets, all_targets, filename)
|
|
|
|
success = True
|
|
|
|
success = True
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
if args.remote_terminate == 'always' or (args.remote_terminate == 'success' and success):
|
|
|
|
if args.remote_terminate == 'always' or (args.remote_terminate == 'success' and success):
|
|
|
@ -603,7 +605,7 @@ def command_windows_integration(args):
|
|
|
|
success = False
|
|
|
|
success = False
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
command_integration_filtered(args, internal_targets, all_targets, pre_target=pre_target,
|
|
|
|
command_integration_filtered(args, internal_targets, all_targets, filename, pre_target=pre_target,
|
|
|
|
post_target=post_target)
|
|
|
|
post_target=post_target)
|
|
|
|
success = True
|
|
|
|
success = True
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
@ -766,11 +768,12 @@ def command_integration_filter(args, targets, init_callback=None):
|
|
|
|
return internal_targets
|
|
|
|
return internal_targets
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def command_integration_filtered(args, targets, all_targets, pre_target=None, post_target=None):
|
|
|
|
def command_integration_filtered(args, targets, all_targets, inventory_path, pre_target=None, post_target=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
:type args: IntegrationConfig
|
|
|
|
:type args: IntegrationConfig
|
|
|
|
:type targets: tuple[IntegrationTarget]
|
|
|
|
:type targets: tuple[IntegrationTarget]
|
|
|
|
:type all_targets: tuple[IntegrationTarget]
|
|
|
|
:type all_targets: tuple[IntegrationTarget]
|
|
|
|
|
|
|
|
:type inventory_path: str
|
|
|
|
:type pre_target: (IntegrationTarget) -> None | None
|
|
|
|
:type pre_target: (IntegrationTarget) -> None | None
|
|
|
|
:type post_target: (IntegrationTarget) -> None | None
|
|
|
|
:type post_target: (IntegrationTarget) -> None | None
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -848,11 +851,11 @@ def command_integration_filtered(args, targets, all_targets, pre_target=None, po
|
|
|
|
if cloud_environment:
|
|
|
|
if cloud_environment:
|
|
|
|
cloud_environment.setup_once()
|
|
|
|
cloud_environment.setup_once()
|
|
|
|
|
|
|
|
|
|
|
|
run_setup_targets(args, test_dir, target.setup_once, all_targets_dict, setup_targets_executed, False)
|
|
|
|
run_setup_targets(args, test_dir, target.setup_once, all_targets_dict, setup_targets_executed, inventory_path, False)
|
|
|
|
|
|
|
|
|
|
|
|
start_time = time.time()
|
|
|
|
start_time = time.time()
|
|
|
|
|
|
|
|
|
|
|
|
run_setup_targets(args, test_dir, target.setup_always, all_targets_dict, setup_targets_executed, True)
|
|
|
|
run_setup_targets(args, test_dir, target.setup_always, all_targets_dict, setup_targets_executed, inventory_path, True)
|
|
|
|
|
|
|
|
|
|
|
|
if not args.explain:
|
|
|
|
if not args.explain:
|
|
|
|
# create a fresh test directory for each test target
|
|
|
|
# create a fresh test directory for each test target
|
|
|
@ -864,9 +867,9 @@ def command_integration_filtered(args, targets, all_targets, pre_target=None, po
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if target.script_path:
|
|
|
|
if target.script_path:
|
|
|
|
command_integration_script(args, target, test_dir)
|
|
|
|
command_integration_script(args, target, test_dir, inventory_path)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
command_integration_role(args, target, start_at_task, test_dir)
|
|
|
|
command_integration_role(args, target, start_at_task, test_dir, inventory_path)
|
|
|
|
start_at_task = None
|
|
|
|
start_at_task = None
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
if post_target:
|
|
|
|
if post_target:
|
|
|
@ -1070,13 +1073,14 @@ rdr pass inet proto tcp from any to any port 443 -> 127.0.0.1 port 8443
|
|
|
|
raise ApplicationError('No supported port forwarding mechanism detected.')
|
|
|
|
raise ApplicationError('No supported port forwarding mechanism detected.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_setup_targets(args, test_dir, target_names, targets_dict, targets_executed, always):
|
|
|
|
def run_setup_targets(args, test_dir, target_names, targets_dict, targets_executed, inventory_path, always):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
:type args: IntegrationConfig
|
|
|
|
:type args: IntegrationConfig
|
|
|
|
:type test_dir: str
|
|
|
|
:type test_dir: str
|
|
|
|
:type target_names: list[str]
|
|
|
|
:type target_names: list[str]
|
|
|
|
:type targets_dict: dict[str, IntegrationTarget]
|
|
|
|
:type targets_dict: dict[str, IntegrationTarget]
|
|
|
|
:type targets_executed: set[str]
|
|
|
|
:type targets_executed: set[str]
|
|
|
|
|
|
|
|
:type inventory_path: str
|
|
|
|
:type always: bool
|
|
|
|
:type always: bool
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
for target_name in target_names:
|
|
|
|
for target_name in target_names:
|
|
|
@ -1091,19 +1095,20 @@ def run_setup_targets(args, test_dir, target_names, targets_dict, targets_execut
|
|
|
|
make_dirs(test_dir)
|
|
|
|
make_dirs(test_dir)
|
|
|
|
|
|
|
|
|
|
|
|
if target.script_path:
|
|
|
|
if target.script_path:
|
|
|
|
command_integration_script(args, target, test_dir)
|
|
|
|
command_integration_script(args, target, test_dir, inventory_path)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
command_integration_role(args, target, None, test_dir)
|
|
|
|
command_integration_role(args, target, None, test_dir, inventory_path)
|
|
|
|
|
|
|
|
|
|
|
|
targets_executed.add(target_name)
|
|
|
|
targets_executed.add(target_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def integration_environment(args, target, cmd, test_dir):
|
|
|
|
def integration_environment(args, target, cmd, test_dir, inventory_path):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
:type args: IntegrationConfig
|
|
|
|
:type args: IntegrationConfig
|
|
|
|
:type target: IntegrationTarget
|
|
|
|
:type target: IntegrationTarget
|
|
|
|
:type cmd: list[str]
|
|
|
|
:type cmd: list[str]
|
|
|
|
:type test_dir: str
|
|
|
|
:type test_dir: str
|
|
|
|
|
|
|
|
:type inventory_path: str
|
|
|
|
:rtype: dict[str, str]
|
|
|
|
:rtype: dict[str, str]
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
env = ansible_environment(args)
|
|
|
|
env = ansible_environment(args)
|
|
|
@ -1118,6 +1123,7 @@ def integration_environment(args, target, cmd, test_dir):
|
|
|
|
ANSIBLE_CALLBACK_WHITELIST='junit',
|
|
|
|
ANSIBLE_CALLBACK_WHITELIST='junit',
|
|
|
|
ANSIBLE_TEST_CI=args.metadata.ci_provider,
|
|
|
|
ANSIBLE_TEST_CI=args.metadata.ci_provider,
|
|
|
|
OUTPUT_DIR=test_dir,
|
|
|
|
OUTPUT_DIR=test_dir,
|
|
|
|
|
|
|
|
INVENTORY_PATH=os.path.abspath(inventory_path),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if args.debug_strategy:
|
|
|
|
if args.debug_strategy:
|
|
|
@ -1139,11 +1145,12 @@ def integration_environment(args, target, cmd, test_dir):
|
|
|
|
return env
|
|
|
|
return env
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def command_integration_script(args, target, test_dir):
|
|
|
|
def command_integration_script(args, target, test_dir, inventory_path):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
:type args: IntegrationConfig
|
|
|
|
:type args: IntegrationConfig
|
|
|
|
:type target: IntegrationTarget
|
|
|
|
:type target: IntegrationTarget
|
|
|
|
:type test_dir: str
|
|
|
|
:type test_dir: str
|
|
|
|
|
|
|
|
:type inventory_path: str
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
display.info('Running %s integration test script' % target.name)
|
|
|
|
display.info('Running %s integration test script' % target.name)
|
|
|
|
|
|
|
|
|
|
|
@ -1152,33 +1159,31 @@ def command_integration_script(args, target, test_dir):
|
|
|
|
if args.verbosity:
|
|
|
|
if args.verbosity:
|
|
|
|
cmd.append('-' + ('v' * args.verbosity))
|
|
|
|
cmd.append('-' + ('v' * args.verbosity))
|
|
|
|
|
|
|
|
|
|
|
|
env = integration_environment(args, target, cmd, test_dir)
|
|
|
|
env = integration_environment(args, target, cmd, test_dir, inventory_path)
|
|
|
|
cwd = target.path
|
|
|
|
cwd = target.path
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
def command_integration_role(args, target, start_at_task, test_dir, inventory_path):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
:type args: IntegrationConfig
|
|
|
|
:type args: IntegrationConfig
|
|
|
|
:type target: IntegrationTarget
|
|
|
|
:type target: IntegrationTarget
|
|
|
|
:type start_at_task: str | None
|
|
|
|
:type start_at_task: str | None
|
|
|
|
:type test_dir: str
|
|
|
|
:type test_dir: str
|
|
|
|
|
|
|
|
:type inventory_path: str
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
display.info('Running %s integration test role' % target.name)
|
|
|
|
display.info('Running %s integration test role' % target.name)
|
|
|
|
|
|
|
|
|
|
|
|
vars_file = 'integration_config.yml'
|
|
|
|
vars_file = 'integration_config.yml'
|
|
|
|
|
|
|
|
|
|
|
|
if isinstance(args, WindowsIntegrationConfig):
|
|
|
|
if isinstance(args, WindowsIntegrationConfig):
|
|
|
|
inventory = 'inventory.winrm'
|
|
|
|
|
|
|
|
hosts = 'windows'
|
|
|
|
hosts = 'windows'
|
|
|
|
gather_facts = False
|
|
|
|
gather_facts = False
|
|
|
|
elif isinstance(args, NetworkIntegrationConfig):
|
|
|
|
elif isinstance(args, NetworkIntegrationConfig):
|
|
|
|
inventory = args.inventory or 'inventory.networking'
|
|
|
|
|
|
|
|
hosts = target.name[:target.name.find('_')]
|
|
|
|
hosts = target.name[:target.name.find('_')]
|
|
|
|
gather_facts = False
|
|
|
|
gather_facts = False
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
inventory = 'inventory'
|
|
|
|
|
|
|
|
hosts = 'testhost'
|
|
|
|
hosts = 'testhost'
|
|
|
|
gather_facts = True
|
|
|
|
gather_facts = True
|
|
|
|
|
|
|
|
|
|
|
@ -1194,6 +1199,11 @@ def command_integration_role(args, target, start_at_task, test_dir):
|
|
|
|
- { role: %s }
|
|
|
|
- { role: %s }
|
|
|
|
''' % (hosts, gather_facts, target.name)
|
|
|
|
''' % (hosts, gather_facts, target.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inventory = os.path.relpath(inventory_path, 'test/integration')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if '/' in inventory:
|
|
|
|
|
|
|
|
inventory = inventory_path
|
|
|
|
|
|
|
|
|
|
|
|
with tempfile.NamedTemporaryFile(dir='test/integration', prefix='%s-' % target.name, suffix='.yml') as pb_fd:
|
|
|
|
with tempfile.NamedTemporaryFile(dir='test/integration', prefix='%s-' % target.name, suffix='.yml') as pb_fd:
|
|
|
|
pb_fd.write(playbook.encode('utf-8'))
|
|
|
|
pb_fd.write(playbook.encode('utf-8'))
|
|
|
|
pb_fd.flush()
|
|
|
|
pb_fd.flush()
|
|
|
@ -1223,7 +1233,7 @@ def command_integration_role(args, target, start_at_task, test_dir):
|
|
|
|
if args.verbosity:
|
|
|
|
if args.verbosity:
|
|
|
|
cmd.append('-' + ('v' * args.verbosity))
|
|
|
|
cmd.append('-' + ('v' * args.verbosity))
|
|
|
|
|
|
|
|
|
|
|
|
env = integration_environment(args, target, cmd, test_dir)
|
|
|
|
env = integration_environment(args, target, cmd, test_dir, inventory_path)
|
|
|
|
cwd = 'test/integration'
|
|
|
|
cwd = 'test/integration'
|
|
|
|
|
|
|
|
|
|
|
|
env['ANSIBLE_ROLES_PATH'] = os.path.abspath('test/integration/targets')
|
|
|
|
env['ANSIBLE_ROLES_PATH'] = os.path.abspath('test/integration/targets')
|
|
|
|