2549.2.8
by Brendan Donegan
Restore test-in-vagrant.sh |
1 |
#!/bin/sh
|
2 |
# Run all tests in various versions of Ubuntu via vagrant
|
|
3 |
||
4 |
mkdir -p vagrant-logs |
|
5 |
TIMING=vagrant-logs/timing.dat |
|
6 |
VAGRANT_DONE_ACTION=${VAGRANT_DONE_ACTION:-destroy} |
|
7 |
||
8 |
||
9 |
pastebinit() { |
|
10 |
/usr/bin/python /usr/bin/pastebinit "$@"; |
|
11 |
}
|
|
12 |
||
13 |
test -z $(which vagrant) && echo "You need to install vagrant first" && exit |
|
14 |
||
15 |
# When running in tarmac, the state file .vagrant, will be removed when the
|
|
16 |
# tree is re-pristinized. To work around that, check for present
|
|
17 |
# VAGRANT_STATE_FILE (custom variable, not set by tarmac or respected by
|
|
18 |
# vagrant) and symlink the .vagrant state file from there.
|
|
19 |
if [ "x$VAGRANT_STATE_FILE" != "x" ]; then |
|
20 |
if [ ! -e "$VAGRANT_STATE_FILE" ]; then |
|
21 |
touch "$VAGRANT_STATE_FILE" |
|
22 |
fi
|
|
23 |
ln -fs "$VAGRANT_STATE_FILE" .vagrant |
|
24 |
fi
|
|
25 |
||
26 |
if [ "$1" = "" ]; then |
|
2625.2.1
by Daniel Manrique
support: test only on precise and trusty |
27 |
# Vagrantfile defines several ubuntu target releases, the ones
|
28 |
# we actually want to test in should be included in target_list below.
|
|
29 |
target_list="precise trusty" |
|
2549.2.8
by Brendan Donegan
Restore test-in-vagrant.sh |
30 |
else
|
31 |
target_list="$1" |
|
32 |
fi
|
|
33 |
||
34 |
PASS="$(printf "\33[32;1mPASS\33[39;0m")" |
|
35 |
FAIL="$(printf "\33[31;1mFAIL\33[39;0m")" |
|
36 |
||
37 |
outcome=0 |
|
38 |
for target in $target_list; do |
|
39 |
# Bring up target if needed
|
|
40 |
if ! vagrant status $target | grep -q running; then |
|
41 |
step="[$target] Bringing VM 'up'" |
|
42 |
echo $step |
|
43 |
if ! time -o $TIMING vagrant up $target >vagrant-logs/$target.startup.log 2>vagrant-logs/$target.startup.err; then |
|
44 |
outcome=1 |
|
45 |
echo "[$target] Unable to 'up' VM!" |
|
46 |
echo "[$target] stdout: $(pastebinit vagrant-logs/$target.startup.log)" |
|
47 |
echo "[$target] stderr: $(pastebinit vagrant-logs/$target.startup.err)" |
|
48 |
echo "[$target] NOTE: unable to execute tests, marked as failed" |
|
49 |
echo "[$target] Destroying failed VM to reclaim resources" |
|
50 |
vagrant destroy -f $target; |
|
51 |
continue
|
|
52 |
fi
|
|
53 |
cat $TIMING | sed -e "s/^/[$target] (timing) /" |
|
54 |
fi
|
|
55 |
# Display something before the first test output
|
|
56 |
echo "[$target] Starting tests..." |
|
2973.1.2
by Daniel Manrique
test-in-vagrant: Use per-component mini-scripts for testing. |
57 |
# Run test suite commands here.
|
58 |
# Tests are found in each component's requirements/ dir and are named *container-tests-*
|
|
59 |
# Numbers can be used at the beginning to control running order within each component.
|
|
60 |
# Tests scripts are expected to:
|
|
61 |
# - Be run from the *component's* top-level directory. This is a convenience to avoid
|
|
62 |
# a boilerplate "cd .." on every test script. So for 'plainbox' we do the equivalent of
|
|
63 |
# $ cd $BLAH/plainbox
|
|
64 |
# $
|
|
65 |
# - Exit 0 for success, other codes for failure
|
|
66 |
# - Write logs/debugging data to stdout and stderr.
|
|
67 |
for test_script in $(find ./ -path '*/requirements/*container-tests-*' | sort); do |
|
68 |
echo "Found a test script: $test_script" |
|
69 |
test_name=$(basename $test_script) |
|
70 |
# Two dirnames strips the requirements/ component
|
|
71 |
component_dir=$(dirname $(dirname $test_script)) |
|
72 |
# Inside the VM, tests are relative to $HOME/src.
|
|
73 |
# Note that for vagrant, we want $HOME to expand *inside* the VM, so
|
|
74 |
# that part of the command is in *single* quotes, otherwise we get the
|
|
75 |
# $HOME from the host. However, $component_dir and $test_name should
|
|
76 |
# come from the host, so we use double quotes.
|
|
77 |
script_md5sum=$(echo $test_script | md5sum |cut -d " " -f 1) |
|
78 |
logfile=vagrant-logs/${target}.${test_name}.${script_md5sum}.log |
|
79 |
errfile=vagrant-logs/${target}.${test_name}.${script_md5sum}.err |
|
80 |
if /usr/bin/time -o $TIMING vagrant ssh $target -c 'cd $HOME/src/'"$component_dir && ./requirements/$test_name" >$logfile 2>$errfile |
|
81 |
then
|
|
82 |
echo "[$target] ${test_name}: $PASS" |
|
83 |
else
|
|
84 |
outcome=1 |
|
85 |
echo "[$target] ${test_name}: $FAIL" |
|
86 |
echo "[$target] stdout: $(pastebinit $logfile)" |
|
87 |
echo "[$target] stderr: $(pastebinit $errfile)" |
|
88 |
fi
|
|
89 |
cat $TIMING | sed -e "s/^/[$target] (timing) /" |
|
90 |
done
|
|
2899.1.13
by Zygmunt Krynicki
test-in-vagrant: test the checkbox provider |
91 |
|
2549.2.8
by Brendan Donegan
Restore test-in-vagrant.sh |
92 |
# Decide what to do with the VM
|
93 |
case $VAGRANT_DONE_ACTION in |
|
94 |
suspend) |
|
95 |
# Suspend the target to conserve resources
|
|
96 |
echo "[$target] Suspending VM" |
|
97 |
if ! vagrant suspend $target >vagrant-logs/$target.suspend.log 2>vagrant-logs/$target.suspend.err; then |
|
98 |
echo "[$target] Unable to suspend VM!" |
|
99 |
echo "[$target] stdout: $(pastebinit vagrant-logs/$target.suspend.log)" |
|
100 |
echo "[$target] stderr: $(pastebinit vagrant-logs/$target.suspend.err)" |
|
101 |
echo "[$target] You may need to manually 'vagrant destroy $target' to fix this" |
|
102 |
fi
|
|
103 |
;;
|
|
104 |
destroy)
|
|
105 |
# Destroy the target to work around virtualbox hostsf bug
|
|
106 |
echo "[$target] Destroying VM" |
|
107 |
if ! vagrant destroy --force $target >vagrant-logs/$target.destroy.log 2>vagrant-logs/$target.destroy.err; then |
|
108 |
echo "[$target] Unable to destroy VM!" |
|
109 |
echo "[$target] stdout: $(pastebinit vagrant-logs/$target.suspend.log)" |
|
110 |
echo "[$target] stderr: $(pastebinit vagrant-logs/$target.suspend.err)" |
|
111 |
echo "[$target] You may need to manually 'vagrant destroy $target' to fix this" |
|
112 |
fi
|
|
113 |
;;
|
|
114 |
esac
|
|
115 |
done
|
|
116 |
# Propagate failure code outside
|
|
117 |
exit $outcome |