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:
Matt Clay 2019-08-13 13:18:55 -07:00 committed by GitHub
parent d9b3af523b
commit 1b8aa798df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 28 additions and 32 deletions

View file

@ -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

View file

@ -6,9 +6,6 @@ host_key_checking = False
log_path = /tmp/ansible-test.out log_path = /tmp/ansible-test.out
stdout_callback = yaml stdout_callback = yaml
# allow cleanup handlers to run when tests fail
force_handlers = True
[ssh_connection] [ssh_connection]
ssh_args = '-o UserKnownHostsFile=/dev/null' ssh_args = '-o UserKnownHostsFile=/dev/null'

View file

@ -1,3 +0,0 @@
[defaults]
# allow cleanup handlers to run when tests fail
force_handlers = True

View file

@ -14,7 +14,6 @@ from .util import (
display, display,
find_python, find_python,
ApplicationError, ApplicationError,
ANSIBLE_ROOT,
ANSIBLE_LIB_ROOT, ANSIBLE_LIB_ROOT,
ANSIBLE_TEST_DATA_ROOT, ANSIBLE_TEST_DATA_ROOT,
ANSIBLE_BIN_PATH, ANSIBLE_BIN_PATH,
@ -25,7 +24,7 @@ from .util_common import (
) )
from .config import ( from .config import (
IntegrationConfig, PosixIntegrationConfig,
EnvironmentConfig, EnvironmentConfig,
) )
@ -49,12 +48,9 @@ def ansible_environment(args, color=True, ansible_config=None):
if not path.startswith(ANSIBLE_BIN_PATH + os.path.pathsep): if not path.startswith(ANSIBLE_BIN_PATH + os.path.pathsep):
path = ANSIBLE_BIN_PATH + os.path.pathsep + path path = ANSIBLE_BIN_PATH + os.path.pathsep + path
if ansible_config: if not ansible_config:
pass # use the default empty configuration unless one has been provided
elif isinstance(args, IntegrationConfig): ansible_config = os.path.join(ANSIBLE_TEST_DATA_ROOT, 'ansible.cfg')
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 args.explain and not os.path.exists(ansible_config): if not args.explain and not os.path.exists(ansible_config):
raise ApplicationError('Configuration not found: %s' % 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 = dict(
ANSIBLE_PYTHON_MODULE_RLIMIT_NOFILE=str(SOFT_RLIMIT_NOFILE), ANSIBLE_PYTHON_MODULE_RLIMIT_NOFILE=str(SOFT_RLIMIT_NOFILE),
ANSIBLE_FORCE_COLOR='%s' % 'true' if args.color and color else 'false', 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_DEPRECATION_WARNINGS='false',
ANSIBLE_HOST_KEY_CHECKING='false', ANSIBLE_HOST_KEY_CHECKING='false',
ANSIBLE_RETRY_FILES_ENABLED='false', ANSIBLE_RETRY_FILES_ENABLED='false',
ANSIBLE_CONFIG=os.path.abspath(ansible_config), ANSIBLE_CONFIG=ansible_config,
ANSIBLE_LIBRARY='/dev/null', ANSIBLE_LIBRARY='/dev/null',
PYTHONPATH=os.path.dirname(ANSIBLE_LIB_ROOT), PYTHONPATH=os.path.dirname(ANSIBLE_LIB_ROOT),
PAGER='/bin/cat', PAGER='/bin/cat',
PATH=path, 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) env.update(ansible)
if args.debug: if args.debug:

View file

@ -29,6 +29,7 @@ from ..util import (
MODE_DIRECTORY_WRITE, MODE_DIRECTORY_WRITE,
MODE_FILE, MODE_FILE,
ANSIBLE_ROOT, ANSIBLE_ROOT,
ANSIBLE_TEST_DATA_ROOT,
to_bytes, to_bytes,
) )
@ -48,6 +49,10 @@ from ..cloud import (
CloudEnvironmentConfig, CloudEnvironmentConfig,
) )
from ..data import (
data_context,
)
def setup_common_temp_dir(args, path): def setup_common_temp_dir(args, path):
""" """
@ -135,12 +140,19 @@ def integration_test_environment(args, target, inventory_path):
""" """
vars_file = 'integration_config.yml' 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: 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.') 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') integration_dir = os.path.abspath('test/integration')
inventory_path = os.path.abspath(inventory_path) 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) vars_file = os.path.join(integration_dir, vars_file)
yield IntegrationEnvironment(integration_dir, inventory_path, ansible_config, 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) files_needed = get_files_needed(target_dependencies)
integration_dir = os.path.join(temp_dir, 'test/integration') 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 = [ 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, '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)), (os.path.join(ANSIBLE_ROOT, inventory_path), os.path.join(integration_dir, inventory_name)),
] ]

View file

@ -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 # these files need to be migrated to the ansible-test data directory
hack_files_to_keep = ( hack_files_to_keep = (
'test/integration/integration.cfg',
'test/integration/integration_config.yml', 'test/integration/integration_config.yml',
'test/integration/inventory', 'test/integration/inventory',
'test/integration/network-integration.cfg',
'test/integration/target-prefixes.network', 'test/integration/target-prefixes.network',
'test/integration/windows-integration.cfg',
) )
# temporary solution to include files not yet present in the ansible-test data directory # temporary solution to include files not yet present in the ansible-test data directory