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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
#!/bin/bash
set -eux
: ${SCRIPTS=$(readlink -f $(dirname $0))}
export INSTANCE_TYPE=$1
export AMI_IMAGE=$2
shift; shift
FIXUP_SOURCES=""
IS_LOCAL="false"
RETRY="false"
ROBUST="false"
REVISION_BUILD=${revision_build:-}
USE_PPA=""
USE_TMPFS="false"
GOTESTCMD="go test"
LOG_FILE_PATH="/usr/share/distro-info/ubuntu.csv"
LOG_TXT="17.04,Angsty Antelope,angsty,2016-10-23,2017-04-30,2018-01-29"
while [[ "${1-}" != "" ]]; do
case $1 in
--force-archive)
FIXUP_SOURCES="sudo sed s,//.*ec2.archive.ubuntu.com,//archive.ubuntu.com, /etc/apt/sources.list -i"
;;
--retry)
RETRY="true"
;;
--robust)
ROBUST="true"
GOTESTCMD="$GOTESTCMD -p 2 -test.timeout=1200s"
;;
--safe)
GOTESTCMD="$GOTESTCMD -p 2 -test.timeout=1200s"
;;
--local)
IS_LOCAL="true"
shift
tarfile=$1
;;
--revision-build)
shift
REVISION_BUILD=$1
;;
--use-ppa)
shift
USE_PPA=$1
if [[ -z $(echo $USE_PPA | grep 'ppa:.*/.*') ]]; then
echo "$USE_PPA is not a ppa."
exit 1
fi
;;
--use-tmpfs)
USE_TMPFS="true"
;;
--race)
GOTESTCMD="$GOTESTCMD -race"
;;
esac
shift
done
if [[ $IS_LOCAL == "false" ]]; then
# Download the buildvars and tartfile and lean the tarfile name.
downloaded=$($SCRIPTS/jujuci.py get build-revision '*' ./)
tarfile=$(basename $(echo "$downloaded" | grep -F tar.gz))
$SCRIPTS/jujuci.py get-build-vars \
--summary --env $AMI_IMAGE $REVISION_BUILD
fi
tarfile_path=$(readlink -f $tarfile)
tarfile_basename=$(basename $tarfile)
juju_version=$(basename $tarfile .tar.gz)
if [[ $INSTANCE_TYPE == "lxc" ]]; then
instance_id="juju-ci-unit-tester"
sudo lxc-stop -n $instance_id || true
sudo lxc-destroy -n $instance_id || true
echo "Creating LXC $instance_id"
if [[ $AMI_IMAGE =~ .*template ]]; then
sudo lxc-clone -o $AMI_IMAGE -n $instance_id
else
sudo lxc-create -n $instance_id -t ubuntu -- \
-r $AMI_IMAGE -S $HOME/.ssh/id_rsa.pub
fi
sudo lxc-start -d -n $instance_id
instance_name="-"
while [[ "$instance_name" == "-" ]]; do
instance_name=$(sudo lxc-ls --fancy |
grep $instance_id |
tr -s ' ' |
cut -d ' ' -f 3)
sleep 2
done
sudoers_file="/var/lib/lxc/$instance_id/rootfs/etc/sudoers.d/91-ubuntu"
echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' | sudo tee -a $sudoers_file
sudo chmod 0440 $sudoers_file
echo "$instance_id is at $instance_name"
elif [[ $INSTANCE_TYPE == "host" ]]; then
instance_name=$AMI_IMAGE
else
instance_id=$($SCRIPTS/ec2-run-instance-get-id)
for attempt in $(seq 5); do
if $SCRIPTS/ec2-tag-job-instances $instance_id; then
break
elif [ "$attempt" == "5" ]; then
exit 1
fi
sleep 15
done
set +x
echo Starting instance $instance_id
instance_name=$($SCRIPTS/ec2-get-name $instance_id)
echo Instance has name $instance_name
sleep 30
$SCRIPTS/wait-for-port $instance_name 22
fi
# Define the common vars before the embedded scripts; do not make them evalaute
# what is already know in the outer script.
set -x
set +e
scp -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" \
$tarfile_path ubuntu@$instance_name:~/
ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" \
ubuntu@$instance_name <<EOT
set -eux
if [[ ! -f ~/.ssh/id_rsa ]]; then
ssh-keygen -t rsa -b 2048 -N "" -f ~/.ssh/id_rsa
fi
if [[ "$USE_TMPFS" == "true" ]]; then
sudo mkdir -m 777 /mnt/tmp
sudo mount -t tmpfs -o size=3G /mnt/tmp /mnt/tmp
export TMPDIR=/mnt/tmp
fi
tar -xzf $tarfile_basename
export GOPATH=\$HOME/$juju_version
if [[ -d \$HOME/goroot ]]; then
export GOROOT=\$HOME/goroot
fi
cd \$GOPATH/src/github.com/juju/juju
if [[ "$INSTANCE_TYPE" != "lxc" && "$INSTANCE_TYPE" != "host" ]]; then
for attempt in \$(seq 10); do
if grep ec2.archive.ubuntu.com /etc/apt/sources.list > /dev/null; then
break
elif [ "\$attempt" == "10" ]; then
exit 1
fi
sleep 10
done
$FIXUP_SOURCES
fi
if [[ "$USE_PPA" != "" ]]; then
sudo apt-add-repository -y $USE_PPA;
fi
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y make python-software-properties distro-info-data
make install-dependencies
# TODO(gz): Remove bzr whoami?
bzr whoami 'J. Random Hacker <jrandom@example.org>'
go version || gccgo -v
make build
export JUJU_NOTEST_MONGOJS=1
if ! grep 'Angsty Antelope' $LOG_FILE_PATH ; then
echo "$LOG_TXT" | sudo tee -a $LOG_FILE_PATH
fi
if [[ "$RETRY" == "true" ]]; then
$GOTESTCMD ./... || $GOTESTCMD ./...
elif [[ "$ROBUST" == "true" ]]; then
JUJUD_PACKAGES=\$(go list github.com/juju/juju/... |
grep 'juju/juju/cmd/jujud')
OTHER_PACKAGES=\$(go list github.com/juju/juju/... |
grep -v 'juju/juju/cmd/jujud')
for packages in "\$JUJUD_PACKAGES" "\$OTHER_PACKAGES"; do
$GOTESTCMD \$packages
sudo killall -SIGABRT /usr/bin/mongod || true
sudo killall -SIGABRT /usr/lib/juju/bin/mongod || true
done
elif [[ "$GOTESTCMD" != "go test" ]]; then
$GOTESTCMD ./...
else
make check
fi
EOT
EXIT_STATUS=$?
set -e
if [[ $INSTANCE_TYPE == "lxc" ]]; then
echo "Deleting lxc"
sudo lxc-stop -n $instance_id
sudo lxc-destroy -n $instance_id
elif [[ $INSTANCE_TYPE == "host" ]]; then
ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" \
ubuntu@$instance_name <<EOT
set -eux
echo "Cleaning up /tmp"
sudo killall -SIGABRT /usr/bin/mongod || true
sudo killall -SIGABRT /usr/lib/juju/bin/mongod || true
rm -rf /home/ubuntu/$juju_version
rm -rf /tmp/adduser-*
rm -rf /tmp/go-*
rm -rf /tmp/gocheck-*
rm -rf /tmp/juju-*
rm -rf /tmp/test-*
EOT
else
set +e
# EC2 failures cannot change the EXIT_STATUS.
$SCRIPTS/ec2-terminate-job-instances
fi
exit $EXIT_STATUS
|