Update ansible-test integration config handling. (#60448)
* Move Ansible test config into env vars. This allows ansible-test to use an empty Ansible config file, leaving open the option for users to customize the one used to run tests (although such usage is discouraged). * Use config from content under test when present.
This commit is contained in:
parent
d9b3af523b
commit
1b8aa798df
|
@ -1,11 +0,0 @@
|
|||
[defaults]
|
||||
# allow cleanup handlers to run when tests fail
|
||||
force_handlers = True
|
||||
# force tests to set ansible_python_interpreter
|
||||
interpreter_python = /set/ansible_python_interpreter/in/inventory
|
||||
# prevent use of global inventory
|
||||
inventory = /dev/null
|
||||
|
||||
[inventory]
|
||||
# prevent tests from unintentionally passing when hosts are not found
|
||||
host_pattern_mismatch = error
|
|
@ -6,9 +6,6 @@ host_key_checking = False
|
|||
log_path = /tmp/ansible-test.out
|
||||
stdout_callback = yaml
|
||||
|
||||
# allow cleanup handlers to run when tests fail
|
||||
force_handlers = True
|
||||
|
||||
[ssh_connection]
|
||||
ssh_args = '-o UserKnownHostsFile=/dev/null'
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
[defaults]
|
||||
# allow cleanup handlers to run when tests fail
|
||||
force_handlers = True
|
|
@ -14,7 +14,6 @@ from .util import (
|
|||
display,
|
||||
find_python,
|
||||
ApplicationError,
|
||||
ANSIBLE_ROOT,
|
||||
ANSIBLE_LIB_ROOT,
|
||||
ANSIBLE_TEST_DATA_ROOT,
|
||||
ANSIBLE_BIN_PATH,
|
||||
|
@ -25,7 +24,7 @@ from .util_common import (
|
|||
)
|
||||
|
||||
from .config import (
|
||||
IntegrationConfig,
|
||||
PosixIntegrationConfig,
|
||||
EnvironmentConfig,
|
||||
)
|
||||
|
||||
|
@ -49,12 +48,9 @@ def ansible_environment(args, color=True, ansible_config=None):
|
|||
if not path.startswith(ANSIBLE_BIN_PATH + os.path.pathsep):
|
||||
path = ANSIBLE_BIN_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_TEST_DATA_ROOT, '%s/ansible.cfg' % args.command)
|
||||
if not ansible_config:
|
||||
# use the default empty configuration unless one has been provided
|
||||
ansible_config = os.path.join(ANSIBLE_TEST_DATA_ROOT, 'ansible.cfg')
|
||||
|
||||
if not args.explain and not os.path.exists(ansible_config):
|
||||
raise ApplicationError('Configuration not found: %s' % ansible_config)
|
||||
|
@ -62,16 +58,24 @@ def ansible_environment(args, color=True, ansible_config=None):
|
|||
ansible = dict(
|
||||
ANSIBLE_PYTHON_MODULE_RLIMIT_NOFILE=str(SOFT_RLIMIT_NOFILE),
|
||||
ANSIBLE_FORCE_COLOR='%s' % 'true' if args.color and color else 'false',
|
||||
ANSIBLE_FORCE_HANDLERS='true', # allow cleanup handlers to run when tests fail
|
||||
ANSIBLE_HOST_PATTERN_MISMATCH='error', # prevent tests from unintentionally passing when hosts are not found
|
||||
ANSIBLE_INVENTORY='/dev/null', # force tests to provide inventory
|
||||
ANSIBLE_DEPRECATION_WARNINGS='false',
|
||||
ANSIBLE_HOST_KEY_CHECKING='false',
|
||||
ANSIBLE_RETRY_FILES_ENABLED='false',
|
||||
ANSIBLE_CONFIG=os.path.abspath(ansible_config),
|
||||
ANSIBLE_CONFIG=ansible_config,
|
||||
ANSIBLE_LIBRARY='/dev/null',
|
||||
PYTHONPATH=os.path.dirname(ANSIBLE_LIB_ROOT),
|
||||
PAGER='/bin/cat',
|
||||
PATH=path,
|
||||
)
|
||||
|
||||
if isinstance(args, PosixIntegrationConfig):
|
||||
ansible.update(dict(
|
||||
ANSIBLE_PYTHON_INTERPRETER='/set/ansible_python_interpreter/in/inventory', # force tests to set ansible_python_interpreter in inventory
|
||||
))
|
||||
|
||||
env.update(ansible)
|
||||
|
||||
if args.debug:
|
||||
|
|
|
@ -29,6 +29,7 @@ from ..util import (
|
|||
MODE_DIRECTORY_WRITE,
|
||||
MODE_FILE,
|
||||
ANSIBLE_ROOT,
|
||||
ANSIBLE_TEST_DATA_ROOT,
|
||||
to_bytes,
|
||||
)
|
||||
|
||||
|
@ -48,6 +49,10 @@ from ..cloud import (
|
|||
CloudEnvironmentConfig,
|
||||
)
|
||||
|
||||
from ..data import (
|
||||
data_context,
|
||||
)
|
||||
|
||||
|
||||
def setup_common_temp_dir(args, path):
|
||||
"""
|
||||
|
@ -135,12 +140,19 @@ def integration_test_environment(args, target, inventory_path):
|
|||
"""
|
||||
vars_file = 'integration_config.yml'
|
||||
|
||||
ansible_config_relative = os.path.join('test', 'integration', '%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):
|
||||
# use the default empty configuration unless one has been provided
|
||||
ansible_config_src = os.path.join(ANSIBLE_TEST_DATA_ROOT, 'ansible.cfg')
|
||||
|
||||
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)
|
||||
ansible_config = os.path.join(integration_dir, '%s.cfg' % args.command)
|
||||
ansible_config = ansible_config_src
|
||||
vars_file = os.path.join(integration_dir, vars_file)
|
||||
|
||||
yield IntegrationEnvironment(integration_dir, inventory_path, ansible_config, vars_file)
|
||||
|
@ -179,10 +191,10 @@ def integration_test_environment(args, target, inventory_path):
|
|||
files_needed = get_files_needed(target_dependencies)
|
||||
|
||||
integration_dir = os.path.join(temp_dir, 'test/integration')
|
||||
ansible_config = os.path.join(integration_dir, '%s.cfg' % args.command)
|
||||
ansible_config = os.path.join(temp_dir, ansible_config_relative)
|
||||
|
||||
file_copies = [
|
||||
(os.path.join(ANSIBLE_ROOT, 'test/integration/%s.cfg' % args.command), ansible_config),
|
||||
(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)),
|
||||
]
|
||||
|
|
|
@ -81,12 +81,9 @@ 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.cfg',
|
||||
'test/integration/integration_config.yml',
|
||||
'test/integration/inventory',
|
||||
'test/integration/network-integration.cfg',
|
||||
'test/integration/target-prefixes.network',
|
||||
'test/integration/windows-integration.cfg',
|
||||
)
|
||||
|
||||
# temporary solution to include files not yet present in the ansible-test data directory
|
||||
|
|
Loading…
Reference in a new issue