Merge lp:~thomir-deactivatedaccount/adt-cloud-worker/trunk-inine-uci-nova into lp:adt-cloud-worker

Proposed by Thomi Richards
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
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).

To post a comment you must log in.
Revision history for this message
Francis Ginther (fginther) wrote :

Approve. This is consistent with the same change performed for lp:core-image-tester.

review: Approve
Revision history for this message
Paul Larson (pwlars) :
review: Approve
Revision history for this message
Ubuntu CI Bot (uci-bot) wrote :
Download full text (23.1 KiB)

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-adt-cloud-workerko5r1052/bin/python3
Also creating executable in /tmp/venv-adt-cloud-workerko5r1052/bin/python
Installing setuptools, pip...done.
Running virtualenv with interpreter /usr/bin/python3
Ignoring indexes: https://pypi.python.org/simple/
Downloading/unpacking kombu==3.0.24 (from -r requirements.txt (line 1))
Downloading/unpacking python-keystoneclient==1.2.0 (from -r requirements.txt (line 2))
Downloading/unpacking python-logstash==0.4.2 (from -r requirements.txt (line 3))
  Running setup.py (path:/tmp/venv-adt-cloud-workerko5r1052/build/python-logstash/setup.py) egg_info for package python-logstash

Downloading/unpacking python-novaclient==2.22.0 (from -r requirements.txt (line 4))
Downloading/unpacking python-swiftclient==2.3.1 (from -r requirements.txt (line 5))
Downloading/unpacking anyjson>=0.3.3 (from kombu==3.0.24->-r requirements.txt (line 1))
  Running setup.py (path:/tmp/venv-adt-cloud-workerko5r1052/build/anyjson/setup.py) egg_info for package anyjson

Downloading/unpacking amqp>=1.4.5,<2.0 (from kombu==3.0.24->-r requirements.txt (line 1))
  Running setup.py (path:/tmp/venv-adt-cloud-workerko5r1052/build/amqp/setup.py) egg_info for package amqp

Downloading/unpacking argparse (from python-keystoneclient==1.2.0->-r requirements.txt (line 2))
Downloading/unpacking netaddr>=0.7.12 (from python-keystoneclient==1.2.0->-r requirements.txt (line 2))
Downloading/unpacking Babel>=1.3 (from python-keystoneclient==1.2.0->-r requirements.txt (line 2))
  Running setup.py (path:/tmp/venv-adt-cloud-workerko5r1052/build/Babel/setup.py) egg_info for package Babel

    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/unpacking oslo.i18n>=1.3.0 (from python-keystoneclient==1.2.0->-r requirements.txt (line 2))
Downloading/unpacking PrettyTable>=0.7,<0.8 (from python-keystoneclient==1.2.0->-r requirements.txt (line 2))
  Running setup.py (path:/tmp/venv-adt-cloud-workerko5r1052/build/PrettyTable/setup.py) egg_info for package PrettyTable

Downloading/unpacking iso8601>=0.1.9 (from python-keystoneclient==1.2.0->-r requirements.txt (line 2))
Downloading/unpacking requests>=2.2.0,!=2.4.0 (from python-keystoneclient==1.2.0->-r requirements.txt (line 2))
Downloading/unpacking oslo.utils>=1.2.0 (from python-keystoneclient==1.2.0->-r requirements.txt (line 2))
Downloading/unpacking six>=1.9.0 (from python-keystoneclient==1.2.0->-r requirements.txt (line 2))
Downloading/unpacking oslo.serialization>=1.2.0 (from python-keystoneclient==1.2.0->-r requirements.txt (line 2))
Downloading/unpacking stevedore>=1.1.0 (from python-keystoneclient==1.2.0->-r requirements.txt (line 2))
Downloading/unpacking pbr>=0.6,!=0.7,<1.0 (from python-keystoneclient==1.2.0->-r requirements.txt (line 2))
Downloading/unpacking o...

40. By Thomi Richards

fix tests.

Preview Diff

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

Subscribers

People subscribed via source and target branches

to all changes: