3
# A runner for the Amulet tests.
6
# - apt-get install sshuttle python-nova juju-core
7
# - A novarc file sourced.
8
# - The following in /etc/sudoers.d/sshuttle:
10
# your_username ALL = (root) NOPASSWD: /usr/bin/python /usr/lib/sshuttle/main.py *
12
TESTDIR="${TESTDIR-$(dirname $0)}"
13
TESTS="${TESTS-$(ls $TESTDIR)}"
15
SSH_OPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
16
AMULET=$(readlink -f $(mktemp -d ci-amulet.XXXX))
17
DEPLOYER=$(readlink -f $(mktemp -d ci-deployer.XXXX))
18
export PYTHONPATH=$AMULET:$DEPLOYER
19
export PATH=$DEPLOYER:$PATH
21
if [ -z "$OS_USERNAME" ]; then
22
echo "Please source a novarc before running this harness." 1>&2
26
sudoersfile=/etc/sudoers.d/sshuttle
27
if [ ! -f $sudoersfile ]; then
28
echo "Please run: " 1>&2
29
echo "echo \"$USER ALL = (root) NOPASSWD: /usr/bin/python /usr/lib/sshuttle/main.py *\" > $sudoersfile" 1>&2
35
echo "Cleaning up environment."
37
rm -rf $AMULET $DEPLOYER
39
# Kill sshuttle if it's running (and it should be).
40
if [ -e sshuttle.pid ]; then
41
kill $(cat sshuttle.pid)
44
if [ -n "$(euca-describe-instances)" ]; then
45
juju destroy-environment -y
49
while [ -n "$(euca-describe-instances)" ]; do
53
echo "Timed out waiting for nodes to disappear." 1>&2
62
echo "Bootstrapping juju."
64
juju bootstrap --constraints="mem=1024M"
66
# we'll be waiting a while any way, so pull down amulet if needed
67
if [ ! -d $AMULET ] ; then
68
echo "downloading amulet"
69
bzr co --lightweight lp:amulet $AMULET
71
if [ ! -d $DEPLOYER ] ; then
72
# the "to" stanza only works in the latest version of deployer not
73
# yet packages and the juju-gui test requires this
74
echo "downloading deployer"
75
bzr co --lightweight lp:juju-deployer $DEPLOYER
76
cat > $DEPLOYER/juju-deployer <<EOF
78
PYTHONPATH=$PYTHONPATH
79
exec python $DEPLOYER/deployer/cli.py \$*
81
chmod +x $DEPLOYER/juju-deployer
88
while [ $max != 0 ]; do
89
ip="$(nova list --name machine-0 --fields networks | grep = | sed 's,.*=\(.*\) .*,\1,')"
98
echo "Could not find IP for bootstrap node." 1>&2
106
# 5 second intervals to wait
110
echo "Trying $ip ($max)"
111
# Attempt to ssh into the machine an immediately exit if successful. We
112
# have a connection, break out of the loop.
113
ssh $SSH_OPTS ubuntu@$ip exit 2>/dev/null && break
118
if [ $max = 0 ]; then
119
echo "Timed out waiting for bootstrap node."
128
echo "Tunneling traffic through bootstrap node."
131
sshuttle -D -r ubuntu@$ip 10.55.0.0/16 -e "ssh $SSH_OPTS"
134
for test in $TESTS; do
135
trap 'cleanup' TERM QUIT INT EXIT
137
# Assume tests are of the form tests/$test/test.py.
138
[ -d "$TESTDIR/$test" ] || continue
139
echo ========================================
140
echo Testing $test ...
141
echo ========================================
146
ip="$(get_bootstrap_ip)"
151
$TESTDIR/$test/test.py