Check for errors by default in scripts
[icn.git] / deploy / metal3-vm / 05_host_cleanup.sh
1 #!/usr/bin/env bash
2 set -eux -o pipefail
3
4 # shellcheck disable=SC1091
5 source lib/logging.sh
6 # shellcheck disable=SC1091
7 source lib/common.sh
8
9 BMO_RUN_LOCAL="${BMO_RUN_LOCAL:-false}"
10 CAPBM_RUN_LOCAL="${CAPBM_RUN_LOCAL:-false}"
11
12 # Kill and remove the running ironic containers
13 for name in ironic ironic-inspector dnsmasq httpd mariadb ipa-downloader; do
14     sudo "${CONTAINER_RUNTIME}" ps | grep -w "$name$" && sudo "${CONTAINER_RUNTIME}" kill $name
15     sudo "${CONTAINER_RUNTIME}" ps --all | grep -w "$name$" && sudo "${CONTAINER_RUNTIME}" rm $name -f
16 done
17
18 # Remove existing pod
19 if [[ "${CONTAINER_RUNTIME}" == "podman" ]]; then
20   if  sudo "${CONTAINER_RUNTIME}" pod exists ironic-pod ; then
21       sudo "${CONTAINER_RUNTIME}" pod rm ironic-pod -f
22   fi
23 fi
24
25 # Kill the locally running operators
26 if [ "${BMO_RUN_LOCAL}" = true ]; then
27   kill "$(pgrep "operator-sdk")" 2> /dev/null || true
28 fi
29 if [ "${CAPBM_RUN_LOCAL}" = true ]; then
30   CAPBM_PARENT_PID="$(pgrep -f "go run ./cmd/manager/main.go")"
31   if [[ "${CAPBM_PARENT_PID}" != "" ]]; then
32     CAPBM_GO_PID="$(pgrep -P "${CAPBM_PARENT_PID}" )"
33     kill "${CAPBM_GO_PID}"  2> /dev/null || true
34   fi
35 fi
36
37
38 ANSIBLE_FORCE_COLOR=true ansible-playbook \
39     -e "working_dir=$WORKING_DIR" \
40     -e "num_masters=$NUM_MASTERS" \
41     -e "num_workers=$NUM_WORKERS" \
42     -e "extradisks=$VM_EXTRADISKS" \
43     -e "virthost=$HOSTNAME" \
44     -e "manage_baremetal=$MANAGE_BR_BRIDGE" \
45     -i vm-setup/inventory.ini \
46     -b -vvv vm-setup/teardown-playbook.yml
47
48 sudo rm -rf /etc/NetworkManager/conf.d/dnsmasq.conf
49 # There was a bug in this file, it may need to be recreated.
50 if [ "$MANAGE_PRO_BRIDGE" == "y" ]; then
51     sudo ifdown provisioning || true
52     sudo rm -f /etc/sysconfig/network-scripts/ifcfg-provisioning || true
53 fi
54 # Leaving this around causes issues when the host is rebooted
55 if [ "$MANAGE_BR_BRIDGE" == "y" ]; then
56     sudo ifdown baremetal || true
57     sudo rm -f /etc/sysconfig/network-scripts/ifcfg-baremetal || true
58 fi
59
60 rm -rf $WORKING_DIR
61 rm -rf $IRONIC_DATA_DIR