7d3db90b0513b93fdb54923b939223ad41b82d56
[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 # Delete all VMs on the slave since proposed patchsets
18 # may leave undesired VM leftovers
19 for vm in $(virsh list --all --name); do
20     virsh destroy $vm || true
21     virsh undefine $vm || true
22 done
23 # Delete all hosts from vbmc (look for a port number)
24 for vm in $(vbmc list | awk '/[0-9]/{{ print $2 }}'); do
25     vbmc delete $vm
26 done
27
28 service ironic-conductor stop || true
29
30 echo "removing inventory files created by previous builds"
31 rm -rf /tmp/baremetal.*
32
33 echo "removing ironic database"
34 if $(which mysql &> /dev/null); then
35     mysql -u root ironic --execute "drop database ironic;"
36 fi
37 echo "removing leases"
38 [[ -e /var/lib/misc/dnsmasq/dnsmasq.leases ]] && > /var/lib/misc/dnsmasq/dnsmasq.leases
39 echo "removing logs"
40 rm -rf /var/log/libvirt/baremetal_logs/*
41
42 # clean up dib images only if requested explicitly
43 CLEAN_DIB_IMAGES=${CLEAN_DIB_IMAGES:-false}
44
45 if [ $CLEAN_DIB_IMAGES = "true" ]; then
46     rm -rf /httpboot /tftpboot
47     mkdir /httpboot /tftpboot
48     chmod -R 755 /httpboot /tftpboot
49 fi
50
51 # remove VM disk images
52 rm -rf /var/lib/libvirt/images/*.qcow2
53
54 echo "restarting services"
55 service dnsmasq restart || true
56 service libvirtd restart
57 service ironic-api restart || true
58 service ironic-conductor start || true
59 service ironic-inspector restart || true