Skip to content

Commit

Permalink
Merge pull request #41 from T-Systems-MMS/localtest
Browse files Browse the repository at this point in the history
make local testing without ansible-test work
  • Loading branch information
rndmh3ro authored Sep 2, 2020
2 parents db5342b + 1abcdb9 commit 64f5109
Show file tree
Hide file tree
Showing 27 changed files with 44 additions and 43 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ Local Testing

```
# run icinga in a container and forward port 80
> docker run -it -p 80:80 jordan/icinga2
> docker run -d -p 80:80 jordan/icinga2
# run the ansible-playbook against the container
> ansible-playbook tests/integration/test.yml -e icinga_url=http://127.0.0.1/icingaweb2
# run the ansible playbooks against the container
> ansible-playbook tests/integration/targets/icinga/normalmode.yml
> ansible-playbook tests/integration/targets/icinga/checkmode.yml
```

License
Expand Down
30 changes: 15 additions & 15 deletions hacking/update_examples_and_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ for module in ../plugins/modules/*.py; do
sed -n '/EXAMPLES/,/"""/{/EXAMPLES/b;/"""/b;p}' "${module}" | tee -a "../examples/${module_name}.yml"

# create tests
echo "---" | tee "../tests/integration/targets/icinga/tasks/${module_name}.yml"
sed -n '/EXAMPLES/,/"""/{/EXAMPLES/b;/"""/b;p}' "${module}" | tee -a "../tests/integration/targets/icinga/tasks/${module_name}.yml"
echo "---" | tee "../tests/integration/targets/icinga/roles/icinga/tasks/${module_name}.yml"
sed -n '/EXAMPLES/,/"""/{/EXAMPLES/b;/"""/b;p}' "${module}" | tee -a "../tests/integration/targets/icinga/roles/icinga/tasks/${module_name}.yml"

# create create working tests deleting the hosts
echo "---" | tee "../tests/integration/targets/icinga/tasks/absent_${module_name}.yml"
sed -n '/EXAMPLES/,/"""/{/EXAMPLES/b;/"""/b;p}' "${module}" | tee -a "../tests/integration/targets/icinga/tasks/absent_${module_name}.yml"
sed -i 's/state: present/state: absent/g' "../tests/integration/targets/icinga/tasks/absent_${module_name}.yml"
echo "---" | tee "../tests/integration/targets/icinga/roles/icinga/tasks/absent_${module_name}.yml"
sed -n '/EXAMPLES/,/"""/{/EXAMPLES/b;/"""/b;p}' "${module}" | tee -a "../tests/integration/targets/icinga/roles/icinga/tasks/absent_${module_name}.yml"
sed -i 's/state: present/state: absent/g' "../tests/integration/targets/icinga/roles/icinga/tasks/absent_${module_name}.yml"

# create failing tests with wrong password
echo "---" | tee "../tests/integration/targets/icinga/tasks/wrong_pass_${module_name}.yml"
sed -n '/EXAMPLES/,/"""/{/EXAMPLES/b;/"""/b;p}' "${module}" | tee -a "../tests/integration/targets/icinga/tasks/wrong_pass_${module_name}.yml"
echo "---" | tee "../tests/integration/targets/icinga/roles/icinga/tasks/wrong_pass_${module_name}.yml"
sed -n '/EXAMPLES/,/"""/{/EXAMPLES/b;/"""/b;p}' "${module}" | tee -a "../tests/integration/targets/icinga/roles/icinga/tasks/wrong_pass_${module_name}.yml"
# replace password variable with wrong password
sed -i 's/{{ icinga_pass }}/iamwrong/g' "../tests/integration/targets/icinga/tasks/wrong_pass_${module_name}.yml"
sed -i 's/{{ icinga_pass }}/iamwrong/g' "../tests/integration/targets/icinga/roles/icinga/tasks/wrong_pass_${module_name}.yml"

# add ignore_errors to the creation-task and an assert task that checks for failure
echo -n "
Expand All @@ -32,15 +32,15 @@ for module in ../plugins/modules/*.py; do
assert:
that:
- \"result.failed\"
- \"result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized'\" # noqa
" >> "../tests/integration/targets/icinga/tasks/wrong_pass_${module_name}.yml"
- \"result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'\" # noqa
" >> "../tests/integration/targets/icinga/roles/icinga/tasks/wrong_pass_${module_name}.yml"

# create failing tests with wrong host
# add test
echo "---" | tee "../tests/integration/targets/icinga/tasks/wrong_host_${module_name}.yml"
sed -n '/EXAMPLES/,/"""/{/EXAMPLES/b;/"""/b;p}' "${module}" | tee -a "../tests/integration/targets/icinga/tasks/wrong_host_${module_name}.yml"
echo "---" | tee "../tests/integration/targets/icinga/roles/icinga/tasks/wrong_host_${module_name}.yml"
sed -n '/EXAMPLES/,/"""/{/EXAMPLES/b;/"""/b;p}' "${module}" | tee -a "../tests/integration/targets/icinga/roles/icinga/tasks/wrong_host_${module_name}.yml"
# replace url varuable with nonexisting url
sed -i 's/{{ icinga_url }}/http:\/\/nonexistant/g' "../tests/integration/targets/icinga/tasks/wrong_host_${module_name}.yml"
sed -i 's/{{ icinga_url }}/http:\/\/nonexistant/g' "../tests/integration/targets/icinga/roles/icinga/tasks/wrong_host_${module_name}.yml"

# add ignore_errors to the creation-task and an assert task that checks for failure
echo -n "
Expand All @@ -51,6 +51,6 @@ for module in ../plugins/modules/*.py; do
assert:
that:
- \"result.failed\"
- \"result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>'\" # noqa
" >> "../tests/integration/targets/icinga/tasks/wrong_host_${module_name}.yml"
- \"result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'\" # noqa
" >> "../tests/integration/targets/icinga/roles/icinga/tasks/wrong_host_${module_name}.yml"
done
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
assert:
that:
- "result.failed"
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized'" # noqa
- "result.msg == 'bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>' or result.msg == 'bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>'" # noqa
Loading

0 comments on commit 64f5109

Please sign in to comment.