From ada954d82d5fc36cae60cb1427721bf6935a3bb5 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 13 Feb 2012 18:07:57 -0800 Subject: [PATCH] Reworking nova clean since now its doing more than just network cleaning. --- conf/templates/nova/nova-clean-network.sh.tpl | 24 ------------- conf/templates/nova/nova-clean.sh.tpl | 36 +++++++++++++++++++ devstack/components/nova.py | 17 ++++++--- 3 files changed, 48 insertions(+), 29 deletions(-) delete mode 100644 conf/templates/nova/nova-clean-network.sh.tpl create mode 100644 conf/templates/nova/nova-clean.sh.tpl diff --git a/conf/templates/nova/nova-clean-network.sh.tpl b/conf/templates/nova/nova-clean-network.sh.tpl deleted file mode 100644 index 7cf43ab5..00000000 --- a/conf/templates/nova/nova-clean-network.sh.tpl +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -# This script cleans up the network as part of a nova uninstall - -# Eventually it should be moved to python code... - -# Ignore any errors from shutting down dnsmasq -# TODO shouldn't this be a service shutdown?? -killall dnsmasq - -# This was added (so that it dies on errors) -set -o errexit - -# Delete rules -iptables -S -v | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-A" | sed "s/-A/-D/g" | awk '{print "sudo iptables",$0}' | bash - -# Delete nat rules -iptables -S -v -t nat | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-A" | sed "s/-A/-D/g" | awk '{print "sudo iptables -t nat",$0}' | bash - -# Delete chains -iptables -S -v | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-N" | sed "s/-N/-X/g" | awk '{print "sudo iptables",$0}' | bash - -# Delete nat chains -iptables -S -v -t nat | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-N" | sed "s/-N/-X/g" | awk '{print "sudo iptables -t nat",$0}' | bash diff --git a/conf/templates/nova/nova-clean.sh.tpl b/conf/templates/nova/nova-clean.sh.tpl new file mode 100644 index 00000000..4b3ed989 --- /dev/null +++ b/conf/templates/nova/nova-clean.sh.tpl @@ -0,0 +1,36 @@ +#!/bin/bash + +# This script cleans up the system as part of a nova uninstall + +# Eventually it should be moved to python code... + +# This was added (so that it dies on errors) +set -o errexit + +if [[ "$ENABLED_SERVICES" =~ "net" ]]; then + + # Ignore any errors from shutting down dnsmasq + # TODO shouldn't this be a service shutdown?? + killall dnsmasq || true + + # Delete rules + iptables -S -v | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-A" | sed "s/-A/-D/g" | awk '{print "sudo iptables",$0}' | bash + + # Delete nat rules + iptables -S -v -t nat | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-A" | sed "s/-A/-D/g" | awk '{print "sudo iptables -t nat",$0}' | bash + + # Delete chains + iptables -S -v | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-N" | sed "s/-N/-X/g" | awk '{print "sudo iptables",$0}' | bash + + # Delete nat chains + iptables -S -v -t nat | sed "s/-c [0-9]* [0-9]* //g" | grep "nova" | grep "\-N" | sed "s/-N/-X/g" | awk '{print "sudo iptables -t nat",$0}' | bash + +fi + +if [[ "$ENABLED_SERVICES" =~ "vol" ]]; then + + # Logout and delete iscsi sessions + iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d " " -f2 | xargs sudo iscsiadm --mode node --logout || true + iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d " " -f2 | sudo iscsiadm --mode node --op delete || true + +fi diff --git a/devstack/components/nova.py b/devstack/components/nova.py index 84e3b6dd..68afddcf 100644 --- a/devstack/components/nova.py +++ b/devstack/components/nova.py @@ -178,7 +178,7 @@ QUANTUM_OPENSWITCH_OPS = { } #this is a special conf -CLEANER_DATA_CONF = 'nova-clean-network.sh' +CLEANER_DATA_CONF = 'nova-clean.sh' CLEANER_CMD_ROOT = [sh.joinpths("/", "bin", 'bash')] #pip files that nova requires @@ -192,13 +192,20 @@ class NovaUninstaller(comp.PythonUninstallComponent): self.cfgdir = sh.joinpths(self.appdir, CONFIG_DIR) def pre_uninstall(self): - self._clear_iptables() self._clear_libvirt_domains() + self._clean_it() - def _clear_iptables(self): - LOG.info("Cleaning up iptables.") + def _clean_it(self): + LOG.info("Cleaning up your system.") + #these environment additions are important + #in that they eventually affect how this script runs + sub_components = self.component_opts or SUBCOMPONENTS + env = dict() + env['ENABLED_SERVICES'] = ",".join(sub_components) + env['BIN_DIR'] = self.bindir + env['VOLUME_NAME_PREFIX'] = self.cfg.get('nova', 'volume_name_prefix') cmd = CLEANER_CMD_ROOT + [sh.joinpths(self.bindir, CLEANER_DATA_CONF)] - sh.execute(*cmd, run_as_root=True) + sh.execute(*cmd, run_as_root=True, env_overrides=env) def _clear_libvirt_domains(self): virt_driver = self.cfg.get('nova', 'virt_driver')