Fix sanity tests based on newer version of shellcheck (#60423)
- change egrep to grep -E - store exit codes and check them directly - ignore SC1091
This commit is contained in:
parent
697b566971
commit
c485a1b91e
8 changed files with 27 additions and 24 deletions
|
@ -12,7 +12,7 @@ ansible-playbook -vv main.yml -i ../../inventory | tee block_test.out
|
|||
env python -c \
|
||||
'import sys, re; sys.stdout.write(re.sub("\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]", "", sys.stdin.read()))' \
|
||||
<block_test.out >block_test_wo_colors.out
|
||||
[ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(egrep '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ]
|
||||
[ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(grep -E '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ]
|
||||
# cleanup the output log again, to make sure the test is clean
|
||||
rm -f block_test.out block_test_wo_colors.out
|
||||
# run test with free strategy and again count the completions
|
||||
|
@ -20,7 +20,7 @@ ansible-playbook -vv main.yml -i ../../inventory -e test_strategy=free | tee blo
|
|||
env python -c \
|
||||
'import sys, re; sys.stdout.write(re.sub("\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]", "", sys.stdin.read()))' \
|
||||
<block_test.out >block_test_wo_colors.out
|
||||
[ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(egrep '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ]
|
||||
[ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(grep -E '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ]
|
||||
# cleanup the output log again, to make sure the test is clean
|
||||
rm -f block_test.out block_test_wo_colors.out
|
||||
# run test with host_pinned strategy and again count the completions
|
||||
|
@ -28,7 +28,7 @@ ansible-playbook -vv main.yml -i ../../inventory -e test_strategy=host_pinned |
|
|||
env python -c \
|
||||
'import sys, re; sys.stdout.write(re.sub("\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]", "", sys.stdin.read()))' \
|
||||
<block_test.out >block_test_wo_colors.out
|
||||
[ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(egrep '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ]
|
||||
[ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(grep -E '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ]
|
||||
|
||||
# run test that includes tasks that fail inside a block with always
|
||||
rm -f block_test.out block_test_wo_colors.out
|
||||
|
@ -36,4 +36,4 @@ ansible-playbook -vv block_fail.yml -i ../../inventory | tee block_test.out
|
|||
env python -c \
|
||||
'import sys, re; sys.stdout.write(re.sub("\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]", "", sys.stdin.read()))' \
|
||||
<block_test.out >block_test_wo_colors.out
|
||||
[ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(egrep '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ]
|
||||
[ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(grep -E '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ]
|
||||
|
|
|
@ -16,5 +16,5 @@ DISTRO="$*"
|
|||
if [[ "$DISTRO" == "MacOSX" ]]; then
|
||||
dscl localhost -list /Local/Default/Groups
|
||||
else
|
||||
egrep -v ^\# /etc/group | cut -d: -f1
|
||||
grep -E -v ^\# /etc/group | cut -d: -f1
|
||||
fi
|
||||
|
|
|
@ -15,44 +15,44 @@ ansible-playbook from_handlers.yml -i inventory.handlers -v "$@" --tags scenario
|
|||
ansible-playbook test_listening_handlers.yml -i inventory.handlers -v "$@"
|
||||
|
||||
[ "$(ansible-playbook test_handlers.yml -i inventory.handlers -v "$@" --tags scenario2 -l A \
|
||||
| egrep -o 'RUNNING HANDLER \[test_handlers : .*?]')" = "RUNNING HANDLER [test_handlers : test handler]" ]
|
||||
| grep -E -o 'RUNNING HANDLER \[test_handlers : .*?]')" = "RUNNING HANDLER [test_handlers : test handler]" ]
|
||||
|
||||
# Not forcing, should only run on successful host
|
||||
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal \
|
||||
| egrep -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ]
|
||||
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ]
|
||||
|
||||
# Forcing from command line
|
||||
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal --force-handlers \
|
||||
| egrep -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
|
||||
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
|
||||
|
||||
# Forcing from command line, should only run later tasks on unfailed hosts
|
||||
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal --force-handlers \
|
||||
| egrep -o CALLED_TASK_. | sort | uniq | xargs)" = "CALLED_TASK_B CALLED_TASK_D CALLED_TASK_E" ]
|
||||
| grep -E -o CALLED_TASK_. | sort | uniq | xargs)" = "CALLED_TASK_B CALLED_TASK_D CALLED_TASK_E" ]
|
||||
|
||||
# Forcing from command line, should call handlers even if all hosts fail
|
||||
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal --force-handlers -e fail_all=yes \
|
||||
| egrep -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
|
||||
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
|
||||
|
||||
# Forcing from ansible.cfg
|
||||
[ "$(ANSIBLE_FORCE_HANDLERS=true ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal \
|
||||
| egrep -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
|
||||
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
|
||||
|
||||
# Forcing true in play
|
||||
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags force_true_in_play \
|
||||
| egrep -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
|
||||
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
|
||||
|
||||
# Forcing false in play, which overrides command line
|
||||
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags force_false_in_play --force-handlers \
|
||||
| egrep -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ]
|
||||
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ]
|
||||
|
||||
[ "$(ansible-playbook test_handlers_include.yml -i ../../inventory -v "$@" --tags playbook_include_handlers \
|
||||
| egrep -o 'RUNNING HANDLER \[.*?]')" = "RUNNING HANDLER [test handler]" ]
|
||||
| grep -E -o 'RUNNING HANDLER \[.*?]')" = "RUNNING HANDLER [test handler]" ]
|
||||
|
||||
[ "$(ansible-playbook test_handlers_include.yml -i ../../inventory -v "$@" --tags role_include_handlers \
|
||||
| egrep -o 'RUNNING HANDLER \[test_handlers_include : .*?]')" = "RUNNING HANDLER [test_handlers_include : test handler]" ]
|
||||
| grep -E -o 'RUNNING HANDLER \[test_handlers_include : .*?]')" = "RUNNING HANDLER [test_handlers_include : test handler]" ]
|
||||
|
||||
[ "$(ansible-playbook test_handlers_include_role.yml -i ../../inventory -v "$@" \
|
||||
| egrep -o 'RUNNING HANDLER \[test_handlers_include_role : .*?]')" = "RUNNING HANDLER [test_handlers_include_role : test handler]" ]
|
||||
| grep -E -o 'RUNNING HANDLER \[test_handlers_include_role : .*?]')" = "RUNNING HANDLER [test_handlers_include_role : test handler]" ]
|
||||
|
||||
# Notify handler listen
|
||||
ansible-playbook test_handlers_listen.yml -i inventory.handlers -v "$@"
|
||||
|
@ -76,7 +76,7 @@ set -e
|
|||
[ ! -f $output_dir/should_not_exist_B ] || (rm -f $output_dir/should_not_exist_B && exit 1)
|
||||
|
||||
# https://github.com/ansible/ansible/issues/47287
|
||||
[ "$(ansible-playbook test_handlers_including_task.yml -i ../../inventory -v "$@" | egrep -o 'failed=[0-9]+')" = "failed=0" ]
|
||||
[ "$(ansible-playbook test_handlers_including_task.yml -i ../../inventory -v "$@" | grep -E -o 'failed=[0-9]+')" = "failed=0" ]
|
||||
|
||||
# https://github.com/ansible/ansible/issues/27237
|
||||
set +e
|
||||
|
|
|
@ -93,11 +93,11 @@ ANSIBLE_HOST_PATTERN_MISMATCH=warning ansible-playbook run_once/playbook.yml "$@
|
|||
|
||||
# https://github.com/ansible/ansible/issues/48936
|
||||
ansible-playbook -v handler_addressing/playbook.yml 2>&1 | tee test_handler_addressing.out
|
||||
test "$(egrep -c 'include handler task|ERROR! The requested handler '"'"'do_import'"'"' was not found' test_handler_addressing.out)" = 2
|
||||
test "$(grep -E -c 'include handler task|ERROR! The requested handler '"'"'do_import'"'"' was not found' test_handler_addressing.out)" = 2
|
||||
|
||||
# https://github.com/ansible/ansible/issues/49969
|
||||
ansible-playbook -v parent_templating/playbook.yml 2>&1 | tee test_parent_templating.out
|
||||
test "$(egrep -c 'Templating the path of the parent include_tasks failed.' test_parent_templating.out)" = 0
|
||||
test "$(grep -E -c 'Templating the path of the parent include_tasks failed.' test_parent_templating.out)" = 0
|
||||
|
||||
# https://github.com/ansible/ansible/issues/54618
|
||||
ansible-playbook test_loop_var_bleed.yaml "$@"
|
||||
|
|
|
@ -63,7 +63,8 @@ ansible-inventory -i ${VMWARE_CONFIG} --list --yaml
|
|||
|
||||
# Install TOML for --toml
|
||||
${PYTHON} -m pip freeze | grep toml > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
TOML_TEST_RESULT=$?
|
||||
if [ $TOML_TEST_RESULT -ne 0 ]; then
|
||||
echo "Installing TOML package"
|
||||
${PYTHON} -m pip install toml
|
||||
else
|
||||
|
@ -72,7 +73,8 @@ fi
|
|||
|
||||
# Get inventory using TOML
|
||||
ansible-inventory -i ${VMWARE_CONFIG} --list --toml
|
||||
if [ $? -ne 0 ]; then
|
||||
TOML_INVENTORY_LIST_RESULT=$?
|
||||
if [ $TOML_INVENTORY_LIST_RESULT -ne 0 ]; then
|
||||
echo "Inventory plugin failed to list inventory host using --toml, please debug"
|
||||
exit 1
|
||||
fi
|
||||
|
|
|
@ -35,12 +35,12 @@ function pass_tests {
|
|||
fi
|
||||
|
||||
# test for https://github.com/ansible/ansible/issues/13681
|
||||
if egrep '127\.0\.0\.1.*ok' "${temp_log}"; then
|
||||
if grep -E '127\.0\.0\.1.*ok' "${temp_log}"; then
|
||||
echo "Found host 127.0.0.1 in output. Only localhost should be present."
|
||||
exit 1
|
||||
fi
|
||||
# make sure one host was run
|
||||
if ! egrep 'localhost.*ok' "${temp_log}"; then
|
||||
if ! grep -E 'localhost.*ok' "${temp_log}"; then
|
||||
echo "Did not find host localhost in output."
|
||||
exit 1
|
||||
fi
|
||||
|
|
|
@ -16,5 +16,5 @@ DISTRO="$*"
|
|||
if [[ "$DISTRO" == "MacOSX" ]]; then
|
||||
dscl localhost -list /Local/Default/Users
|
||||
else
|
||||
egrep -v ^\# /etc/passwd | cut -d: -f1
|
||||
grep -E -v ^\# /etc/passwd | cut -d: -f1
|
||||
fi
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
SC1090
|
||||
SC1091
|
||||
SC2164
|
||||
|
|
Loading…
Reference in a new issue