From e47cdad33ce29f7db4e0cb72c323ed63504afe16 Mon Sep 17 00:00:00 2001 From: Markos Chandras Date: Mon, 19 Mar 2018 16:22:47 +0000 Subject: xci: Move cleanup script outside of bifrost The cleanup script has grown quite a bit over time and it now does more things than cleaning up old 'bifrost' artifacts to move it to the global files directory so it can be used by all installers. Change-Id: Ibf70ff255f14e798216cedc71fb7c5f5476b964a Signed-off-by: Markos Chandras --- xci/files/xci-destroy-env.sh | 78 ++++++++++++++++++++++++++++++++ xci/infra/bifrost/infra-provision.sh | 4 -- xci/infra/bifrost/scripts/destroy-env.sh | 78 -------------------------------- xci/xci-deploy.sh | 11 +++++ 4 files changed, 89 insertions(+), 82 deletions(-) create mode 100755 xci/files/xci-destroy-env.sh delete mode 100755 xci/infra/bifrost/scripts/destroy-env.sh diff --git a/xci/files/xci-destroy-env.sh b/xci/files/xci-destroy-env.sh new file mode 100755 index 00000000..9d53dc15 --- /dev/null +++ b/xci/files/xci-destroy-env.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# SPDX-license-identifier: Apache-2.0 +############################################################################## +# Copyright (c) 2016 RedHat and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# We need to execute everything as root +if [[ $(whoami) != "root" ]]; then + echo "Error: This script must be run as root!" + exit 1 +fi + +# Start fresh +rm -rf /opt/stack +# HOME is normally set by sudo -H +rm -rf ${HOME}/.config/openstack +rm -rf ${HOME}/.ansible + +# bifrost installs everything on venv so we need to look there if virtualbmc is not installed on the host. +if which vbmc &>/dev/null || { [[ -e /opt/stack/bifrost/bin/activate ]] && source /opt/stack/bifrost/bin/activate; }; then + # Delete all libvirt VMs and hosts from vbmc (look for a port number) + for vm in $(vbmc list | awk '/[0-9]/{{ print $2 }}'); do + if which virsh &>/dev/null; then + virsh destroy $vm || true + virsh undefine $vm || true + fi + vbmc delete $vm + done + which vbmc &>/dev/null || { [[ -e /opt/stack/bifrost/bin/activate ]] && deactivate; } +fi + +# Destroy all XCI VMs if the previous operation failed +[[ -n ${XCI_FLAVOR} ]] && \ + for vm in ${TEST_VM_NODE_NAMES}; do + if which virsh &>/dev/null; then + virsh destroy $vm || true + virsh undefine $vm || true + fi + done + +service ironic-conductor stop || true + +echo "removing inventory files created by previous builds" +rm -rf /tmp/baremetal.* + +echo "removing ironic database" +if $(which mysql &> /dev/null); then + mysql_ironic_user=$(sudo grep "connection" /etc/ironic/ironic.conf | cut -d : -f 2 ) + msyql_ironic_password=$(sudo grep "connection" /etc/ironic/ironic.conf | cut -d : -f 3) + mysql -u${mysql_ironic_user#*//} -p${msyql_ironic_password%%@*} --execute "drop database ironic;" +fi +echo "removing leases" +[[ -e /var/lib/misc/dnsmasq/dnsmasq.leases ]] && > /var/lib/misc/dnsmasq/dnsmasq.leases +echo "removing logs" +rm -rf /var/log/libvirt/baremetal_logs/* + +# clean up dib images by default +CLEAN_DIB_IMAGES=${CLEAN_DIB_IMAGES:-true} + +if [ $CLEAN_DIB_IMAGES = "true" ]; then + rm -rf /httpboot /tftpboot + mkdir /httpboot /tftpboot + chmod -R 755 /httpboot /tftpboot +fi + +# remove VM disk images +rm -rf /var/lib/libvirt/images/*.qcow2 + +echo "restarting services" +service dnsmasq restart || true +service libvirtd restart +service ironic-api restart || true +service ironic-conductor start || true +service ironic-inspector restart || true diff --git a/xci/infra/bifrost/infra-provision.sh b/xci/infra/bifrost/infra-provision.sh index f847e66d..9c3adfc2 100644 --- a/xci/infra/bifrost/infra-provision.sh +++ b/xci/infra/bifrost/infra-provision.sh @@ -12,10 +12,6 @@ BIFROST_ROOT_DIR="$(dirname $(realpath ${BASH_SOURCE[0]}))" echo "Info: Starting provisining VM nodes using openstack/bifrost" echo "-------------------------------------------------------------------------" -# We are using sudo so we need to make sure that env_reset is not present -sudo sed -i "s/^Defaults.*env_reset/#&/" /etc/sudoers -cd $BIFROST_ROOT_DIR -sudo -E bash ./scripts/destroy-env.sh cd $BIFROST_ROOT_DIR/playbooks/ ansible-playbook ${XCI_ANSIBLE_PARAMS} -i "localhost," bootstrap-bifrost.yml cd ${XCI_CACHE}/repos/bifrost diff --git a/xci/infra/bifrost/scripts/destroy-env.sh b/xci/infra/bifrost/scripts/destroy-env.sh deleted file mode 100755 index 9d53dc15..00000000 --- a/xci/infra/bifrost/scripts/destroy-env.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/bash -# SPDX-license-identifier: Apache-2.0 -############################################################################## -# Copyright (c) 2016 RedHat and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -# We need to execute everything as root -if [[ $(whoami) != "root" ]]; then - echo "Error: This script must be run as root!" - exit 1 -fi - -# Start fresh -rm -rf /opt/stack -# HOME is normally set by sudo -H -rm -rf ${HOME}/.config/openstack -rm -rf ${HOME}/.ansible - -# bifrost installs everything on venv so we need to look there if virtualbmc is not installed on the host. -if which vbmc &>/dev/null || { [[ -e /opt/stack/bifrost/bin/activate ]] && source /opt/stack/bifrost/bin/activate; }; then - # Delete all libvirt VMs and hosts from vbmc (look for a port number) - for vm in $(vbmc list | awk '/[0-9]/{{ print $2 }}'); do - if which virsh &>/dev/null; then - virsh destroy $vm || true - virsh undefine $vm || true - fi - vbmc delete $vm - done - which vbmc &>/dev/null || { [[ -e /opt/stack/bifrost/bin/activate ]] && deactivate; } -fi - -# Destroy all XCI VMs if the previous operation failed -[[ -n ${XCI_FLAVOR} ]] && \ - for vm in ${TEST_VM_NODE_NAMES}; do - if which virsh &>/dev/null; then - virsh destroy $vm || true - virsh undefine $vm || true - fi - done - -service ironic-conductor stop || true - -echo "removing inventory files created by previous builds" -rm -rf /tmp/baremetal.* - -echo "removing ironic database" -if $(which mysql &> /dev/null); then - mysql_ironic_user=$(sudo grep "connection" /etc/ironic/ironic.conf | cut -d : -f 2 ) - msyql_ironic_password=$(sudo grep "connection" /etc/ironic/ironic.conf | cut -d : -f 3) - mysql -u${mysql_ironic_user#*//} -p${msyql_ironic_password%%@*} --execute "drop database ironic;" -fi -echo "removing leases" -[[ -e /var/lib/misc/dnsmasq/dnsmasq.leases ]] && > /var/lib/misc/dnsmasq/dnsmasq.leases -echo "removing logs" -rm -rf /var/log/libvirt/baremetal_logs/* - -# clean up dib images by default -CLEAN_DIB_IMAGES=${CLEAN_DIB_IMAGES:-true} - -if [ $CLEAN_DIB_IMAGES = "true" ]; then - rm -rf /httpboot /tftpboot - mkdir /httpboot /tftpboot - chmod -R 755 /httpboot /tftpboot -fi - -# remove VM disk images -rm -rf /var/lib/libvirt/images/*.qcow2 - -echo "restarting services" -service dnsmasq restart || true -service libvirtd restart -service ironic-api restart || true -service ironic-conductor start || true -service ironic-inspector restart || true diff --git a/xci/xci-deploy.sh b/xci/xci-deploy.sh index fb678ec5..80b10106 100755 --- a/xci/xci-deploy.sh +++ b/xci/xci-deploy.sh @@ -85,6 +85,9 @@ unset user_local_dev_vars local_user_var # register our handler trap submit_bug_report ERR +# We are using sudo so we need to make sure that env_reset is not present +sudo sed -i "s/^Defaults.*env_reset/#&/" /etc/sudoers + #------------------------------------------------------------------------------- # Log info to console #------------------------------------------------------------------------------- @@ -102,6 +105,14 @@ echo "openstack/bifrost version: $OPENSTACK_BIFROST_VERSION" [[ "$INFRA_DEPLOYMENT" == "bifrost" ]] && echo "bifrost version: $OPENSTACK_BIFROST_VERSION" echo "-------------------------------------------------------------------------" +#------------------------------------------------------------------------------- +# Clean up environment +#------------------------------------------------------------------------------- +echo "Info: Cleaning up previous XCI artifacts" +echo "-------------------------------------------------------------------------" +sudo -E bash files/xci-destroy-env.sh +echo "-------------------------------------------------------------------------" + #------------------------------------------------------------------------------- # Install ansible on localhost #------------------------------------------------------------------------------- -- cgit 1.2.3-korg