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
|
#!/bin/bash
# IMPORTANT: The ssh options are always remapped to $@ which preserves
# their tokenisation.
set -eux
: ${LOCAL_JENKINS_URL=$JENKINS_URL}
ssh_options='-o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null"'
remote_user="ubuntu"
if [[ $1 =~ .*@.* ]]; then
is_ephemeral="false"
remote_user=$(echo $1 | cut -d @ -f1)
instance_name=$(echo $1 | cut -d @ -f2)
shift
eval "set -- $ssh_options $1"
else
is_ephemeral="true"
export INSTANCE_TYPE=$1
export AMI_IMAGE=$2
eval "set -- $ssh_options"
fi
if [[ $is_ephemeral == "true" ]]; then
instance_id=$($SCRIPTS/ec2-run-instance-get-id)
$SCRIPTS/ec2-tag-job-instances $instance_id
set +x
echo Starting instance $instance_id
instance_name=$($SCRIPTS/ec2-get-name $instance_id)
echo Instance has ip $instance_name
sleep 30
$SCRIPTS/wait-for-port $instance_name 22
fi
# Define common vars for remote scripts; do not make them evalaute
# what is known in this script to ensure the logs line order is sane.
archive="$LOCAL_JENKINS_URL/job/build-revision/lastSuccessfulBuild/artifact"
test -f buildvars.bash && rm buildvars.bash
wget -q $archive/buildvars.bash
source buildvars.bash
rev=${REVNO-$(echo $REVISION_ID | head -c8)}
echo "Testing $BRANCH $rev"
tarfile=$($SCRIPTS/get-tarfile-name $revision_build)
test -f $tarfile && rm $tarfile
wget -q $archive/$tarfile
juju_version=$(basename $tarfile .tar.gz)
set -x
set +e
DEPS="make bzr distro-info-data git-core mercurial zip rsyslog-gnutls"
ssh "$@" $remote_user@$instance_name <<EOT
set -eux
if [[ $is_ephemeral == "true" ]]; then
for attempt in \$(seq 10); do
if grep -r '^deb .* universe$' /etc/apt/sources.list > /dev/null; then
break
elif [ "\$attempt" == "10" ]; then
echo "Universe is not available to install packages from."
exit 1
fi
sleep 10m
done
fi
needs_ppa=\$(lsb_release -sc | sed -r 's,(saucy|precise),true,')
if [[ \$needs_ppa == 'true' ]]; then
sudo apt-add-repository -y ppa:juju/experimental;
fi
sudo apt-get update
if [[ $is_ephemeral == "true" ]]; then
# sudo apt-get upgrade -y
echo "Skipping upgrade."
fi
if [[ \$(apt-cache madison juju-mongodb) =~ .*juju-mongodb.* ]]; then
juju_db="juju-mongodb"
else
juju_db="mongodb-server"
fi
if [[ \$(uname -p) =~ .*86|armel|armhf.* ]]; then
juju_compiler="golang"
else
juju_compiler="gccgo-4.9 gccgo-go"
fi
sudo apt-get install -y --no-install-recommends $DEPS \$juju_db \$juju_compiler
if [[ \$(lsb_release -sc) == "trusty" ]]; then
sudo apt-get install -y mongodb-server
fi
EOT
scp "$@" $tarfile $remote_user@$instance_name:~/
ssh "$@" $remote_user@$instance_name <<EOT
set -eux
if [[ ! -f ~/.ssh/id_rsa ]]; then
ssh-keygen -t rsa -b 2048 -N "" -f ~/.ssh/id_rsa
fi
export GOPATH=\$HOME/$juju_version
if [[ -d \$GOPATH ]]; then
rm -r \$GOPATH
fi
tar -xzf $tarfile
if [[ -d \$GOPATH/src/launchpad.net/juju-core ]]; then
cd \$GOPATH/src/launchpad.net/juju-core
else
cd \$GOPATH/src/github.com/juju/juju
fi
bzr whoami 'J. Random Hacker <jrandom@example.org>'
go version || gccgo -v
make build
# Hack match for i386.
sed -i 's/x86/86/' Makefile
export JUJU_NOTEST_MONGOJS=1
make check
EOT
EXIT_STATUS=$?
ssh "$@" $remote_user@$instance_name <<EOT
echo "Cleaning up /tmp"
sudo killall -SIGABRT /usr/bin/mongod
rm -r /tmp/adduser-* || true
rm -r /tmp/go-* || true
rm -r /tmp/gocheck-* || true
rm -r /tmp/juju-* || true
rm -r /tmp/test-* || true
EOT
if [[ $is_ephemeral == "true" ]]; then
$SCRIPTS/ec2-terminate-job-instances
fi
exit $EXIT_STATUS
|