Merge lp:~thomir-deactivatedaccount/adt-cloud-worker/trunk-inine-uci-nova into lp:adt-cloud-worker
- trunk-inine-uci-nova
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Celso Providelo |
Approved revision: | 40 |
Merged at revision: | 40 |
Proposed branch: | lp:~thomir-deactivatedaccount/adt-cloud-worker/trunk-inine-uci-nova |
Merge into: | lp:adt-cloud-worker |
Diff against target: |
552 lines (+481/-9) 4 files modified
README.rst (+0/-6) adt_cloud_worker/__init__.py (+13/-1) adt_cloud_worker/tests/test_cloud_worker.py (+3/-2) uci-nova (+465/-0) |
To merge this branch: | bzr merge lp:~thomir-deactivatedaccount/adt-cloud-worker/trunk-inine-uci-nova |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Paul Larson | Approve | ||
Francis Ginther | Approve | ||
Review via email: mp+257605@code.launchpad.net |
Commit message
Inline the uci-nova ssh setup script.
Description of the change
Inline the uci-nova ssh setup script. This MP changes the code to point to the new ssh setup script, but doesn't change the contents of the ssh setup script at all (that will happen next).
Paul Larson (pwlars) : | # |
Ubuntu CI Bot (uci-bot) wrote : | # |
The attempt to merge lp:~thomir/adt-cloud-worker/trunk-inine-uci-nova into lp:adt-cloud-worker failed. Below is the output from the failed tests.
Using base prefix '/usr'
New python executable in /tmp/venv-
Also creating executable in /tmp/venv-
Installing setuptools, pip...done.
Running virtualenv with interpreter /usr/bin/python3
Ignoring indexes: https:/
Downloading/
Downloading/
Downloading/
Running setup.py (path:/
Downloading/
Downloading/
Downloading/
Running setup.py (path:/
Downloading/
Running setup.py (path:/
Downloading/
Downloading/
Downloading/
Running setup.py (path:/
warning: no previously-included files matching '*' found under directory 'docs/_build'
warning: no previously-included files matching '*.pyc' found under directory 'tests'
warning: no previously-included files matching '*.pyo' found under directory 'tests'
Downloading/
Downloading/
Running setup.py (path:/
Downloading/
Downloading/
Downloading/
Downloading/
Downloading/
Downloading/
Downloading/
Downloading/
- 40. By Thomi Richards
-
fix tests.
Preview Diff
1 | === modified file 'README.rst' | |||
2 | --- README.rst 2015-03-16 20:50:34 +0000 | |||
3 | +++ README.rst 2015-04-28 04:25:40 +0000 | |||
4 | @@ -35,12 +35,6 @@ | |||
5 | 35 | $ sudo apt-get update | 35 | $ sudo apt-get update |
6 | 36 | $ sudo apt-get install autopkgtest | 36 | $ sudo apt-get install autopkgtest |
7 | 37 | 37 | ||
8 | 38 | .. note:: | ||
9 | 39 | Thomi: At the time of writing (16/3/2015), the autopkgtest from the PPA is not | ||
10 | 40 | enough to make this work. You also need to manually branch | ||
11 | 41 | lp:~canonical-ci-engineering/adt-cloud-worker/uci-nova and follow the instructions | ||
12 | 42 | there. | ||
13 | 43 | |||
14 | 44 | Install the service itself:: | 38 | Install the service itself:: |
15 | 45 | 39 | ||
16 | 46 | $ python setup.py install | 40 | $ python setup.py install |
17 | 47 | 41 | ||
18 | === modified file 'adt_cloud_worker/__init__.py' | |||
19 | --- adt_cloud_worker/__init__.py 2015-04-28 03:28:12 +0000 | |||
20 | +++ adt_cloud_worker/__init__.py 2015-04-28 04:25:40 +0000 | |||
21 | @@ -27,6 +27,7 @@ | |||
22 | 27 | import logging | 27 | import logging |
23 | 28 | import logstash | 28 | import logstash |
24 | 29 | import os | 29 | import os |
25 | 30 | import os.path | ||
26 | 30 | import socket | 31 | import socket |
27 | 31 | import subprocess | 32 | import subprocess |
28 | 32 | import tarfile | 33 | import tarfile |
29 | @@ -238,11 +239,22 @@ | |||
30 | 238 | 239 | ||
31 | 239 | return ( | 240 | return ( |
32 | 240 | adt_run_args + | 241 | adt_run_args + |
34 | 241 | ['---', 'ssh', '-s', 'uci-nova', '-d'] + | 242 | ['---', 'ssh', '-s', get_uci_nova_path(), '-d'] + |
35 | 242 | adt_ssh_nova_args | 243 | adt_ssh_nova_args |
36 | 243 | ) | 244 | ) |
37 | 244 | 245 | ||
38 | 245 | 246 | ||
39 | 247 | def get_uci_nova_path(): | ||
40 | 248 | return os.path.abspath( | ||
41 | 249 | os.path.join( | ||
42 | 250 | __file__, | ||
43 | 251 | '..', | ||
44 | 252 | '..', | ||
45 | 253 | 'uci-nova' | ||
46 | 254 | ) | ||
47 | 255 | ) | ||
48 | 256 | |||
49 | 257 | |||
50 | 246 | def _set_nova_environment_variables(nova_config): | 258 | def _set_nova_environment_variables(nova_config): |
51 | 247 | """Set environment variables for nova configuration. | 259 | """Set environment variables for nova configuration. |
52 | 248 | 260 | ||
53 | 249 | 261 | ||
54 | === modified file 'adt_cloud_worker/tests/test_cloud_worker.py' | |||
55 | --- adt_cloud_worker/tests/test_cloud_worker.py 2015-04-23 16:22:51 +0000 | |||
56 | +++ adt_cloud_worker/tests/test_cloud_worker.py 2015-04-28 04:25:40 +0000 | |||
57 | @@ -36,6 +36,7 @@ | |||
58 | 36 | _set_nova_environment_variables, | 36 | _set_nova_environment_variables, |
59 | 37 | _validate_request_contents, | 37 | _validate_request_contents, |
60 | 38 | _create_run_metadata_file, | 38 | _create_run_metadata_file, |
61 | 39 | get_uci_nova_path, | ||
62 | 39 | ) | 40 | ) |
63 | 40 | 41 | ||
64 | 41 | 42 | ||
65 | @@ -70,7 +71,7 @@ | |||
66 | 70 | '--output-dir', '/tmp/some/dir', | 71 | '--output-dir', '/tmp/some/dir', |
67 | 71 | '---', | 72 | '---', |
68 | 72 | 'ssh', | 73 | 'ssh', |
70 | 73 | '-s', 'uci-nova', | 74 | '-s', get_uci_nova_path(), |
71 | 74 | '-d', | 75 | '-d', |
72 | 75 | '--', | 76 | '--', |
73 | 76 | '-d', | 77 | '-d', |
74 | @@ -92,7 +93,7 @@ | |||
75 | 92 | '--apt-pocket', 'foo', '--apt-upgrade', | 93 | '--apt-pocket', 'foo', '--apt-upgrade', |
76 | 93 | '---', | 94 | '---', |
77 | 94 | 'ssh', | 95 | 'ssh', |
79 | 95 | '-s', 'uci-nova', | 96 | '-s', get_uci_nova_path(), |
80 | 96 | '-d', | 97 | '-d', |
81 | 97 | '--', | 98 | '--', |
82 | 98 | '-d', | 99 | '-d', |
83 | 99 | 100 | ||
84 | === added file 'uci-nova' | |||
85 | --- uci-nova 1970-01-01 00:00:00 +0000 | |||
86 | +++ uci-nova 2015-04-28 04:25:40 +0000 | |||
87 | @@ -0,0 +1,465 @@ | |||
88 | 1 | #!/bin/sh -eu | ||
89 | 2 | # | ||
90 | 3 | # This script is part of autopkgtest | ||
91 | 4 | # autopkgtest is a tool for testing Debian binary packages | ||
92 | 5 | # | ||
93 | 6 | # This script sets up a nova instance to use as an autopkgtest testbed. It | ||
94 | 7 | # assumes that the host system is already prepared to run nova commands. | ||
95 | 8 | # WARNING: This is mostly a proof of concept and not very robust. | ||
96 | 9 | |||
97 | 10 | # Options: | ||
98 | 11 | # | ||
99 | 12 | # -f flavor | --flavor=flavor | ||
100 | 13 | # Name or ID of flavor (see 'nova flavor-list'), mandatory | ||
101 | 14 | # -i image | --image=image | ||
102 | 15 | # Name or ID of image (see 'nova image-list'), mandatory | ||
103 | 16 | # -N net-id | --net-id=net-id | ||
104 | 17 | # UUID of the network that should be used for the instance | ||
105 | 18 | # -n name | --name=name | ||
106 | 19 | # Name for the new server. A name will be generated if not specified. | ||
107 | 20 | # -m mirror | --mirror=mirror | ||
108 | 21 | # Optional ubuntu archive mirror to override the default. | ||
109 | 22 | # -p proxy_url | --proxy=proxy_url | ||
110 | 23 | # Optional HTTP[S] proxy url to populate testbed environment. | ||
111 | 24 | # -c console-log | --console=file-name | ||
112 | 25 | # Save the nova console-log of the server to the specified file. | ||
113 | 26 | # | ||
114 | 27 | # | ||
115 | 28 | # Authors: | ||
116 | 29 | # Celso Providelo <celso.providelo@canonical.com> | ||
117 | 30 | # | ||
118 | 31 | # | ||
119 | 32 | # autopkgtest is Copyright (C) 2006-2015 Canonical Ltd. | ||
120 | 33 | # | ||
121 | 34 | # This program is free software; you can redistribute it and/or modify | ||
122 | 35 | # it under the terms of the GNU General Public License as published by | ||
123 | 36 | # the Free Software Foundation; either version 2 of the License, or | ||
124 | 37 | # (at your option) any later version. | ||
125 | 38 | # | ||
126 | 39 | # This program is distributed in the hope that it will be useful, | ||
127 | 40 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
128 | 41 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
129 | 42 | # GNU General Public License for more details. | ||
130 | 43 | # | ||
131 | 44 | # You should have received a copy of the GNU General Public License | ||
132 | 45 | # along with this program; if not, write to the Free Software | ||
133 | 46 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
134 | 47 | # | ||
135 | 48 | # See the file CREDITS for a full list of credits information (often | ||
136 | 49 | # installed as /usr/share/doc/autopkgtest/CREDITS). | ||
137 | 50 | set -eu | ||
138 | 51 | |||
139 | 52 | CAPABILITIES='isolation-machine,reboot,revert,revert-full-system' | ||
140 | 53 | |||
141 | 54 | SUDO_PASSWORD='' | ||
142 | 55 | SSH_USER=ubuntu | ||
143 | 56 | |||
144 | 57 | FLAVOR="" | ||
145 | 58 | IMAGE="" | ||
146 | 59 | |||
147 | 60 | SRVNAME="" | ||
148 | 61 | NET_ID="" | ||
149 | 62 | CONSOLE="" | ||
150 | 63 | MIRROR="" | ||
151 | 64 | PROXY="" | ||
152 | 65 | DEBUG="" | ||
153 | 66 | |||
154 | 67 | |||
155 | 68 | debug() { | ||
156 | 69 | [ -z "$DEBUG" ] && return | ||
157 | 70 | echo "$@">&2 | ||
158 | 71 | } | ||
159 | 72 | |||
160 | 73 | warning() { | ||
161 | 74 | echo "$@">&2 | ||
162 | 75 | } | ||
163 | 76 | |||
164 | 77 | error() { | ||
165 | 78 | echo "$@">&2 | ||
166 | 79 | } | ||
167 | 80 | |||
168 | 81 | parse_args() { | ||
169 | 82 | # Parse command line argument and populate environment | ||
170 | 83 | |||
171 | 84 | SHORTOPTS="f:,i:,N:,n:,m:,p:,c:,d" | ||
172 | 85 | LONGOPTS="flavor:,image:,net-id:,name:,mirror:,proxy:,console:,debug" | ||
173 | 86 | |||
174 | 87 | TEMP=$(getopt -o $SHORTOPTS --long $LONGOPTS -- "$@") | ||
175 | 88 | eval set -- "$TEMP" | ||
176 | 89 | |||
177 | 90 | while true; do | ||
178 | 91 | case "$1" in | ||
179 | 92 | -f|--flavor) | ||
180 | 93 | FLAVOR=$2 | ||
181 | 94 | shift 2;; | ||
182 | 95 | -i|--image) | ||
183 | 96 | IMAGE=$2 | ||
184 | 97 | shift 2;; | ||
185 | 98 | -N|--net-id) | ||
186 | 99 | NET_ID="$2" | ||
187 | 100 | shift 2;; | ||
188 | 101 | -n|--name) | ||
189 | 102 | SRVNAME=$2 | ||
190 | 103 | shift 2;; | ||
191 | 104 | -m|--mirror) | ||
192 | 105 | MIRROR=$2 | ||
193 | 106 | shift 2;; | ||
194 | 107 | -p|--proxy) | ||
195 | 108 | PROXY=$2 | ||
196 | 109 | shift 2;; | ||
197 | 110 | -c|--console) | ||
198 | 111 | CONSOLE=$2 | ||
199 | 112 | shift 2;; | ||
200 | 113 | -d|--debug) | ||
201 | 114 | DEBUG=1; shift;; | ||
202 | 115 | --) | ||
203 | 116 | shift; | ||
204 | 117 | break;; | ||
205 | 118 | *) | ||
206 | 119 | error "E: $(basename $0): Unsupported option $1" | ||
207 | 120 | exit 1;; | ||
208 | 121 | esac | ||
209 | 122 | done | ||
210 | 123 | |||
211 | 124 | if [ -z "$FLAVOR" ]; then | ||
212 | 125 | error "Argument 'flavor' is mandatory. Run 'nova flavor-list' to "\ | ||
213 | 126 | "print a list of available flavors." | ||
214 | 127 | exit 1 | ||
215 | 128 | fi | ||
216 | 129 | if [ -z "$IMAGE" ]; then | ||
217 | 130 | error "Argument 'image' is mandatory. Run 'nova image-list' to "\ | ||
218 | 131 | "print a list of available images to boot from." | ||
219 | 132 | exit 1 | ||
220 | 133 | fi | ||
221 | 134 | } | ||
222 | 135 | |||
223 | 136 | security_setup_nova() { | ||
224 | 137 | if ! nova secgroup-create $SRVNAME "$SRVNAME testbed" >/dev/null 2>&1; then | ||
225 | 138 | debug "Could not create specific nova security-group: $SRVNAME" | ||
226 | 139 | exit 1 | ||
227 | 140 | fi | ||
228 | 141 | |||
229 | 142 | if ! nova secgroup-add-rule $SRVNAME tcp 22 22 0.0.0.0/0 >/dev/null 2>&1; then | ||
230 | 143 | debug "Could not allow ingress SSH." | ||
231 | 144 | exit 1 | ||
232 | 145 | fi | ||
233 | 146 | } | ||
234 | 147 | |||
235 | 148 | security_setup_neutron() { | ||
236 | 149 | debug "Creating specific neutron security-group: $SRVNAME" | ||
237 | 150 | neutron security-group-create $SRVNAME \ | ||
238 | 151 | --description "$SRVNAME testbed" | ||
239 | 152 | |||
240 | 153 | debug "Cleaning up default egress rules ..." | ||
241 | 154 | DEFAULT_RULES=$(neutron security-group-rule-list \ | ||
242 | 155 | --format csv -c id -c security_group --quote none \ | ||
243 | 156 | | grep $SRVNAME | cut -d',' -f1) | ||
244 | 157 | for rule_id in $DEFAULT_RULES; do | ||
245 | 158 | neutron security-group-rule-delete $rule_id | ||
246 | 159 | done | ||
247 | 160 | |||
248 | 161 | debug "Allowing ingress SSH ..." | ||
249 | 162 | neutron security-group-rule-create \ | ||
250 | 163 | --direction ingress \ | ||
251 | 164 | --ethertype ipv4 \ | ||
252 | 165 | --protocol tcp \ | ||
253 | 166 | --port-range-min 22 \ | ||
254 | 167 | --port-range-max 22 \ | ||
255 | 168 | --remote-ip-prefix 0.0.0.0/0 \ | ||
256 | 169 | $SRVNAME | ||
257 | 170 | |||
258 | 171 | debug "Allowing DNS egress traffic ..." | ||
259 | 172 | neutron security-group-rule-create \ | ||
260 | 173 | --direction egress \ | ||
261 | 174 | --remote-ip-prefix 8.8.8.8 \ | ||
262 | 175 | $SRVNAME | ||
263 | 176 | |||
264 | 177 | debug "Allowing APT and NTP egress traffic ..." | ||
265 | 178 | neutron security-group-rule-create \ | ||
266 | 179 | --direction egress \ | ||
267 | 180 | --remote-ip-prefix 91.189.88.0/21 \ | ||
268 | 181 | $SRVNAME | ||
269 | 182 | |||
270 | 183 | if [ -n "$PROXY" ]; then | ||
271 | 184 | debug "Allowing internet proxy egress traffic ..." | ||
272 | 185 | proxy_hostname=$(echo $PROXY | sed -e "s/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/") | ||
273 | 186 | if [ $(echo "$proxy_hostname" | grep -E "^[0-9]{1,3}(\.[0-9]{1,3}){3}$") ]; then | ||
274 | 187 | proxy_ip=$proxy_hostname | ||
275 | 188 | else | ||
276 | 189 | proxy_ip=$(host $proxy_hostname | cut -d' ' -f4) | ||
277 | 190 | fi | ||
278 | 191 | |||
279 | 192 | neutron security-group-rule-create \ | ||
280 | 193 | --direction egress \ | ||
281 | 194 | --remote-ip-prefix $proxy_ip/24 \ | ||
282 | 195 | $SRVNAME | ||
283 | 196 | fi | ||
284 | 197 | } | ||
285 | 198 | |||
286 | 199 | # create a testbed (if necessary), configure ssh, copy ssh key into it, | ||
287 | 200 | # configure sudo, etc.; print a list of "key=value" parameters to stdout on | ||
288 | 201 | # success | ||
289 | 202 | open() { | ||
290 | 203 | # Boot a nova instance and returns its connection parameters | ||
291 | 204 | [ -n "$SRVNAME" ] || SRVNAME=`mktemp -u adt-nova-XXXXXX` | ||
292 | 205 | |||
293 | 206 | mkdir /tmp/$SRVNAME | ||
294 | 207 | |||
295 | 208 | debug "Creating new SSH key on /tmp/$SRVNAME" | ||
296 | 209 | SSH_IDENTITY=/tmp/$SRVNAME/id_rsa | ||
297 | 210 | ssh-keygen -f $SSH_IDENTITY -q -N "" | ||
298 | 211 | |||
299 | 212 | debug "Creating specific nova keypair: $SRVNAME" | ||
300 | 213 | nova keypair-add --pub-key $SSH_IDENTITY.pub $SRVNAME | ||
301 | 214 | |||
302 | 215 | # Setup testbed security with nova or neutron according to their | ||
303 | 216 | # availability in the target cloud. | ||
304 | 217 | if type neutron >/dev/null && neutron security-group-list >/dev/null 2>&1; then | ||
305 | 218 | debug "Setting up neutron secgroup" | ||
306 | 219 | security_setup_neutron | ||
307 | 220 | else | ||
308 | 221 | security_setup_nova | ||
309 | 222 | fi | ||
310 | 223 | |||
311 | 224 | # Generate a new apt sources.list using either the specified mirror | ||
312 | 225 | # or the test client's currently configured archive mirror. This includes | ||
313 | 226 | # adding multiverse which is not enabled in our cloud images by default. | ||
314 | 227 | # | ||
315 | 228 | # The following archive_setup uses an awk command to determine the release | ||
316 | 229 | # and archive mirror configured on the test client. $2 will be set to the | ||
317 | 230 | # archive mirror and $3 to the release. These are used before overwriting | ||
318 | 231 | # the test client's /etc/apt/sources.list file. | ||
319 | 232 | if [ -n "${MIRROR}" ]; then | ||
320 | 233 | archive_setup="mirror=${MIRROR}; release=\`awk '/^deb .*(debian|ubuntu)/ { print \$3; exit }' \"\$root/etc/apt/sources.list\"\`; echo \"deb \${mirror} \${release} main restricted universe multiverse\ndeb \${mirror} \${release}-updates main restricted universe multiverse\ndeb-src \${mirror} \${release} main restricted universe multiverse\ndeb-src \${mirror} \${release}-updates main restricted universe multiverse\" > /etc/apt/sources.list" | ||
321 | 234 | else | ||
322 | 235 | archive_setup="mirror_release=\`awk '/^deb .*(debian|ubuntu)/ { print \$2,\$3; exit }' \"\$root/etc/apt/sources.list\"\`; echo \"deb \${mirror_release} main restricted universe multiverse\ndeb \${mirror_release}-updates main restricted universe multiverse\ndeb-src \${mirror_release} main restricted universe multiverse\ndeb-src \${mirror_release}-updates main restricted universe multiverse\" > /etc/apt/sources.list" | ||
323 | 236 | fi | ||
324 | 237 | |||
325 | 238 | # Add a swapfile to extend the amount of RAM available to process. As this | ||
326 | 239 | # is a local file on the boot disk, it does not need any support within the | ||
327 | 240 | # nova flavor. This does consume space on the boot disk and is not ideal | ||
328 | 241 | # from the performance perspective. | ||
329 | 242 | swap_setup="fallocate -l 4G /swapfile; chmod 600 /swapfile; mkswap /swapfile; swapon /swapfile; echo \"/swapfile none swap sw 0 0\" >> /etc/fstab" | ||
330 | 243 | |||
331 | 244 | # Testbed environment setup to be executed by cloud-init. | ||
332 | 245 | # Sets proxy-related environment variables, the local address and the | ||
333 | 246 | # configured archive_host are excluded from http[s] proxying and general | ||
334 | 247 | # http[s] proxying it set according to the user-given --proxy option. | ||
335 | 248 | environment_setup="archive_host=\`awk '/^deb .*(debian|ubuntu)/ { split(\$2, u, \"/\"); print u[3]; exit }' \"\$root/etc/apt/sources.list\"\`; echo \"no_proxy=\\\"localhost,127.0.0.1,localaddress,.localdomain.com,\${archive_host}\\\"\nhttp_proxy=\\\"${PROXY}\\\"\nhttps_proxy=\\\"${PROXY}\\\"\nHTTP_PROXY=\\\"${PROXY}\\\"\nHTTPS_PROXY=\\\"${PROXY}\\\"\" >> /etc/environment" | ||
336 | 249 | |||
337 | 250 | # generate cloud-init user data; mostly for manage_etc_hosts, but also get | ||
338 | 251 | # rid of some unnecessary stuff in the VM | ||
339 | 252 | # | ||
340 | 253 | # NOTE: The "#cloud-config" at the top of this file tells cloud-init that this is | ||
341 | 254 | # a config file, as opposed to a shell script (which must start with "#!"). Don't | ||
342 | 255 | # Do what I did and think "commented out code! DELETE!" and then wonder why nothing | ||
343 | 256 | # works. - Thomi | ||
344 | 257 | local userdata=`mktemp` | ||
345 | 258 | cat <<EOF > $userdata | ||
346 | 259 | #cloud-config | ||
347 | 260 | manage_etc_hosts: true | ||
348 | 261 | apt_update: true | ||
349 | 262 | apt_upgrade: false | ||
350 | 263 | snappy: | ||
351 | 264 | ssh_enabled: True | ||
352 | 265 | |||
353 | 266 | runcmd: | ||
354 | 267 | # Setup archive and do an update after changing the apt sources | ||
355 | 268 | - ${archive_setup} | ||
356 | 269 | - apt-get update | ||
357 | 270 | # Add a swapfile | ||
358 | 271 | - ${swap_setup} | ||
359 | 272 | # Make apt faster: | ||
360 | 273 | - echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/90nolanguages | ||
361 | 274 | - echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/autopkgtest | ||
362 | 275 | # provides kmods like scsi_debug or mac80211_hwsim | ||
363 | 276 | - apt-get install -y linux-generic | ||
364 | 277 | # some tests use a lot of /dev/random, avoid hangs | ||
365 | 278 | - apt-get install -y haveged | ||
366 | 279 | # We need python to run the auxverb helper - install it iff it's missing: | ||
367 | 280 | - if ! sh -c 'type python3 >/dev/null 2>&1 || type python >/dev/null 2>&1'; then apt-get install -y --no-install-recommends python3-minimal; fi | ||
368 | 281 | # Remove some packages we don't need | ||
369 | 282 | - for p in accountsservice apt-xapian-index cryptsetup landscape-client landscape-common open-vm-tools w3m vim-runtime aptitude-common command-not-found-data manpages ntfs-3g sosreport ubuntu-release-upgrader-core; do apt-get --auto-remove -y purge \$p || true; done | ||
370 | 283 | - apt-get clean | ||
371 | 284 | # Do a dist-upgrade: | ||
372 | 285 | - DEBIAN_FRONTEND=noninteractive apt-get -y dist-upgrade | ||
373 | 286 | # Set extra environment variables for testing. | ||
374 | 287 | - ${environment_setup} | ||
375 | 288 | EOF | ||
376 | 289 | |||
377 | 290 | EXTRA_OPTS='' | ||
378 | 291 | if [ -n "$NET_ID" ]; then | ||
379 | 292 | EXTRA_OPTS="$EXTRA_OPTS --nic net-id=$NET_ID" | ||
380 | 293 | fi | ||
381 | 294 | |||
382 | 295 | # Boot the instance | ||
383 | 296 | debug "Creating nova instance $SRVNAME ..." | ||
384 | 297 | OUT=$(nova boot --config-drive=1 \ | ||
385 | 298 | --flavor $FLAVOR --image $IMAGE --user-data $userdata \ | ||
386 | 299 | --key_name $SRVNAME --security-groups $SRVNAME \ | ||
387 | 300 | $EXTRA_OPTS $SRVNAME 2>&1) || { | ||
388 | 301 | error "nova boot failed:" | ||
389 | 302 | error "$OUT" | ||
390 | 303 | exit 1 | ||
391 | 304 | } | ||
392 | 305 | debug "Nova boot succeeded" | ||
393 | 306 | rm $userdata | ||
394 | 307 | |||
395 | 308 | # Find IP address | ||
396 | 309 | ipaddr="" | ||
397 | 310 | retry=60 | ||
398 | 311 | while [ -z "$ipaddr" ]; do | ||
399 | 312 | OUT=$(nova show --minimal $SRVNAME) | ||
400 | 313 | # Check that the instance is in the 'ACTIVE' state before probing for | ||
401 | 314 | # the IP address to avoid awk'ing the wrong field | ||
402 | 315 | if $(echo "$OUT" | grep -q "ACTIVE"); then | ||
403 | 316 | ipaddr=$(echo "$OUT" | awk 'BEGIN {FS="|"} /network/ {n=split($3,i,/,\s*/); gsub(" ", "", i[n]); print i[n]}') | ||
404 | 317 | fi | ||
405 | 318 | retry=$(( retry - 1 )) | ||
406 | 319 | if [ $retry -le 0 ]; then | ||
407 | 320 | error "Failed to acquire an IP address. Aborting!" | ||
408 | 321 | error "$OUT" | ||
409 | 322 | cleanup | ||
410 | 323 | exit 1 | ||
411 | 324 | fi | ||
412 | 325 | sleep 3 | ||
413 | 326 | done | ||
414 | 327 | debug "Finding IP address succeeded: $ipaddr" | ||
415 | 328 | |||
416 | 329 | # purge the device host key so that SSH doesn't print a scary warning | ||
417 | 330 | ssh-keygen -f ~/.ssh/known_hosts -R $ipaddr >/dev/null 2>&1 || true | ||
418 | 331 | |||
419 | 332 | ADT_EXTRA_OPTS="-n $SRVNAME" | ||
420 | 333 | if [ -n "$CONSOLE" ]; then | ||
421 | 334 | ADT_EXTRA_OPTS="$ADT_EXTRA_OPTS -c $CONSOLE" | ||
422 | 335 | fi | ||
423 | 336 | |||
424 | 337 | # Return access information to adt-virt-ssh. | ||
425 | 338 | cat<<EOF | ||
426 | 339 | identity=$SSH_IDENTITY | ||
427 | 340 | login=$SSH_USER | ||
428 | 341 | hostname=$ipaddr | ||
429 | 342 | capabilities=$CAPABILITIES | ||
430 | 343 | extraopts=$ADT_EXTRA_OPTS | ||
431 | 344 | EOF | ||
432 | 345 | if [ -n "$SUDO_PASSWORD" ]; then | ||
433 | 346 | echo "password=$SUDO_PASSWORD" | ||
434 | 347 | fi | ||
435 | 348 | |||
436 | 349 | # wait until ssh is available and cloud-config is done | ||
437 | 350 | debug "Waiting until ssh becomes available" | ||
438 | 351 | SSH="ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /tmp/$SRVNAME/id_rsa -l $SSH_USER $ipaddr" | ||
439 | 352 | retry=60 | ||
440 | 353 | while ! $SSH true; do | ||
441 | 354 | retry=$(( retry - 1 )) | ||
442 | 355 | if [ $retry -le 0 ]; then | ||
443 | 356 | error "Timed out waiting for ssh. Aborting!" | ||
444 | 357 | cleanup | ||
445 | 358 | exit 1 | ||
446 | 359 | fi | ||
447 | 360 | sleep 5 | ||
448 | 361 | done | ||
449 | 362 | |||
450 | 363 | debug "Waiting for cloud-init to finish" | ||
451 | 364 | if ! timeout 30m $SSH 'while [ ! -e /var/lib/cloud/instance/boot-finished ]; do sleep 1; done'; then | ||
452 | 365 | error "Timed out waiting for cloud-init to finish. Aborting!" | ||
453 | 366 | cleanup | ||
454 | 367 | exit 1 | ||
455 | 368 | fi | ||
456 | 369 | |||
457 | 370 | reboot | ||
458 | 371 | |||
459 | 372 | } | ||
460 | 373 | |||
461 | 374 | cleanup() { | ||
462 | 375 | if [ -z "$SRVNAME" ]; then | ||
463 | 376 | error "Cannot determine server name. Instance won't be deleted!" | ||
464 | 377 | exit 0 | ||
465 | 378 | fi | ||
466 | 379 | |||
467 | 380 | if [ -n "$CONSOLE" ]; then | ||
468 | 381 | debug "Saving console-log for $SRVNAME" | ||
469 | 382 | nova console-log $SRVNAME > $CONSOLE | ||
470 | 383 | fi | ||
471 | 384 | |||
472 | 385 | if ! nova delete $SRVNAME >/dev/null 2>&1; then | ||
473 | 386 | error "Could not delete $SRVNAME instance." | ||
474 | 387 | fi | ||
475 | 388 | |||
476 | 389 | if ! nova keypair-delete $SRVNAME >/dev/null 2>&1; then | ||
477 | 390 | error "Could not delete $SRVNAME keypair." | ||
478 | 391 | fi | ||
479 | 392 | |||
480 | 393 | if ! rm -rf /tmp/$SRVNAME >/dev/null 2>&1; then | ||
481 | 394 | debug "Could not delete /tmp/$SRVNAME SSH keys" | ||
482 | 395 | fi | ||
483 | 396 | |||
484 | 397 | DELETE_CMD="neutron security-group-delete $SRVNAME" | ||
485 | 398 | if ! type neutron >/dev/null || ! neutron security-group-list >/dev/null 2>&1; then | ||
486 | 399 | DELETE_CMD="nova secgroup-delete $SRVNAME" | ||
487 | 400 | fi | ||
488 | 401 | |||
489 | 402 | debug "Deleting $SRVNAME security-group" | ||
490 | 403 | retry=3 | ||
491 | 404 | while ! eval "$DELETE_CMD" >/dev/null 2>&1; do | ||
492 | 405 | retry=$(( retry - 1 )) | ||
493 | 406 | if [ $retry -le 0 ]; then | ||
494 | 407 | error "Timed out deleting secgroup. Aborting!" | ||
495 | 408 | cleanup | ||
496 | 409 | exit 1 | ||
497 | 410 | fi | ||
498 | 411 | sleep 5 | ||
499 | 412 | done | ||
500 | 413 | |||
501 | 414 | SRVNAME="" | ||
502 | 415 | } | ||
503 | 416 | |||
504 | 417 | revert() { | ||
505 | 418 | if [ -z "$SRVNAME" ]; then | ||
506 | 419 | echo "Needs to be called with -n <server name>" >&2 | ||
507 | 420 | exit 1 | ||
508 | 421 | fi | ||
509 | 422 | cleanup | ||
510 | 423 | open | ||
511 | 424 | } | ||
512 | 425 | |||
513 | 426 | reboot() { | ||
514 | 427 | if [ -z "$SRVNAME" ]; then | ||
515 | 428 | error "Cannot determine server name. Instance won't be rebooted!" | ||
516 | 429 | exit 1 | ||
517 | 430 | fi | ||
518 | 431 | |||
519 | 432 | nova reboot --poll $SRVNAME >/dev/null 2>&1||true | ||
520 | 433 | } | ||
521 | 434 | |||
522 | 435 | # ######################################## | ||
523 | 436 | # Main procedure | ||
524 | 437 | # | ||
525 | 438 | if [ $# -eq 0 ]; then | ||
526 | 439 | error "Invalid number of arguments, command is missing" | ||
527 | 440 | exit 1 | ||
528 | 441 | fi | ||
529 | 442 | cmd=$(echo $1|tr [[:upper:]] [[:lower:]]) | ||
530 | 443 | shift | ||
531 | 444 | parse_args "$@" | ||
532 | 445 | |||
533 | 446 | # Don't leave stuff behind ... | ||
534 | 447 | trap "cleanup" 1 2 6 15 | ||
535 | 448 | |||
536 | 449 | case $cmd in | ||
537 | 450 | open) | ||
538 | 451 | open;; | ||
539 | 452 | cleanup) | ||
540 | 453 | cleanup;; | ||
541 | 454 | revert) | ||
542 | 455 | revert;; | ||
543 | 456 | reboot) | ||
544 | 457 | reboot;; | ||
545 | 458 | '') | ||
546 | 459 | echo "Needs to be called with command as first argument" >&2 | ||
547 | 460 | exit 1 | ||
548 | 461 | ;; | ||
549 | 462 | *) | ||
550 | 463 | echo "invalid command $cmd" >&2 | ||
551 | 464 | exit 1 | ||
552 | 465 | esac |
Approve. This is consistent with the same change performed for lp:core-image-tester.