tripleo-ci/scripts/te-broker/destroy-env

82 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
set -xe
ENVNUM=${1:-$(date +%s)}
PROVISIONNET=provision-${ENVNUM}
PUBLICNET=public-${ENVNUM}
ENVFILE=env-${ENVNUM}-base.yaml
COMPUTE_ENVFILE=env-${ENVNUM}-compute.yaml
EXTRA_ENVFILE=env-${ENVNUM}-extra.yaml
rm -f /opt/stack/openstack-virtual-baremetal/$ENVFILE
rm -f /opt/stack/openstack-virtual-baremetal/env-${ENVNUM}.yaml
rm -f /opt/stack/openstack-virtual-baremetal/$COMPUTE_ENVFILE
rm -f /opt/stack/openstack-virtual-baremetal/$EXTRA_ENVFILE
rm -f /opt/stack/openstack-virtual-baremetal/temp-key-$ENVNUM.pub
set +x
source /etc/nodepoolrc
set -x
# NOTE(bnemec): This function starts the port deletions in the background.
# To ensure they complete before you proceed, you must call "wait" after
# calling this function.
function delete_ports {
local subnetid=${1:-}
if [ -z "$subnetid" ]; then
return
fi
for PORT in $(neutron port-list | grep $subnetid | awk '{print $2}') ; do
neutron port-delete $PORT &
done
}
# Save the end of the bmc log for debugging IPMI connectivity problems
PYTHONIOENCODING='utf-8'
CONSOLE_LOG_PATH=/var/www/html/tebroker/console-logs/
nova console-log bmc-${ENVNUM} | tail -n 100 | awk -v envnum="$ENVNUM" '$0=envnum ": " $0' >> /var/log/bmc-console-logs
# Save all the consoles in the stack to a dedicated directory, stripping out ANSI color codes.
for server in $(openstack server list -f value -c Name | grep baremetal-${ENVNUM}) bmc-$ENVNUM ; do
openstack console log show $server | sed 's/\[[0-9;]*[a-zA-Z]//g' | gzip > $CONSOLE_LOG_PATH/$server-console.log.gz || true
done
# Delete the ports that have been attached to the undercloud
SUBNETID=$(neutron subnet-show $PUBLICNET | awk '$2=="id" {print $4}' || echo '')
delete_ports $SUBNETID
SUBNETID=$(neutron subnet-show $PROVISIONNET | awk '$2=="id" {print $4}')
delete_ports $SUBNETID
# Needed to ensure all ports have been deleted before we delete the heat stack
wait
# If there was a keypair for this specific run, delete it.
openstack keypair delete "tripleo-ci-key-$ENVNUM" || true
function delete_stack {
local stackname=$1
# Nothing to do if the specified stack doesn't exist
if ! heat stack-show $stackname; then
return 0
fi
# NOTE(bnemec): I'm periodically seeing the stack-delete fail to connect to
# Heat. It looks like a transient network issue, so let's just retry when it happens.
for i in $(seq 10); do
heat stack-delete -y $stackname && break
sleep 5
done
while heat stack-show $stackname 2>&1 > /dev/null ; do
# If the delete failed, try again
if heat stack-show $stackname | grep DELETE_FAILED ; then
heat stack-delete -y $stackname || true
fi
sleep 20
done
}
# Extra role stacks must be deleted first
delete_stack baremetal_${ENVNUM}-extra
delete_stack baremetal_${ENVNUM}-compute
delete_stack baremetal_${ENVNUM}