308.1.1
by Aaron Bentley
Add closed-network test. |
1 |
#!/bin/bash
|
2 |
set -eu
|
|
791.1.1
by Curtis Hovey
Parameterise args so that restricted network testing can run on precise or trusty. |
3 |
JUJU_HOME="$HOME/.juju" |
4 |
AMI_IMAGE="" |
|
5 |
SERIES="" |
|
6 |
while [[ "${1-}" != "" && $1 =~ ^-.* ]]; do |
|
7 |
case $1 in |
|
8 |
--juju-home)
|
|
9 |
shift
|
|
10 |
JUJU_HOME=$(cd $1; pwd) |
|
11 |
;;
|
|
12 |
--ami-image)
|
|
13 |
shift
|
|
14 |
AMI_IMAGE=$1 |
|
15 |
;;
|
|
16 |
--series)
|
|
17 |
shift
|
|
18 |
SERIES=$1 |
|
19 |
;;
|
|
20 |
esac
|
|
21 |
shift
|
|
22 |
done
|
|
23 |
||
24 |
if [[ -z $AMI_IMAGE || -z $SERIES ]]; then |
|
25 |
echo "--ami-image and --series are required" |
|
26 |
exit 2 |
|
27 |
fi
|
|
28 |
||
29 |
export JUJU_HOME
|
|
30 |
export AMI_IMAGE
|
|
31 |
export SERIES
|
|
32 |
||
308.1.1
by Aaron Bentley
Add closed-network test. |
33 |
SCRIPTS=$(readlink -f $(dirname $0)) |
791.1.1
by Curtis Hovey
Parameterise args so that restricted network testing can run on precise or trusty. |
34 |
: ${JENKINS_URL="http://juju-ci.vapour.ws:8080/"} |
308.1.1
by Aaron Bentley
Add closed-network test. |
35 |
: ${JOB_NAME="testy"} |
36 |
export JOB_NAME
|
|
37 |
export PATH="$SCRIPTS:$PATH" |
|
38 |
source $JUJU_HOME/ec2rc |
|
39 |
ec2-terminate-job-instances |
|
40 |
set -x
|
|
41 |
export INSTANCE_TYPE=m1.large |
|
42 |
instance_id=$(ec2-run-instance-get-id) |
|
43 |
ec2-tag-job-instances $instance_id
|
|
44 |
instance_name=$(ec2-get-name $instance_id) |
|
45 |
wait-for-port $instance_name 22 |
|
46 |
set +e
|
|
47 |
ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" \ |
|
791.1.1
by Curtis Hovey
Parameterise args so that restricted network testing can run on precise or trusty. |
48 |
ubuntu@$instance_name "JENKINS_URL=$JENKINS_URL SERIES=$SERIES bash"<<"EOT" |
308.1.1
by Aaron Bentley
Add closed-network test. |
49 |
set -eux
|
314
by Aaron Bentley
Verify sources.list before running script. |
50 |
for attempt in $(seq 10); do |
316
by Aaron Bentley
Stop looping on apt-get install. |
51 |
if grep ec2.archive.ubuntu.com /etc/apt/sources.list > /dev/null; then |
314
by Aaron Bentley
Verify sources.list before running script. |
52 |
break
|
315
by Aaron Bentley
Fix test. |
53 |
elif [ "$attempt" == "10" ]; then |
314
by Aaron Bentley
Verify sources.list before running script. |
54 |
exit 1 |
55 |
fi
|
|
56 |
sleep 10
|
|
57 |
done
|
|
791.1.1
by Curtis Hovey
Parameterise args so that restricted network testing can run on precise or trusty. |
58 |
if [[ $SERIES == "precise" ]]; then |
59 |
sudo add-apt-repository cloud-archive:tools |
|
60 |
CONNTRACK="" |
|
61 |
else
|
|
62 |
CONNTRACK="conntrack" |
|
63 |
fi
|
|
308.1.1
by Aaron Bentley
Add closed-network test. |
64 |
sudo apt-get update |
323
by Aaron Bentley
Try moving frontend specification. |
65 |
sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y |
791.1.1
by Curtis Hovey
Parameterise args so that restricted network testing can run on precise or trusty. |
66 |
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y bzr $CONNTRACK |
316
by Aaron Bentley
Stop looping on apt-get install. |
67 |
|
313
by Aaron Bentley
Prevent spurious failure. |
68 |
# prevent spurious failure on success
|
69 |
rm .bash_logout |
|
780
by Curtis Hovey
Revert use of jujuci.py because it will not exist on the remote machine. |
70 |
afact=lastSuccessfulBuild/artifact |
71 |
wget -q ${JENKINS_URL}job/build-revision/$afact/buildvars.bash |
|
491
by Curtis Hovey
Remove juju-local dependency hack because proper source |
72 |
source buildvars.bash
|
73 |
RELEASE=$(lsb_release -sr) |
|
74 |
ARCH=$(dpkg --print-architecture) |
|
75 |
juju_local_deb="juju-local_$VERSION-0ubuntu1~$RELEASE.1~juju1_all.deb" |
|
76 |
juju_core_deb="juju-core_$VERSION-0ubuntu1~$RELEASE.1~juju1_$ARCH.deb" |
|
780
by Curtis Hovey
Revert use of jujuci.py because it will not exist on the remote machine. |
77 |
wget -q ${JENKINS_URL}job/publish-revision/$afact/$juju_local_deb |
78 |
wget -q ${JENKINS_URL}job/publish-revision/$afact/$juju_core_deb |
|
441
by Curtis Hovey
I meant +e not +x |
79 |
set +e
|
491
by Curtis Hovey
Remove juju-local dependency hack because proper source |
80 |
sudo dpkg -i $juju_core_deb $juju_local_deb |
441
by Curtis Hovey
I meant +e not +x |
81 |
set -e
|
446
by Curtis Hovey
Hack the rsyslog-gnutls dep because the packaging step |
82 |
sudo apt-get install -y -f |
308.1.1
by Aaron Bentley
Add closed-network test. |
83 |
export JUJU_REPOSITORY="$HOME/repo" |
791.1.1
by Curtis Hovey
Parameterise args so that restricted network testing can run on precise or trusty. |
84 |
mkdir -p $JUJU_REPOSITORY/$SERIES |
85 |
bzr branch lp:charms/ubuntu $JUJU_REPOSITORY/$SERIES/ubuntu |
|
339.1.3
by Aaron Bentley
Provide specific juju config for restricted network test. |
86 |
mkdir ~/.juju |
87 |
cat > ~/.juju/environments.yaml <<EOT2
|
|
88 |
default: local
|
|
89 |
environments:
|
|
90 |
local:
|
|
91 |
type: local
|
|
339.1.4
by Aaron Bentley
Update config names. |
92 |
tools-metadata-url: http://juju-dist.s3.amazonaws.com/testing/tools
|
339.1.3
by Aaron Bentley
Provide specific juju config for restricted network test. |
93 |
EOT2
|
308.1.1
by Aaron Bentley
Add closed-network test. |
94 |
ssh-keygen -t rsa -b 2048 -N "" -f ~/.ssh/id_rsa |
379
by Aaron Bentley
Apply live fixes. |
95 |
#juju sync-tools --show-log
|
791.1.1
by Curtis Hovey
Parameterise args so that restricted network testing can run on precise or trusty. |
96 |
login_ip=$(sudo cat /proc/net/ip_conntrack || sudo conntrack -L | \ |
97 |
sed -nr 's/.*src=([^ ]*) .*dport=22 .*/\1/p' | uniq) |
|
308.1.1
by Aaron Bentley
Add closed-network test. |
98 |
gateway=$(route -n | sed -rn 's/^0.0.0.0 *([0-7.]*) .*/\1/p') |
99 |
nameservers="$(sed /etc/resolv.conf -nr -e 's/nameserver (.*)/\1/p')" |
|
100 |
for ns in $nameservers; do |
|
101 |
sudo route add $ns gw $gateway |
|
102 |
done
|
|
103 |
sudo route add $login_ip gw $gateway |
|
104 |
for ip in $(dig archive.ubuntu.com ubuntu-cloud.archive.canonical.com\ |
|
105 |
security.ubuntu.com cloud-images.ubuntu.com +short |sort|uniq); do |
|
106 |
sudo route add $ip gw $gateway |
|
107 |
done
|
|
108 |
sudo route add -net 172.16.0.0 netmask 255.240.0.0 gw $gateway |
|
109 |
sudo route del default gw $gateway
|
|
339.1.5
by Aaron Bentley
Add --show-log to juju commands. |
110 |
juju bootstrap --show-log |
324
by Aaron Bentley
Retry on deploy failure. |
111 |
for x in $(seq 6); do |
791.1.1
by Curtis Hovey
Parameterise args so that restricted network testing can run on precise or trusty. |
112 |
if juju deploy --show-log local:$SERIES/ubuntu; then |
324
by Aaron Bentley
Retry on deploy failure. |
113 |
break
|
114 |
elif [ "$x" == "6" ]; then |
|
115 |
exit 0; |
|
116 |
fi
|
|
117 |
done
|
|
308.1.1
by Aaron Bentley
Add closed-network test. |
118 |
for x in $(seq 30); do |
119 |
# relying on the indentation of ubuntu/0's agent-state here...
|
|
120 |
if juju status | grep -E ' {8}agent-state: started'; then |
|
121 |
exit 0; |
|
122 |
fi
|
|
123 |
sleep 10
|
|
124 |
done
|
|
325
by Aaron Bentley
Show full status on error. |
125 |
juju status |
308.1.1
by Aaron Bentley
Add closed-network test. |
126 |
exit 1 |
127 |
EOT |
|
128 |
result=$? |
|
129 |
set -e
|
|
130 |
ec2-terminate-job-instances |
|
131 |
exit $result |