Add test to ordered integration tests to exercise shuffle code path (#53138)

This is meant to exercise the code path not test for randomness, though it somewhat does that.
This commit is contained in:
Sam Doran 2019-03-11 10:14:06 -04:00 committed by GitHub
parent dbcfb3d0fe
commit a4b2ce5e13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 10 deletions

View file

@ -3,7 +3,7 @@
gather_facts: false gather_facts: false
order: '{{ myorder | default("inventory") }}' order: '{{ myorder | default("inventory") }}'
tasks: tasks:
- shell: echo '{{inventory_hostname}}' >> hostlist.txt - shell: "echo '{{ inventory_hostname }}' >> hostlist.txt"
- name: with serial - name: with serial
hosts: all hosts: all
@ -11,7 +11,7 @@
serial: 1 serial: 1
order: '{{ myorder | default("inventory")}}' order: '{{ myorder | default("inventory")}}'
tasks: tasks:
- shell: echo '{{inventory_hostname}}' >> shostlist.txt - shell: "echo '{{ inventory_hostname }}' >> shostlist.txt"
- name: ensure everything works - name: ensure everything works
hosts: localhost hosts: localhost
@ -25,3 +25,15 @@
vars: vars:
hostlist: '{{ lookup("file", "hostlist.txt").splitlines() }}' hostlist: '{{ lookup("file", "hostlist.txt").splitlines() }}'
shostlist: '{{ lookup("file", "shostlist.txt").splitlines() }}' shostlist: '{{ lookup("file", "shostlist.txt").splitlines() }}'
when: myorder | default('inventory') != 'shuffle'
- name: Assert that shuffle worked
assert:
that:
- item.1 != hostlist[item.0] or item.1 in hostlist
- item.1 != hostlist[item.0] or item.1 in hostlist
loop: '{{ lookup("indexed_items", inputlist) }}'
vars:
hostlist: '{{ lookup("file", "hostlist.txt").splitlines() }}'
shostlist: '{{ lookup("file", "shostlist.txt").splitlines() }}'
when: myorder | default('inventory') == 'shuffle'

View file

@ -2,12 +2,23 @@
set -eux set -eux
cleanup () {
files="shostlist.txt hostlist.txt"
for file in $files; do
if [[ -f "$file" ]]; then
rm -f "$file"
fi
done
}
for EXTRA in '{"inputlist": ["hostB", "hostA", "hostD", "hostC"]}' \ for EXTRA in '{"inputlist": ["hostB", "hostA", "hostD", "hostC"]}' \
'{"myorder": "inventory", "inputlist": ["hostB", "hostA", "hostD", "hostC"]}' \ '{"myorder": "inventory", "inputlist": ["hostB", "hostA", "hostD", "hostC"]}' \
'{"myorder": "sorted", "inputlist": ["hostA", "hostB", "hostC", "hostD"]}' \ '{"myorder": "sorted", "inputlist": ["hostA", "hostB", "hostC", "hostD"]}' \
'{"myorder": "reverse_sorted", "inputlist": ["hostD", "hostC", "hostB", "hostA"]}' \ '{"myorder": "reverse_sorted", "inputlist": ["hostD", "hostC", "hostB", "hostA"]}' \
'{"myorder": "reverse_inventory", "inputlist": ["hostC", "hostD", "hostA", "hostB"]}' '{"myorder": "reverse_inventory", "inputlist": ["hostC", "hostD", "hostA", "hostB"]}' \
'{"myorder": "shuffle", "inputlist": ["hostC", "hostD", "hostA", "hostB"]}'
do do
rm shostlist.txt hostlist.txt || true cleanup
ansible-playbook order.yml --forks 1 -i inventory -e "$EXTRA" "$@" ansible-playbook order.yml --forks 1 -i inventory -e "$EXTRA" "$@" || cleanup
done done
cleanup