From 35665db4ed052337ed2f1ee543a728a7fc06b02b Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Thu, 20 Mar 2025 09:48:02 -0700 Subject: [PATCH] Miscellaneous integration test fixes (#84871) --- .../targets/ansible-test-cloud-aws/tasks/main.yml | 12 ++++++------ .../ansible-test-cloud-azure/tasks/main.yml | 12 ++++++------ .../ansible-test-cloud-openshift/tasks/main.yml | 2 +- test/integration/targets/ansible/runme.sh | 2 +- test/integration/targets/apt/tasks/upgrade.yml | 2 +- .../targets/connection_winrm/tests.yml | 2 +- .../integration/targets/debugger/test_run_once.py | 2 +- .../targets/failed_when/tasks/main.yml | 6 ++++++ .../targets/gathering_facts/verify_subset.yml | 2 +- .../targets/hash/test_inventory_hash.yml | 2 +- .../targets/hostname/tasks/test_check_mode.yml | 2 +- .../targets/lookup_vars/tasks/main.yml | 3 +-- .../targets/prepare_http_tests/tasks/kerberos.yml | 2 +- .../targets/unarchive/tasks/test_mode.yml | 4 ++-- test/integration/targets/undefined/tasks/main.yml | 3 +-- test/integration/targets/uri/tasks/main.yml | 2 +- .../ansible-var-precedence-check.py | 2 +- test/integration/targets/win_fetch/tasks/main.yml | 8 ++++---- test/integration/targets/win_raw/tasks/main.yml | 7 +++---- .../integration/targets/win_script/tasks/main.yml | 15 ++++++--------- 20 files changed, 46 insertions(+), 46 deletions(-) diff --git a/test/integration/targets/ansible-test-cloud-aws/tasks/main.yml b/test/integration/targets/ansible-test-cloud-aws/tasks/main.yml index 4f7c4c4d921..4fb43fd4a01 100644 --- a/test/integration/targets/ansible-test-cloud-aws/tasks/main.yml +++ b/test/integration/targets/ansible-test-cloud-aws/tasks/main.yml @@ -1,12 +1,12 @@ - name: Verify variables are set assert: that: - - aws_access_key - - aws_region - - aws_secret_key - - resource_prefix - - security_token - - tiny_prefix + - aws_access_key is defined + - aws_region is defined + - aws_secret_key is defined + - resource_prefix is defined + - security_token is defined + - tiny_prefix is defined - name: Show variables debug: msg: "{{ lookup('vars', item) }}" diff --git a/test/integration/targets/ansible-test-cloud-azure/tasks/main.yml b/test/integration/targets/ansible-test-cloud-azure/tasks/main.yml index c9201ba67e7..543aaeb241f 100644 --- a/test/integration/targets/ansible-test-cloud-azure/tasks/main.yml +++ b/test/integration/targets/ansible-test-cloud-azure/tasks/main.yml @@ -1,12 +1,12 @@ - name: Verify variables are set assert: that: - - azure_client_id - - azure_secret - - azure_subscription_id - - azure_tenant - - resource_group - - resource_group_secondary + - azure_client_id is defined + - azure_secret is defined + - azure_subscription_id is defined + - azure_tenant is defined + - resource_group is defined + - resource_group_secondary is defined - name: Show variables debug: msg: "{{ lookup('vars', item) }}" diff --git a/test/integration/targets/ansible-test-cloud-openshift/tasks/main.yml b/test/integration/targets/ansible-test-cloud-openshift/tasks/main.yml index 6acb67dc12c..5281a36d597 100644 --- a/test/integration/targets/ansible-test-cloud-openshift/tasks/main.yml +++ b/test/integration/targets/ansible-test-cloud-openshift/tasks/main.yml @@ -3,7 +3,7 @@ - name: Verify endpoints exist assert: - that: clusters + that: clusters is defined - name: Verify endpoints respond uri: diff --git a/test/integration/targets/ansible/runme.sh b/test/integration/targets/ansible/runme.sh index d6780214751..eab05f4b035 100755 --- a/test/integration/targets/ansible/runme.sh +++ b/test/integration/targets/ansible/runme.sh @@ -20,7 +20,7 @@ ANSIBLE_COLLECTIONS_PATH=/tmp/collections ansible-config dump| grep 'COLLECTIONS ansible-config list | grep 'COLLECTIONS_PATHS' # 'view' command must fail when config file is missing or has an invalid file extension -ansible-config view -c ./ansible-non-existent.cfg 2> err1.txt || grep -Eq 'ERROR! The provided configuration file is missing or not accessible:' err1.txt || (cat err*.txt; rm -f err1.txt; exit 1) +ansible-config view -c ./ansible-non-existent.cfg 2> err1.txt || grep -Eq 'The provided configuration file is missing or not accessible:' err1.txt || (cat err*.txt; rm -f err1.txt; exit 1) ansible-config view -c ./no-extension 2> err2.txt || grep -q 'Unsupported configuration file extension' err2.txt || (cat err2.txt; rm -f err*.txt; exit 1) rm -f err*.txt diff --git a/test/integration/targets/apt/tasks/upgrade.yml b/test/integration/targets/apt/tasks/upgrade.yml index 4fdfd065d8c..719d4e62e95 100644 --- a/test/integration/targets/apt/tasks/upgrade.yml +++ b/test/integration/targets/apt/tasks/upgrade.yml @@ -31,7 +31,7 @@ - name: check that warning is not given when force_apt_get set assert: that: - - "'warnings' not in upgrade_result" + - upgrade_result.warnings | default([]) | length == 0 when: - force_apt_get diff --git a/test/integration/targets/connection_winrm/tests.yml b/test/integration/targets/connection_winrm/tests.yml index 36be126aca7..c6fe4091a54 100644 --- a/test/integration/targets/connection_winrm/tests.yml +++ b/test/integration/targets/connection_winrm/tests.yml @@ -67,7 +67,7 @@ - name: run ping with loop to exceed quota win_ping: - loop: '{{ range(0, 4) }}' + loop: '{{ range(0, 4) | list }}' always: - name: reset WinRM quota value diff --git a/test/integration/targets/debugger/test_run_once.py b/test/integration/targets/debugger/test_run_once.py index 0b65c42492b..2c7c81e0f5b 100755 --- a/test/integration/targets/debugger/test_run_once.py +++ b/test/integration/targets/debugger/test_run_once.py @@ -27,7 +27,7 @@ with io.BytesIO() as logfile: debugger_test_test.logfile = logfile debugger_test_test.expect_exact('TASK: Task 1 (debug)> ') - debugger_test_test.send('task.args["that"] = "true"\r') + debugger_test_test.send('task.args["that"] = []\r') debugger_test_test.expect_exact('TASK: Task 1 (debug)> ') debugger_test_test.send('r\r') debugger_test_test.expect(pexpect.EOF) diff --git a/test/integration/targets/failed_when/tasks/main.yml b/test/integration/targets/failed_when/tasks/main.yml index 1b10bef14b7..c87c7f81da8 100644 --- a/test/integration/targets/failed_when/tasks/main.yml +++ b/test/integration/targets/failed_when/tasks/main.yml @@ -78,3 +78,9 @@ - invalid_conditional is failed - invalid_conditional.stdout is defined - invalid_conditional.failed_when_result is contains('boomboomboom') + +- name: add_host failed_when (coverage exercise for strategy) + add_host: + name: some_host + groups: blah + failed_when: false diff --git a/test/integration/targets/gathering_facts/verify_subset.yml b/test/integration/targets/gathering_facts/verify_subset.yml index 89132756ea7..efe57a5b57f 100644 --- a/test/integration/targets/gathering_facts/verify_subset.yml +++ b/test/integration/targets/gathering_facts/verify_subset.yml @@ -10,4 +10,4 @@ assert: that: - bad_sub is failed - - "'MODULE FAILURE' not in bad_sub['msg']" + - bad_sub.msg is match "Bad subset 'nonsense' given to Ansible" diff --git a/test/integration/targets/hash/test_inventory_hash.yml b/test/integration/targets/hash/test_inventory_hash.yml index 1091b135025..10e99dd3d48 100644 --- a/test/integration/targets/hash/test_inventory_hash.yml +++ b/test/integration/targets/hash/test_inventory_hash.yml @@ -10,7 +10,7 @@ - name: debug hash behaviour result debug: - var: "{{ lookup('env', 'ANSIBLE_HASH_BEHAVIOUR') }}" + var: lookup('env', 'ANSIBLE_HASH_BEHAVIOUR') verbosity: 2 - name: assert hash behaviour is merge or replace diff --git a/test/integration/targets/hostname/tasks/test_check_mode.yml b/test/integration/targets/hostname/tasks/test_check_mode.yml index 9ba1d65c720..369bca31395 100644 --- a/test/integration/targets/hostname/tasks/test_check_mode.yml +++ b/test/integration/targets/hostname/tasks/test_check_mode.yml @@ -14,7 +14,7 @@ - hn1 is changed - original.stdout == after_hn.stdout -- when: _hostname_file is defined and _hostname_file +- when: _hostname_file is defined and _hostname_file is not none block: - name: See if current hostname file exists stat: diff --git a/test/integration/targets/lookup_vars/tasks/main.yml b/test/integration/targets/lookup_vars/tasks/main.yml index 57b05b8f232..be3142e6137 100644 --- a/test/integration/targets/lookup_vars/tasks/main.yml +++ b/test/integration/targets/lookup_vars/tasks/main.yml @@ -17,8 +17,7 @@ - block: - name: EXPECTED FAILURE - test invalid var - debug: - var: '{{ lookup("vars", "doesnotexist") }}' + raw: '{{ lookup("vars", "doesnotexist") }}' - fail: msg: "should not get here" diff --git a/test/integration/targets/prepare_http_tests/tasks/kerberos.yml b/test/integration/targets/prepare_http_tests/tasks/kerberos.yml index 80ab72815e4..8256d8fddf3 100644 --- a/test/integration/targets/prepare_http_tests/tasks/kerberos.yml +++ b/test/integration/targets/prepare_http_tests/tasks/kerberos.yml @@ -26,7 +26,7 @@ copy: src: openssl_legacy.cnf dest: '{{ krb5_openssl_conf }}' - when: krb5_openssl_conf | default(False, True) + when: krb5_openssl_conf is defined and krb5_openssl_conf is truthy - name: Include distribution specific variables include_vars: '{{ lookup("first_found", params) }}' diff --git a/test/integration/targets/unarchive/tasks/test_mode.yml b/test/integration/targets/unarchive/tasks/test_mode.yml index e4cd601f934..815cfa4d893 100644 --- a/test/integration/targets/unarchive/tasks/test_mode.yml +++ b/test/integration/targets/unarchive/tasks/test_mode.yml @@ -47,7 +47,7 @@ - "unarchive06_stat.stat.mode == '0600'" # Verify that file list is generated - "'files' in unarchive06" - - "{{unarchive06['files']| length}} == 1" + - unarchive06['files']| length == 1 - "'foo-unarchive.txt' in unarchive06['files']" - name: remove our tar.gz unarchive destination @@ -97,7 +97,7 @@ - "unarchive07.changed == false" # Verify that file list is generated - "'files' in unarchive07" - - "{{unarchive07['files']| length}} == 1" + - unarchive07['files']| length == 1 - "'foo-unarchive.txt' in unarchive07['files']" - name: remove our tar.gz unarchive destination diff --git a/test/integration/targets/undefined/tasks/main.yml b/test/integration/targets/undefined/tasks/main.yml index 5bf478606cc..7be62dc48df 100644 --- a/test/integration/targets/undefined/tasks/main.yml +++ b/test/integration/targets/undefined/tasks/main.yml @@ -11,6 +11,5 @@ - assert: that: - - '("%r"|format(undefined_variable)).startswith("AnsibleUndefined")' - undefined_set_fact is failed - - undefined_set_fact.msg is contains 'undefined variable' + - undefined_set_fact.msg is contains "has no attribute 'name'" diff --git a/test/integration/targets/uri/tasks/main.yml b/test/integration/targets/uri/tasks/main.yml index 9c8f110e684..fdf14b80431 100644 --- a/test/integration/targets/uri/tasks/main.yml +++ b/test/integration/targets/uri/tasks/main.yml @@ -619,7 +619,7 @@ - name: assert that keys were sanitized assert: that: - - sanitize_keys.json.args['key-********'] == 'value-********' + - sanitize_keys.json.args['key-********'] == 'value-********' - name: Test gzip encoding uri: diff --git a/test/integration/targets/var_precedence/ansible-var-precedence-check.py b/test/integration/targets/var_precedence/ansible-var-precedence-check.py index e75bcdd315e..ea9ccfcde23 100755 --- a/test/integration/targets/var_precedence/ansible-var-precedence-check.py +++ b/test/integration/targets/var_precedence/ansible-var-precedence-check.py @@ -430,7 +430,7 @@ def main(): 'ini_host_vars_file', 'ini_host', 'pb_group_vars_file_child', - # 'ini_group_vars_file_child', #FIXME: this contradicts documented precedence pb group vars files should override inventory ones + # 'ini_group_vars_file_child', # FIXME: this contradicts documented precedence pb group vars files should override inventory ones 'pb_group_vars_file_parent', 'ini_group_vars_file_parent', 'pb_group_vars_file_all', diff --git a/test/integration/targets/win_fetch/tasks/main.yml b/test/integration/targets/win_fetch/tasks/main.yml index 16a287618ee..0da7477d93f 100644 --- a/test/integration/targets/win_fetch/tasks/main.yml +++ b/test/integration/targets/win_fetch/tasks/main.yml @@ -149,7 +149,7 @@ assert: that: - "fetch_missing_nofail is not failed" - - "fetch_missing_nofail.msg" + - "fetch_missing_nofail.msg | length > 0" - "fetch_missing_nofail is not changed" - name: attempt to fetch a non-existent file - fail on missing @@ -161,7 +161,7 @@ assert: that: - "fetch_missing is failed" - - "fetch_missing.msg" + - "fetch_missing.msg | length > 0" - "fetch_missing is not changed" - name: attempt to fetch a non-existent file - fail on missing implicit @@ -173,7 +173,7 @@ assert: that: - "fetch_missing_implicit is failed" - - "fetch_missing_implicit.msg" + - "fetch_missing_implicit.msg | length > 0" - "fetch_missing_implicit is not changed" - name: create empty temp directory @@ -191,7 +191,7 @@ that: # Doesn't fail anymore, only returns a message. - "fetch_dir is not changed" - - "fetch_dir.msg" + - "fetch_dir.msg | length > 0" - name: create file with special characters raw: Set-Content -LiteralPath '{{ remote_tmp_dir }}\abc$not var''quote‘‘' -Value 'abc' diff --git a/test/integration/targets/win_raw/tasks/main.yml b/test/integration/targets/win_raw/tasks/main.yml index a4e93f25e49..4232182b06b 100644 --- a/test/integration/targets/win_raw/tasks/main.yml +++ b/test/integration/targets/win_raw/tasks/main.yml @@ -24,7 +24,7 @@ assert: that: - "getmac_result.rc == 0" - - "getmac_result.stdout" + - "getmac_result.stdout | length > 0" - (ansible_connection == 'ssh') | ternary(getmac_result.stderr is defined, not getmac_result.stderr) - "getmac_result is not failed" - "getmac_result is changed" @@ -37,7 +37,6 @@ assert: that: - "ipconfig_result.rc == 0" - - "ipconfig_result.stdout" - "'Physical Address' in ipconfig_result.stdout" - (ansible_connection == 'ssh') | ternary(ipconfig_result.stderr is defined, not ipconfig_result.stderr) - "ipconfig_result is not failed" @@ -52,7 +51,7 @@ assert: that: - "ipconfig_invalid_result.rc != 0" - - "ipconfig_invalid_result.stdout" # ipconfig displays errors on stdout. + - "ipconfig_invalid_result.stdout | length > 0" # ipconfig displays errors on stdout. # - "not ipconfig_invalid_result.stderr" - "ipconfig_invalid_result is failed" - "ipconfig_invalid_result is changed" @@ -67,7 +66,7 @@ that: - "unknown_result.rc != 0" - "not unknown_result.stdout" - - "unknown_result.stderr" # An unknown command displays error on stderr. + - "unknown_result.stderr | length > 0" # An unknown command displays error on stderr. - "unknown_result is failed" - "unknown_result is changed" diff --git a/test/integration/targets/win_script/tasks/main.yml b/test/integration/targets/win_script/tasks/main.yml index d1082e72e8e..3aaa1f85a6c 100644 --- a/test/integration/targets/win_script/tasks/main.yml +++ b/test/integration/targets/win_script/tasks/main.yml @@ -36,7 +36,6 @@ assert: that: - "test_script_result.rc == 0" - - "test_script_result.stdout" - "'Woohoo' in test_script_result.stdout" - (ansible_connection == 'ssh') | ternary(test_script_result.stderr is defined, not test_script_result.stderr) - "test_script_result is not failed" @@ -50,7 +49,7 @@ assert: that: - "test_script_with_args_result.rc == 0" - - "test_script_with_args_result.stdout" + - "test_script_with_args_result.stdout | length > 0" - "test_script_with_args_result.stdout_lines[0] == '/this'" - "test_script_with_args_result.stdout_lines[1] == '/that'" - "test_script_with_args_result.stdout_lines[2] == '/Ӧther'" @@ -95,7 +94,7 @@ assert: that: - "test_script_with_splatting_result.rc == 0" - - "test_script_with_splatting_result.stdout" + - "test_script_with_splatting_result.stdout | length > 0" - "test_script_with_splatting_result.stdout_lines[0] == 'this'" - "test_script_with_splatting_result.stdout_lines[1] == test_win_script_value" - "test_script_with_splatting_result.stdout_lines[2] == 'other'" @@ -111,7 +110,7 @@ assert: that: - "test_script_with_splatting2_result.rc == 0" - - "test_script_with_splatting2_result.stdout" + - "test_script_with_splatting2_result.stdout | length > 0" - "test_script_with_splatting2_result.stdout_lines[0] == 'THIS'" - "test_script_with_splatting2_result.stdout_lines[1] == 'THAT'" - "test_script_with_splatting2_result.stdout_lines[2] == 'OTHER'" @@ -129,7 +128,7 @@ that: - "test_script_with_errors_result.rc != 0" - "not test_script_with_errors_result.stdout" - - "test_script_with_errors_result.stderr" + - "test_script_with_errors_result.stderr | length > 0" - "test_script_with_errors_result is failed" - "test_script_with_errors_result is changed" @@ -203,7 +202,6 @@ assert: that: - "test_batch_result.rc == 0" - - "test_batch_result.stdout" - "'batch' in test_batch_result.stdout" - (ansible_connection == 'ssh') | ternary(test_batch_result.stderr is defined, not test_batch_result.stderr) - "test_batch_result is not failed" @@ -217,7 +215,6 @@ assert: that: - "test_cmd_result.rc == 0" - - "test_cmd_result.stdout" - "'cmd extension' in test_cmd_result.stdout" - (ansible_connection == 'ssh') | ternary(test_cmd_result.stderr is defined, not test_cmd_result.stderr) - "test_cmd_result is not failed" @@ -232,8 +229,8 @@ assert: that: - test_batch_result.rc == 1 - - test_batch_result.stdout - - test_batch_result.stderr + - test_batch_result.stdout | length > 0 + - test_batch_result.stderr | length > 0 - test_batch_result is failed - test_batch_result is changed when: not ansible_distribution_version.startswith('6.0')