prototypes: bifrost: Add keystone roles
[releng.git] / prototypes / bifrost / scripts / destroy-env.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 RedHat and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 # We need to execute everything as root
12 if [[ $(whoami) != "root" ]]; then
13     echo "Error: This script must be run as root!"
14     exit 1
15 fi
16
17 # Start fresh
18 rm -rf /opt/stack
19 # HOME is normally set by sudo -H
20 rm -rf ${HOME}/.config/openstack
21
22 # Delete all libvirt VMs and hosts from vbmc (look for a port number)
23 for vm in $(vbmc list | awk '/[0-9]/{{ print $2 }}'); do
24     virsh destroy $vm || true
25     virsh undefine $vm || true
26     vbmc delete $vm
27 done
28
29 service ironic-conductor stop || true
30
31 echo "removing inventory files created by previous builds"
32 rm -rf /tmp/baremetal.*
33
34 echo "removing ironic database"
35 if $(which mysql &> /dev/null); then
36     mysql -u root ironic --execute "drop database ironic;"
37 fi
38 echo "removing leases"
39 [[ -e /var/lib/misc/dnsmasq/dnsmasq.leases ]] && > /var/lib/misc/dnsmasq/dnsmasq.leases
40 echo "removing logs"
41 rm -rf /var/log/libvirt/baremetal_logs/*
42
43 # clean up dib images only if requested explicitly
44 CLEAN_DIB_IMAGES=${CLEAN_DIB_IMAGES:-false}
45
46 if [ $CLEAN_DIB_IMAGES = "true" ]; then
47     rm -rf /httpboot /tftpboot
48     mkdir /httpboot /tftpboot
49     chmod -R 755 /httpboot /tftpboot
50 fi
51
52 # remove VM disk images
53 rm -rf /var/lib/libvirt/images/*.qcow2
54
55 echo "restarting services"
56 service dnsmasq restart || true
57 service libvirtd restart
58 service ironic-api restart || true
59 service ironic-conductor start || true
60 service ironic-inspector restart || true