1e69d12945cabc83bad78ad071552f2ab336e5b9
[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 # Kill the locally running operators
19 if [ "${BMO_RUN_LOCAL}" = true ]; then
20   kill "$(pgrep "operator-sdk")" 2> /dev/null || true
21 fi
22 if [ "${CAPBM_RUN_LOCAL}" = true ]; then
23   CAPBM_PARENT_PID="$(pgrep -f "go run ./cmd/manager/main.go")"
24   if [[ "${CAPBM_PARENT_PID}" != "" ]]; then
25     CAPBM_GO_PID="$(pgrep -P "${CAPBM_PARENT_PID}" )"
26     kill "${CAPBM_GO_PID}"  2> /dev/null || true
27   fi
28 fi
29
30
31 ANSIBLE_FORCE_COLOR=true ansible-playbook \
32     -e "working_dir=$WORKING_DIR" \
33     -e "num_masters=$NUM_MASTERS" \
34     -e "num_workers=$NUM_WORKERS" \
35     -e "extradisks=$VM_EXTRADISKS" \
36     -e "virthost=$HOSTNAME" \
37     -e "manage_baremetal=$MANAGE_BR_BRIDGE" \
38     -i vm-setup/inventory.ini \
39     -b -vvv vm-setup/teardown-playbook.yml
40
41 sudo rm -rf /etc/NetworkManager/conf.d/dnsmasq.conf
42 # There was a bug in this file, it may need to be recreated.
43 if [ "$MANAGE_PRO_BRIDGE" == "y" ]; then
44     sudo ip link set dev provisioning down || true
45     sudo rm -f /etc/sysconfig/network-scripts/ifcfg-provisioning || true
46 fi
47 # Leaving this around causes issues when the host is rebooted
48 if [ "$MANAGE_BR_BRIDGE" == "y" ]; then
49     sudo ip link set dev baremetal down || true
50     sudo rm -f /etc/sysconfig/network-scripts/ifcfg-baremetal || true
51 fi
52
53 rm -rf $WORKING_DIR
54 rm -rf $IRONIC_DATA_DIR