Skip to content

Commit 64cf03f

Browse files
committed
tests scripts synced with primogen v14.
1 parent 1db4619 commit 64cf03f

File tree

6 files changed

+226
-14
lines changed

6 files changed

+226
-14
lines changed

tests/ansible.cfg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
[defaults]
2+
ansible_managed = Ansible managed file, do not edit directly
23
callback_plugins = plugins/callback
34

45
host_key_checking = False
56

67
private_key_file = ~/.vagrant.d/insecure_private_key
78

8-
roles_path = ../../:../
9+
roles_path = ../../:../:dependencies
10+

tests/setup.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
# #################
3+
#
4+
# Bash script to setup the test environment.
5+
#
6+
# version: 1.0
7+
#
8+
# usage:
9+
#
10+
# setup.sh
11+
#
12+
# example:
13+
#
14+
# bash setup.sh
15+
#
16+
# changelog:
17+
#
18+
# v1.0 : 10 June 2016
19+
# - initial version
20+
#
21+
# author(s):
22+
# - Pedro Salgado <[email protected]>
23+
#
24+
# #################
25+
26+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
27+
28+
test -s ${DIR}/../requirements.yml \
29+
&& ansible-galaxy install \
30+
--force \
31+
-r ${DIR}/../requirements.yml \
32+
--roles-path=${DIR}/dependencies \
33+
|| true

tests/test_checkmode.sh

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env bash
2+
# #################
3+
#
4+
# Bash script to run check mode tests.
5+
#
6+
# version: 1.5
7+
#
8+
# usage:
9+
#
10+
# test_checkmode [options]
11+
#
12+
# options:
13+
#
14+
# --box The name of the Vagrant box or host name
15+
# --env The name of the test environment
16+
# --inventory The Ansible inventory in the form of a file or string "host,"
17+
# --playbook The path to the Ansible test playbook
18+
#
19+
# example:
20+
#
21+
# # on localhost
22+
# bash test_checkmode.sh
23+
#
24+
# # on a Vagrant box
25+
# bash test_checkmode.sh \
26+
# --box precise64.vagrant.dev \
27+
# --inventory .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
28+
#
29+
#
30+
# changelog:
31+
#
32+
# v1.5 : 8 Mar 2016
33+
# - pass vagrant_box variable to playbook
34+
# - default inventory changed from localhost to match what Vagrant provisioner generates
35+
# v1.4 : 10 Jul 2015
36+
# - added extra variables to force running idempotence tests on vagrant
37+
# v1.2
38+
# - added env option
39+
#
40+
# author(s):
41+
# - Pedro Salgado <[email protected]>
42+
#
43+
# #################
44+
45+
46+
# GREEN : SGR code to set text color (foreground) to green.
47+
GREEN='\033[0;32m'
48+
# RED : SGR code to set text color (foreground) to red.
49+
RED='\033[0;31m'
50+
# SGR code to set text color (foreground) to no color.
51+
NC='\033[0m'
52+
# The idempotence pass criteria.
53+
PASS_CRITERIA="changed=0.* unreachable=0.* failed=0"
54+
55+
# the name of the virtualenv
56+
VIRTUALENV_NAME=$(which python | awk -F / 'NF && NF-2 { print ( $(NF-2) ) }')
57+
58+
59+
while [[ $# > 1 ]]
60+
do
61+
key="$1"
62+
63+
case $key in
64+
65+
--box)
66+
# the name of the Vagrant box or host name
67+
BOX="$2"
68+
shift;;
69+
70+
--env)
71+
# the test environment
72+
ENV="$2"
73+
shift;;
74+
75+
--inventory)
76+
# the Ansible inventory in the form of a file or string "host,"
77+
INVENTORY="$2"
78+
shift;;
79+
80+
--playbook)
81+
# the path to the Ansible test playbook
82+
PLAYBOOK="$2"
83+
shift;;
84+
85+
*)
86+
# unknown option
87+
;;
88+
89+
esac
90+
shift
91+
done
92+
93+
# the name of the Vagrant box or host name
94+
BOX=${BOX:-localhost}
95+
# the Ansible inventory
96+
INVENTORY=${INVENTORY:-'.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory'}
97+
# the path to the Ansible test playbook
98+
PLAYBOOK=${PLAYBOOK:-test.yml}
99+
# the logfile to hold the output of the playbook run
100+
LOGFILE="log/${BOX}_checkmode_${VIRTUALENV_NAME}.log"
101+
102+
EXTRA_ARGS=''
103+
if [ $BOX == "localhost" ]; then
104+
INVENTORY='localhost,'
105+
EXTRA_ARGS="--connection=local -e env=${ENV} -e vagrant_box=localhost --skip-tags=test"
106+
else
107+
EXTRA_ARGS="--user vagrant -e env=vagrant -e vagrant_box=${BOX} --skip-tags=test"
108+
fi
109+
110+
echo "[INFO] ${BOX} ${VIRTUALENV_NAME} running checkmode test..."
111+
ansible-playbook -vvvv --check --diff -i ${INVENTORY} --limit ${BOX}, ${EXTRA_ARGS} ${PLAYBOOK} 2>&1 | \
112+
tee ${LOGFILE} | \
113+
grep "${BOX}" | grep -q "${PASS_CRITERIA}" && \
114+
echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} checkmode : ${GREEN}PASS${NC}\n" || ( \
115+
cat ${LOGFILE} &&
116+
echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} checkmode : ${RED}FAILED${NC} ${PASS_CRITERIA}\n" && \
117+
exit 1)
118+

tests/test_idempotence.sh

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Bash script to run idempotence tests.
55
#
6-
# version: 1.4
6+
# version: 1.5
77
#
88
# usage:
99
#
@@ -23,12 +23,15 @@
2323
#
2424
# # on a Vagrant box
2525
# bash test_idempotence.sh \
26-
# --box precise64.vagrant.dev
26+
# --box precise64.vagrant.dev \
2727
# --inventory .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
2828
#
2929
#
3030
# changelog:
3131
#
32+
# v1.5 : 8 Mar 2016
33+
# - pass vagrant_box variable to playbook
34+
# - default inventory changed from localhost to match what Vagrant provisioner generates
3235
# v1.4 : 10 Jul 2015
3336
# - added extra variables to force running idempotence tests on vagrant
3437
# v1.2
@@ -47,7 +50,7 @@ RED='\033[0;31m'
4750
# SGR code to set text color (foreground) to no color.
4851
NC='\033[0m'
4952
# The idempotence pass criteria.
50-
PASS_CRITERIA="changed=0.*unreachable=0.*failed=0"
53+
PASS_CRITERIA="changed=0.* unreachable=0.* failed=0"
5154

5255
# the name of the virtualenv
5356
VIRTUALENV_NAME=$(which python | awk -F / 'NF && NF-2 { print ( $(NF-2) ) }')
@@ -89,22 +92,28 @@ done
8992

9093
# the name of the Vagrant box or host name
9194
BOX=${BOX:-localhost}
92-
# the Ansible inventory in the form of a file or string "host,"
93-
INVENTORY=${INVENTORY:-'localhost,'}
95+
# the Ansible inventory
96+
INVENTORY=${INVENTORY:-'.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory'}
9497
# the path to the Ansible test playbook
9598
PLAYBOOK=${PLAYBOOK:-test.yml}
9699
# the logfile to hold the output of the playbook run
97-
LOGFILE="log/${BOX}_${VIRTUALENV_NAME}.log"
100+
LOGFILE="log/${BOX}_idempotence_${VIRTUALENV_NAME}.log"
98101

99102
EXTRA_ARGS=''
100103
if [ $BOX == "localhost" ]; then
101-
EXTRA_ARGS="--connection=local --extra-vars idempotence=yes --extra-vars env=${ENV}"
104+
INVENTORY='localhost,'
105+
EXTRA_ARGS="--connection=local -e env=${ENV} -e vagrant_box=localhost"
102106
else
103-
EXTRA_ARGS="--u vagrant --extra-vars idempotence=yes --extra-vars env=vagrant"
107+
EXTRA_ARGS="--user vagrant -e env=vagrant -e vagrant_box=${BOX}"
104108
fi
105109

106110
echo "[INFO] ${BOX} ${VIRTUALENV_NAME} running idempotence test..."
107-
ansible-playbook -i ${INVENTORY} --limit ${BOX}, ${EXTRA_ARGS} ${PLAYBOOK} 2>&1 | tee ${LOGFILE} | \
111+
IDEMPOTENCE='yes' \
112+
ansible-playbook -vvvv -i ${INVENTORY} --limit ${BOX}, ${EXTRA_ARGS} ${PLAYBOOK} 2>&1 | \
113+
tee ${LOGFILE} | \
108114
grep "${BOX}" | grep -q "${PASS_CRITERIA}" && \
109-
echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${GREEN}PASS${NC}\n" || \
110-
(echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${RED}FAILED${NC} ${PASS_CRITERIA}\n" && cat ${LOGFILE} && exit 1)
115+
echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${GREEN}PASS${NC}\n" || ( \
116+
cat ${LOGFILE} &&
117+
echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${RED}FAILED${NC} ${PASS_CRITERIA}\n" && \
118+
exit 1)
119+

tests/travis.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
# #################
3+
#
4+
# Bash script to run tests in the travis-ci environment.
5+
#
6+
# version: 1.0
7+
#
8+
# usage:
9+
#
10+
# travis.sh
11+
#
12+
# example:
13+
#
14+
# bash travis.sh
15+
#
16+
# changelog:
17+
#
18+
# v1.0 : 10 June 2016
19+
# - initial version
20+
#
21+
# author(s):
22+
# - Pedro Salgado <[email protected]>
23+
#
24+
# #################
25+
26+
test $USER != 'travis' && exit 0
27+
28+
set -e
29+
30+
ansible-playbook \
31+
-i localhost, \
32+
--connection=local test.yml \
33+
-e vagrant_box=localhost \
34+
-e env=travis \
35+
--skip-tags=test \
36+
$@ \
37+
&& bash test_checkmode.sh \
38+
--env travis \
39+
&& bash test_idempotence.sh \
40+
--env travis
41+

tests/vagrant.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Bash script to run the test suite against the Vagrant environment.
55
#
6-
# version: 1.2
6+
# version: 1.8
77
#
88
# usage:
99
#
@@ -16,6 +16,12 @@
1616
#
1717
# changelog:
1818
#
19+
# v1.8 : 10 August 2016
20+
# - force provisioning
21+
#
22+
# v1.6 : 10 Jun 2016
23+
# - exit if USER environment variable is travis
24+
#
1925
# v1.4 : 10 Jul 2015
2026
# - remove environment variable ANSIBLE_ASK_SUDO_PASS
2127
#
@@ -24,6 +30,8 @@
2430
#
2531
# #################
2632

33+
test $USER == 'travis' && exit 0
34+
2735
DIR="$(dirname "$0")"
2836

2937
cd $DIR
@@ -56,13 +64,14 @@ do
5664
if [ ! -n "${BOX+1}" ] || [ "${BOX}" = "${VAGRANT_BOX}" ]; then
5765

5866
echo "[INFO] preparing ${VAGRANT_BOX}..."
59-
vagrant up ${VAGRANT_BOX} 2> /dev/null
67+
vagrant up --provision ${VAGRANT_BOX} 2> /dev/null
6068
if [ $? -ne 0 ]; then
6169
# box not enabled
6270
continue
6371
fi
6472

6573
bash ${DIR}/test_idempotence.sh --box ${VAGRANT_BOX} --inventory $INVENTORY
74+
bash ${DIR}/test_checkmode.sh --box ${VAGRANT_BOX} --inventory $INVENTORY
6675

6776
echo "[INFO] destroy ${VAGRANT_BOX}..."
6877
vagrant destroy -f ${VAGRANT_BOX}

0 commit comments

Comments
 (0)