Reworking nova clean since now its doing more than just network cleaning.

This commit is contained in:
Joshua Harlow 2012-02-13 18:07:57 -08:00
parent a06220a9ec
commit ada954d82d
3 changed files with 48 additions and 29 deletions
conf/templates/nova
devstack/components

@ -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

@ -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

@ -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')