forked from checkbox/checkbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-in-vagrant.sh
executable file
·162 lines (146 loc) · 7.37 KB
/
test-in-vagrant.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/sh
# Run all tests in various versions of Ubuntu via vagrant
mkdir -p vagrant-logs
TIMING=vagrant-logs/timing.dat
VAGRANT_DONE_ACTION=${VAGRANT_DONE_ACTION:-destroy}
pastebinit() {
/usr/bin/python /usr/bin/pastebinit "$@";
}
test -z $(which vagrant) && echo "You need to install vagrant first" && exit
# When running in tarmac, the state file .vagrant, will be removed when the
# tree is re-pristinized. To work around that, check for present
# VAGRANT_STATE_FILE (custom variable, not set by tarmac or respected by
# vagrant) and symlink the .vagrant state file from there.
if [ "x$VAGRANT_STATE_FILE" != "x" ]; then
if [ ! -e "$VAGRANT_STATE_FILE" ]; then
touch "$VAGRANT_STATE_FILE"
fi
ln -fs "$VAGRANT_STATE_FILE" .vagrant
fi
if [ "$1" = "" ]; then
# Vagrantfile defines several ubuntu target releases, the ones
# we actually want to test in should be included in target_list below.
target_list="precise trusty"
else
target_list="$1"
fi
PASS="$(printf "\33[32;1mPASS\33[39;0m")"
FAIL="$(printf "\33[31;1mFAIL\33[39;0m")"
outcome=0
for target in $target_list; do
# Bring up target if needed
if ! vagrant status $target | grep -q running; then
step="[$target] Bringing VM 'up'"
echo $step
if ! time -o $TIMING vagrant up $target >vagrant-logs/$target.startup.log 2>vagrant-logs/$target.startup.err; then
outcome=1
echo "[$target] Unable to 'up' VM!"
echo "[$target] stdout: $(pastebinit vagrant-logs/$target.startup.log)"
echo "[$target] stderr: $(pastebinit vagrant-logs/$target.startup.err)"
echo "[$target] NOTE: unable to execute tests, marked as failed"
echo "[$target] Destroying failed VM to reclaim resources"
vagrant destroy -f $target;
continue
fi
cat $TIMING | sed -e "s/^/[$target] (timing) /"
fi
# Display something before the first test output
echo "[$target] Starting tests..."
# Build checkbox-gui
if time -o $TIMING vagrant ssh $target -c 'cd src/checkbox-gui; make distclean; qmake && make' >vagrant-logs/$target.checkbox-gui.log 2>vagrant-logs/$target.checkbox-gui.err; then
echo "[$target] Checkbox GUI build: $PASS"
else
outcome=1
echo "[$target] Checkbox GUI build: $FAIL"
echo "[$target] stdout: $(pastebinit vagrant-logs/$target.checkbox-gui.log)"
echo "[$target] stderr: $(pastebinit vagrant-logs/$target.checkbox-gui.err)"
fi
cat $TIMING | sed -e "s/^/[$target] (timing) /"
# Run checkbox unit tests
if time -o $TIMING vagrant ssh $target -c 'cd src/checkbox-old && python3 setup.py test' >vagrant-logs/$target.checkbox.log 2>vagrant-logs/$target.checkbox.err; then
echo "[$target] CheckBox test suite: $PASS"
else
outcome=1
echo "[$target] CheckBox test suite: $FAIL"
echo "[$target] stdout: $(pastebinit vagrant-logs/$target.checkbox.log)"
echo "[$target] stderr: $(pastebinit vagrant-logs/$target.checkbox.err)"
fi
cat $TIMING | sed -e "s/^/[$target] (timing) /"
# Refresh plainbox installation. This is needed if .egg-info (which is
# essential for 'develop' to work) was removed in the meantime, for
# example, by tarmac.
if ! time -o $TIMING vagrant ssh $target -c 'cd src/plainbox && python3 setup.py egg_info' >vagrant-logs/$target.egginfo.log 2>vagrant-logs/$target.egginfo.err; then
outcome=1
echo "[$target] Running 'plainbox/setup.py egg_info' failed"
echo "[$target] stdout: $(pastebinit vagrant-logs/$target.egginfo.log)"
echo "[$target] stderr: $(pastebinit vagrant-logs/$target.egginfo.err)"
echo "[$target] NOTE: unable to execute tests, marked as failed"
fi
cat $TIMING | sed -e "s/^/[$target] (timing) /"
# Run plainbox unit tests
# TODO: It would be nice to support fast failing here
if time -o $TIMING vagrant ssh $target -c 'cd src/plainbox && python3 setup.py test' >vagrant-logs/$target.plainbox.log 2>vagrant-logs/$target.plainbox.err; then
echo "[$target] PlainBox test suite: $PASS"
else
outcome=1
echo "[$target] PlainBox test suite: $FAIL"
echo "[$target] stdout: $(pastebinit vagrant-logs/$target.plainbox.log)"
echo "[$target] stderr: $(pastebinit vagrant-logs/$target.plainbox.err)"
fi
cat $TIMING | sed -e "s/^/[$target] (timing) /"
# Build plainbox documentation
if time -o $TIMING vagrant ssh $target -c 'cd src/plainbox && python3 setup.py build_sphinx' >vagrant-logs/$target.sphinx.log 2>vagrant-logs/$target.sphinx.err; then
echo "[$target] PlainBox documentation build: $PASS"
else
outcome=1
echo "[$target] PlainBox documentation build: $FAIL"
echo "[$target] stdout: $(pastebinit vagrant-logs/$target.sphinx.log)"
echo "[$target] stderr: $(pastebinit vagrant-logs/$target.sphinx.err)"
fi
cat $TIMING | sed -e "s/^/[$target] (timing) /"
# Run checkbox-ng unit tests
if time -o $TIMING vagrant ssh $target -c 'cd src/checkbox-ng && python3 setup.py test' >vagrant-logs/$target.checkbox-ng.log 2>vagrant-logs/$target.checkbox-ng.err; then
echo "[$target] CheckBoxNG test suite: $PASS"
else
outcome=1
echo "[$target] CheckBoxNG test suite: $FAIL"
echo "[$target] stdout: $(pastebinit vagrant-logs/$target.checkbox-ng.log)"
echo "[$target] stderr: $(pastebinit vagrant-logs/$target.checkbox-ng.err)"
fi
cat $TIMING | sed -e "s/^/[$target] (timing) /"
# Run plainbox integration test suite (that tests checkbox scripts)
if time -o $TIMING vagrant ssh $target -c 'sudo plainbox self-test --verbose --fail-fast --integration-tests' >vagrant-logs/$target.self-test.log 2>vagrant-logs/$target.self-test.err; then
echo "[$target] Integration tests: $PASS"
else
outcome=1
echo "[$target] Integration tests: $FAIL"
echo "[$target] stdout: $(pastebinit vagrant-logs/$target.self-test.log)"
echo "[$target] stderr: $(pastebinit vagrant-logs/$target.self-test.err)"
fi
cat $TIMING | sed -e "s/^/[$target] (timing) /"
# Decide what to do with the VM
case $VAGRANT_DONE_ACTION in
suspend)
# Suspend the target to conserve resources
echo "[$target] Suspending VM"
if ! vagrant suspend $target >vagrant-logs/$target.suspend.log 2>vagrant-logs/$target.suspend.err; then
echo "[$target] Unable to suspend VM!"
echo "[$target] stdout: $(pastebinit vagrant-logs/$target.suspend.log)"
echo "[$target] stderr: $(pastebinit vagrant-logs/$target.suspend.err)"
echo "[$target] You may need to manually 'vagrant destroy $target' to fix this"
fi
;;
destroy)
# Destroy the target to work around virtualbox hostsf bug
echo "[$target] Destroying VM"
if ! vagrant destroy --force $target >vagrant-logs/$target.destroy.log 2>vagrant-logs/$target.destroy.err; then
echo "[$target] Unable to destroy VM!"
echo "[$target] stdout: $(pastebinit vagrant-logs/$target.suspend.log)"
echo "[$target] stderr: $(pastebinit vagrant-logs/$target.suspend.err)"
echo "[$target] You may need to manually 'vagrant destroy $target' to fix this"
fi
;;
esac
done
# Propagate failure code outside
exit $outcome