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

Proposed by Thomi Richards on 2015-04-28
Status: Merged
Approved by: Celso Providelo on 2015-04-28
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 on 2015-04-28
Francis Ginther 2015-04-28 Approve on 2015-04-28
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.
Francis Ginther (fginther) wrote :

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

review: Approve
Paul Larson (pwlars) :
review: Approve
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 on 2015-04-28

fix tests.

Preview Diff

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

Subscribers

People subscribed via source and target branches

to all changes: