Load integration config test vars from content.

The `test/integration/integration_config.yml` vars file will now be loaded from the content under test and is now optional.

The `output_dir` and `win_output_dir` vars are now provided by ansible-test.
pull/60624/head
Matt Clay 5 years ago
parent 4ebac7d5b7
commit 7968dc4c00

@ -1,3 +0,0 @@
---
win_output_dir: 'C:\ansible_testing'
output_dir: ~/ansible_testing

@ -129,6 +129,7 @@ from .integration import (
integration_test_environment,
integration_test_config_file,
setup_common_temp_dir,
VARS_FILE_RELATIVE,
)
from .data import (
@ -817,6 +818,23 @@ def command_integration_filter(args, # type: TIntegrationConfig
cloud_init(args, internal_targets)
vars_file_src = os.path.join(data_context().content.root, VARS_FILE_RELATIVE)
if os.path.exists(vars_file_src):
def integration_config_callback(files): # type: (t.List[t.Tuple[str, str]]) -> None
"""
Add the integration config vars file to the payload file list.
This will preserve the file during delegation even if the file is ignored by source control.
"""
if data_context().content.collection:
working_path = data_context().content.collection.directory
else:
working_path = ''
files.append((vars_file_src, os.path.join(working_path, VARS_FILE_RELATIVE)))
data_context().register_payload_callback(integration_config_callback)
if args.delegate:
raise Delegate(require=require, exclude=exclude, integration_targets=internal_targets)
@ -1273,9 +1291,17 @@ def command_integration_role(args, target, start_at_task, test_dir, inventory_pa
env_config = None
vars_files = []
variables = dict(
output_dir=test_dir,
)
if isinstance(args, WindowsIntegrationConfig):
hosts = 'windows'
gather_facts = False
variables.update(dict(
win_output_dir=r'C:\ansible_testing',
))
elif isinstance(args, NetworkIntegrationConfig):
hosts = target.name[:target.name.find('_')]
gather_facts = False
@ -1289,12 +1315,14 @@ def command_integration_role(args, target, start_at_task, test_dir, inventory_pa
env_config = cloud_environment.get_environment_config()
with integration_test_environment(args, target, inventory_path) as test_env:
if os.path.exists(test_env.vars_file):
vars_files.append(os.path.relpath(test_env.vars_file, test_env.integration_dir))
play = dict(
hosts=hosts,
gather_facts=gather_facts,
vars_files=[
os.path.relpath(test_env.vars_file, test_env.integration_dir),
],
vars_files=vars_files,
vars=variables,
roles=[
target.name,
],

@ -53,6 +53,9 @@ from ..data import (
data_context,
)
INTEGRATION_DIR_RELATIVE = 'test/integration'
VARS_FILE_RELATIVE = os.path.join(INTEGRATION_DIR_RELATIVE, 'integration_config.yml')
def setup_common_temp_dir(args, path):
"""
@ -138,9 +141,7 @@ def integration_test_environment(args, target, inventory_path):
:type target: IntegrationTarget
:type inventory_path: str
"""
vars_file = 'integration_config.yml'
ansible_config_relative = os.path.join('test', 'integration', '%s.cfg' % args.command)
ansible_config_relative = os.path.join(INTEGRATION_DIR_RELATIVE, '%s.cfg' % args.command)
ansible_config_src = os.path.join(data_context().content.root, ansible_config_relative)
if not os.path.exists(ansible_config_src):
@ -150,10 +151,10 @@ def integration_test_environment(args, target, inventory_path):
if args.no_temp_workdir or 'no/temp_workdir/' in target.aliases:
display.warning('Disabling the temp work dir is a temporary debugging feature that may be removed in the future without notice.')
integration_dir = os.path.abspath('test/integration')
inventory_path = os.path.abspath(inventory_path)
integration_dir = os.path.join(data_context().content.root, INTEGRATION_DIR_RELATIVE)
inventory_path = os.path.join(data_context().content.root, inventory_path)
ansible_config = ansible_config_src
vars_file = os.path.join(integration_dir, vars_file)
vars_file = os.path.join(data_context().content.root, VARS_FILE_RELATIVE)
yield IntegrationEnvironment(integration_dir, inventory_path, ansible_config, vars_file)
return
@ -190,19 +191,25 @@ def integration_test_environment(args, target, inventory_path):
files_needed = get_files_needed(target_dependencies)
integration_dir = os.path.join(temp_dir, 'test/integration')
integration_dir = os.path.join(temp_dir, INTEGRATION_DIR_RELATIVE)
ansible_config = os.path.join(temp_dir, ansible_config_relative)
vars_file_src = os.path.join(data_context().content.root, VARS_FILE_RELATIVE)
vars_file = os.path.join(temp_dir, VARS_FILE_RELATIVE)
file_copies = [
(ansible_config_src, ansible_config),
(os.path.join(ANSIBLE_ROOT, 'test/integration/integration_config.yml'), os.path.join(integration_dir, vars_file)),
(os.path.join(ANSIBLE_ROOT, inventory_path), os.path.join(integration_dir, inventory_name)),
]
if os.path.exists(vars_file_src):
file_copies.append((vars_file_src, vars_file))
file_copies += [(path, os.path.join(temp_dir, path)) for path in files_needed]
directory_copies = [
(os.path.join('test/integration/targets', target.name), os.path.join(integration_dir, 'targets', target.name)) for target in target_dependencies
(os.path.join(INTEGRATION_DIR_RELATIVE, 'targets', target.name), os.path.join(integration_dir, 'targets', target.name))
for target in target_dependencies
]
inventory_dir = os.path.dirname(inventory_path)
@ -236,7 +243,6 @@ def integration_test_environment(args, target, inventory_path):
shutil.copy2(file_src, file_dst)
inventory_path = os.path.join(integration_dir, inventory_name)
vars_file = os.path.join(integration_dir, vars_file)
yield IntegrationEnvironment(integration_dir, inventory_path, ansible_config, vars_file)
finally:

@ -81,9 +81,7 @@ def create_payload(args, dst_path): # type: (CommonConfig, str) -> None
# these files need to be migrated to the ansible-test data directory
hack_files_to_keep = (
'test/integration/integration_config.yml',
'test/integration/inventory',
'test/integration/target-prefixes.network',
)
# temporary solution to include files not yet present in the ansible-test data directory

Loading…
Cancel
Save