Skip to content

Commit ac45aaa

Browse files
author
David Farrington
committed
Implement new role based testing rig + clearer idempotence testing
1 parent 1db4efb commit ac45aaa

File tree

7 files changed

+49
-17
lines changed

7 files changed

+49
-17
lines changed

.travis.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ install:
1414
- pip install ansible==1.8.4
1515
script:
1616
- echo localhost > inventory
17-
- ansible-playbook -i inventory test.yml --syntax-check
18-
- ansible-playbook -i inventory test.yml --connection=local --sudo -e "postgresql_version=$POSTGRESQL_VERSION"
19-
- >
20-
ansible-playbook -i inventory test.yml --connection=local --sudo -e "postgresql_version=$POSTGRESQL_VERSION"
21-
| grep -q 'changed=0.*failed=0'
22-
&& (echo 'Idempotence test: pass' && exit 0)
23-
|| (echo 'Idempotence test: fail' && exit 1)
17+
18+
# Syntax check
19+
- ansible-playbook -i inventory tests/test.yml --syntax-check
20+
21+
# Play test
22+
- ansible-playbook -i inventory tests/test.yml --connection=local --sudo -e "postgresql_version=$POSTGRESQL_VERSION"
23+
24+
# Idempotence test
25+
- ansible-playbook -i inventory tests/test.yml --connection=local --sudo -e "postgresql_version=$POSTGRESQL_VERSION" > idempotence_out
26+
- ./tests/idempotence_check.sh idempotence_out

Vagrantfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Vagrant.configure('2') do |config|
77
c.vm.network :private_network, ip: '192.168.88.22'
88
c.vm.hostname = 'anxs.local'
99
c.vm.provision 'ansible' do |ansible|
10-
ansible.playbook = 'test.yml'
10+
ansible.playbook = 'tests/test.yml'
1111
ansible.sudo = true
1212
ansible.inventory_path = 'vagrant-inventory'
1313
ansible.host_key_checking = false

ansible.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[defaults]
2+
roles_path = ../

idempotence_check.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# Process the output of the given file (should contain a plays stdout/err)
4+
# If we pass, return with 0 else return with 1, and print useful output
5+
6+
_file="$1"
7+
8+
# Assert filename has been passed
9+
[ $# -eq 0 ] && { echo "Usage: $0 filename"; exit 1; }
10+
11+
# Assert file exists
12+
[ ! -f "$_file" ] && { echo "$0: $_file file not found."; exit 2; }
13+
14+
# Make sure nothing has changed or failed
15+
grep -q 'changed=0.*failed=0' $_file
16+
17+
# Success condition
18+
if [ $? -eq 0 ]; then
19+
echo 'Idempotence test: pass'
20+
exit
21+
22+
# Failure condition, extract useful information and exit
23+
else
24+
echo 'Idempotence test: fail'
25+
echo ''
26+
grep --color=auto -B1 -A1 "\(changed\|failed\):" $_file
27+
exit 1
28+
fi

test.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
3+
- hosts: all
4+
remote_user: root
5+
sudo: yes
6+
roles:
7+
- postgresql

vagrant-inventory

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[anxs]
2-
anxs.local ansible_ssh_host=192.168.88.22 ansible_ssh_port=22
2+
anxs.local ansible_ssh_host=192.168.88.22 ansible_ssh_port=22 ansible_ssh_user=vagrant

0 commit comments

Comments
 (0)