From 1b8aa798df6f6fa96ba5ea2a9dbf01b3f1de555c Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 13 Aug 2019 13:18:55 -0700 Subject: [PATCH] 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. --- test/integration/integration.cfg | 11 ---------- test/integration/network-integration.cfg | 3 --- test/integration/windows-integration.cfg | 3 --- .../ansible_test/_data/{env => }/ansible.cfg | 0 .../lib/ansible_test/_data/sanity/ansible.cfg | 0 test/lib/ansible_test/_data/units/ansible.cfg | 0 .../ansible_test/_internal/ansible_util.py | 22 +++++++++++-------- .../_internal/integration/__init__.py | 18 ++++++++++++--- test/lib/ansible_test/_internal/payload.py | 3 --- 9 files changed, 28 insertions(+), 32 deletions(-) delete mode 100644 test/integration/integration.cfg delete mode 100644 test/integration/windows-integration.cfg rename test/lib/ansible_test/_data/{env => }/ansible.cfg (100%) delete mode 100644 test/lib/ansible_test/_data/sanity/ansible.cfg delete mode 100644 test/lib/ansible_test/_data/units/ansible.cfg diff --git a/test/integration/integration.cfg b/test/integration/integration.cfg deleted file mode 100644 index 8f232a276da..00000000000 --- a/test/integration/integration.cfg +++ /dev/null @@ -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 diff --git a/test/integration/network-integration.cfg b/test/integration/network-integration.cfg index acbb4e53ddf..66357f5c327 100644 --- a/test/integration/network-integration.cfg +++ b/test/integration/network-integration.cfg @@ -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' diff --git a/test/integration/windows-integration.cfg b/test/integration/windows-integration.cfg deleted file mode 100644 index f0ce19704b8..00000000000 --- a/test/integration/windows-integration.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[defaults] -# allow cleanup handlers to run when tests fail -force_handlers = True diff --git a/test/lib/ansible_test/_data/env/ansible.cfg b/test/lib/ansible_test/_data/ansible.cfg similarity index 100% rename from test/lib/ansible_test/_data/env/ansible.cfg rename to test/lib/ansible_test/_data/ansible.cfg diff --git a/test/lib/ansible_test/_data/sanity/ansible.cfg b/test/lib/ansible_test/_data/sanity/ansible.cfg deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/lib/ansible_test/_data/units/ansible.cfg b/test/lib/ansible_test/_data/units/ansible.cfg deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/lib/ansible_test/_internal/ansible_util.py b/test/lib/ansible_test/_internal/ansible_util.py index c3b10becb9e..18c4c13b2df 100644 --- a/test/lib/ansible_test/_internal/ansible_util.py +++ b/test/lib/ansible_test/_internal/ansible_util.py @@ -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: diff --git a/test/lib/ansible_test/_internal/integration/__init__.py b/test/lib/ansible_test/_internal/integration/__init__.py index 5f43e2020d9..f0ae9ed567d 100644 --- a/test/lib/ansible_test/_internal/integration/__init__.py +++ b/test/lib/ansible_test/_internal/integration/__init__.py @@ -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)), ] diff --git a/test/lib/ansible_test/_internal/payload.py b/test/lib/ansible_test/_internal/payload.py index 4635bc19a98..3adb46f7ef1 100644 --- a/test/lib/ansible_test/_internal/payload.py +++ b/test/lib/ansible_test/_internal/payload.py @@ -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