Skip to content

Commit 4236363

Browse files
committed
refactoring of test structure.
added default Vagrant boxes for several Linux distributions.
1 parent 9799781 commit 4236363

File tree

10 files changed

+304
-59
lines changed

10 files changed

+304
-59
lines changed

tests/Vagrantfile

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,36 @@
33
require 'yaml'
44

55
PLAYBOOK = 'vagrant.yml'
6+
CONFIGURATION_FILE = 'group_vars/all.yml'
67

78
Vagrant.configure('2') do |config|
89

9-
config.hostmanager.enabled = true
10-
config.hostmanager.manage_host = true
11-
config.hostmanager.ignore_private_ip = false
10+
puts "[INFO] loading box settings from #{CONFIGURATION_FILE}..."
11+
vagrant_environment = YAML.load_file(File.expand_path(CONFIGURATION_FILE, File.dirname(__FILE__)))
1212

13-
Dir.glob('host_vars/*').each do |host_var_file|
13+
vagrant_environment['vagrant'].each do |box_name, box_settings|
14+
if not box_settings['enabled']
15+
puts "[INFO] #{box_name} is not enabled. skipping..."
16+
next
17+
done
1418

15-
puts "[INFO] loading #{host_var_file} box settings..."
16-
vagrant_host_var = YAML.load_file(host_var_file)
19+
puts "[INFO] applying #{box_name} settings..."
20+
config.vm.define "#{box_name}" do |host|
1721

18-
# removed 'host_vars/' prefix and '.yml' suffix
19-
vagrant_box_name = host_var_file[10..-5]
22+
host.vm.box = box_settings['box'] unless not box_settings.key? 'box'
23+
host.vm.hostname = box_name
2024

21-
puts "[INFO] applying #{vagrant_box_name} settings..."
22-
config.vm.define "#{vagrant_box_name}" do |host|
23-
host.vm.box = vagrant_host_var['box'] unless not vagrant_host_var.key? 'box'
24-
host.vm.hostname = vagrant_host_var['name'] unless not vagrant_host_var.key? 'name'
25+
host.vm.network box_settings['network']['name'], ip: box_settings['network']['ip'] unless box_settings.key? 'network'
2526

26-
host.vm.network vagrant_host_var['network']['name'], ip: vagrant_host_var['network']['ip'] unless vagrant_host_var.key? 'network'
27-
28-
puts "[INFO] applying virtualbox provider settings for #{vagrant_box_name} box..."
29-
config.vm.provider "#{vagrant_host_var['provider']}" do | provider |
30-
vagrant_host_var['provider'].each do |key, value|
27+
puts "[INFO] applying virtualbox provider settings for #{box_name} box..."
28+
config.vm.provider "#{box_settings['provider']}" do | provider |
29+
box_settings['provider'].each do |key, value|
3130
next if key == 'name'
3231
provider.send("#{key}=", value)
3332
end
3433
end
3534

36-
puts "[INFO] provisioning #{vagrant_box_name} using ansible vagrant playbook..."
35+
puts "[INFO] provisioning #{box_name} using ansible vagrant playbook..."
3736
config.vm.provision 'ansible' do |ansible|
3837
ansible.playbook = PLAYBOOK
3938
ansible.verbose = 'v'

tests/ansible.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[defaults]
2+
host_key_checking = False
3+
24
private_key_file = ~/.vagrant.d/insecure_private_key
35

46
roles_path = ../../

tests/group_vars/all.yml

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
---
2+
# file: primogen/tests/vars/main.yml
3+
#
4+
5+
vagrant:
6+
7+
8+
# CentOS
9+
10+
centos66-64.vagrant.dev:
11+
enabled: false
12+
box: hansode/centos-6.4-x86_64
13+
network:
14+
name: private_network
15+
ip: 192.168.121.1
16+
17+
provider:
18+
name: virtualbox
19+
memory: 1024
20+
cpus: 1
21+
22+
centos66-64.vagrant.dev:
23+
enabled: false
24+
box: hansode/centos-6.6-x86_64
25+
network:
26+
name: private_network
27+
ip: 192.168.121.2
28+
29+
provider:
30+
name: virtualbox
31+
memory: 1024
32+
cpus: 1
33+
34+
centos7-64.vagrant.dev:
35+
enabled: false
36+
box: relativkreativ/centos-7-minimal
37+
network:
38+
name: private_network
39+
ip: 192.168.121.3
40+
41+
provider:
42+
name: virtualbox
43+
memory: 1024
44+
cpus: 1
45+
46+
47+
# Debian
48+
49+
jessie64.vagrant.dev:
50+
enabled: false
51+
box: debian/jessie64
52+
network:
53+
name: private_network
54+
ip: 192.168.122.1
55+
56+
provider:
57+
name: virtualbox
58+
memory: 1024
59+
cpus: 1
60+
61+
wheezy64.vagrant.dev:
62+
enabled: false
63+
box: debian/wheezy64
64+
network:
65+
name: private_network
66+
ip: 192.168.122.2
67+
68+
provider:
69+
name: virtualbox
70+
memory: 1024
71+
cpus: 1
72+
73+
precise32.vagrant.dev:
74+
enabled: false
75+
box: hansode/fedora-20-i386
76+
network:
77+
name: private_network
78+
ip: 192.168.122.3
79+
80+
provider:
81+
name: virtualbox
82+
memory: 1024
83+
cpus: 1
84+
85+
precise64.vagrant.dev:
86+
enabled: false
87+
box: ubuntu/precise64
88+
network:
89+
name: private_network
90+
ip: 192.168.122.4
91+
92+
provider:
93+
name: virtualbox
94+
memory: 1024
95+
cpus: 1
96+
97+
98+
# Fedora
99+
100+
fedora20-32.vagrant.dev:
101+
enabled: false
102+
box: hansode/fedora-20-i386
103+
network:
104+
name: private_network
105+
ip: 192.168.123.1
106+
107+
provider:
108+
name: virtualbox
109+
memory: 1024
110+
cpus: 1
111+
112+
fedora20-64.vagrant.dev:
113+
enabled: false
114+
box: hansode/fedora-20-x86_64
115+
network:
116+
name: private_network
117+
ip: 192.168.123.2
118+
119+
provider:
120+
name: virtualbox
121+
memory: 1024
122+
cpus: 1
123+
124+
fedora21-32.vagrant.dev:
125+
enabled: false
126+
box: hansode/fedora-21-i386
127+
network:
128+
name: private_network
129+
ip: 192.168.123.3
130+
131+
provider:
132+
name: virtualbox
133+
memory: 1024
134+
cpus: 1
135+
136+
fedora21-64.vagrant.dev:
137+
enabled: false
138+
box: hansode/fedora-21-x86_64
139+
network:
140+
name: private_network
141+
ip: 192.168.123.4
142+
143+
provider:
144+
name: virtualbox
145+
memory: 1024
146+
cpus: 1
147+
148+
# Ubuntu
149+
150+
precise32.vagrant.dev:
151+
enabled: false
152+
box: ubuntu/precise32
153+
network:
154+
name: private_network
155+
ip: 192.168.124.1
156+
157+
provider:
158+
name: virtualbox
159+
memory: 1024
160+
cpus: 1
161+
162+
precise64.vagrant.dev:
163+
enabled: false
164+
box: ubuntu/precise64
165+
network:
166+
name: private_network
167+
ip: 192.168.124.2
168+
169+
provider:
170+
name: virtualbox
171+
memory: 1024
172+
cpus: 1
173+
174+
trusty32.vagrant.dev:
175+
enabled: false
176+
box: ubuntu/trusty32
177+
network:
178+
name: private_network
179+
ip: 192.168.124.3
180+
181+
provider:
182+
name: virtualbox
183+
memory: 1024
184+
cpus: 1
185+
186+
trusty64.vagrant.dev:
187+
enabled: false
188+
box: ubuntu/trusty64
189+
network:
190+
name: private_network
191+
ip: 192.168.124.4
192+
193+
provider:
194+
name: virtualbox
195+
memory: 1024
196+
cpus: 1
197+
198+
vivid32.vagrant.dev:
199+
enabled: false
200+
box: ubuntu/vivid32
201+
network:
202+
name: private_network
203+
ip: 192.168.124.5
204+
205+
provider:
206+
name: virtualbox
207+
memory: 1024
208+
cpus: 1
209+
210+
vivid64.vagrant.dev:
211+
enabled: false
212+
box: ubuntu/vivid64
213+
network:
214+
name: private_network
215+
ip: 192.168.124.6
216+
217+
provider:
218+
name: virtualbox
219+
memory: 1024
220+
cpus: 1

tests/host_vars/precise64.vagrant.dev.yml

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

tests/host_vars/trusty64.vagrant.dev.yml

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

tests/localhost.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ INVENTORY="localhost,"
3030
PLAYBOOK="localhost.yml"
3131
VIRTUALENV_NAME="localhost"
3232

33+
box="localhost"
34+
3335
# provision
3436
ansible-playbook -i ${INVENTORY} ${PLAYBOOK}
3537

tests/localhost.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
- hosts: localhost
55
gather_facts: yes
66
connection: local
7+
78
roles:
9+
- ansiblebit.oracle-java
810
- primogen

tests/test_idempotence.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
#
88
# mandatory variables:
99
#
10+
# from environment.sh
1011
# - INVENTORY : the inventory to be used to run the test against.
1112
# - PLAYBOOK : the path to the Ansible playbook.
1213
#
14+
# from <playbook_name>.sh
15+
# - box : the name of the vagrant box
16+
#
1317
# optional variables:
1418
#
1519
# - VIRTUALENV_NAME : the name of the virtualenv being used.
@@ -28,7 +32,8 @@ RED='\033[0;31m'
2832
NC='\033[0m'
2933

3034
echo "[INFO] $VIRTUALENV_NAME running idempotence test..."
31-
ansible-playbook -i ${INVENTORY} ${PLAYBOOK} | \
32-
grep -q "${PASS_CRITERIA}" && \
35+
ansible-playbook -i ${INVENTORY} --limit ${box} ${PLAYBOOK}
36+
ansible-playbook -i ${INVENTORY} --limit ${box} ${PLAYBOOK} | \
37+
grep "${box}" | grep -q "${PASS_CRITERIA}" && \
3338
echo -ne "[TEST] $VIRTUALENV_NAME idempotence : ${GREEN}PASS${NC}\n" || \
3439
(echo -ne "[TEST] $VIRTUALENV_NAME idempotence : ${RED}FAILED${NC} ${PASS_CRITERIA}\n" && exit 1)

tests/vagrant.sh

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@
77
#
88
# usage:
99
#
10-
# bash vagrant.sh
10+
# $ bash vagrant.sh --python 27 --ansible 1901
1111
#
12-
# # in case you want to use one of tox virtualenvs
13-
#
14-
# bash vagrant.sh --virtualenv $PWD/.tox/py27-ansible184 --virtualenv-name py27-ansible184
15-
# # or
16-
# bash vagrant.sh --python 27 --ansible 184
12+
# $ bash vagrant.sh --virtualenv ../.tox/py27-ansible1901 --virtualenv-name py27-ansible1901
1713
#
1814
# author(s):
1915
# - Pedro Salgado <[email protected]>
@@ -81,19 +77,20 @@ source ${VIRTUALENV}/bin/activate
8177

8278
. install_role_dependencies.sh
8379

80+
# force Ansible to ask for sudo password when running tests against Vagrant
81+
export ANSIBLE_ASK_SUDO_PASS=True
8482

85-
for box_yml in host_vars/*.yml
83+
for box in `grep vagrant.dev group_vars/all.yml | sed 's/://g'`
8684
do
87-
filename=$(basename "$box_yml")
88-
box=${filename%.*}
8985

9086
echo "[INFO] preparing ${box}..."
91-
vagrant up ${box}
92-
93-
# force tests to be run against this Vagrant box
94-
INVENTORY="${box},"
87+
vagrant up ${box} 2> /dev/null
88+
if [ ! -z $? ]; then
89+
# box not enabled
90+
continue
91+
fi
9592

96-
. test_idempotence.sh
93+
# . test_idempotence.sh
9794

9895
echo "[INFO] destroying ${box}..."
9996
vagrant destroy -f $box

0 commit comments

Comments
 (0)