enable vhostuser for ovs-dpdk scenario
[apex.git] / ci / clean.sh
1 #!/usr/bin/env bash
2 ##############################################################################
3 # Copyright (c) 2015 Tim Rozet (Red Hat), Dan Radez (Red Hat) and others.
4 #
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 #Clean script to uninstall provisioning server for Apex
12 #author: Dan Radez (dradez@redhat.com)
13 #author: Tim Rozet (trozet@redhat.com)
14
15 # Use default if no param passed
16 CONFIG=${CONFIG:-'/var/opt/opnfv'}
17 RESOURCES=${RESOURCES:-"$CONFIG/images"}
18 LIB=${LIB:-"$CONFIG/lib"}
19 reset=$(tput sgr0 || echo "")
20 blue=$(tput setaf 4 || echo "")
21 red=$(tput setaf 1 || echo "")
22 green=$(tput setaf 2 || echo "")
23
24 ##LIBRARIES
25 for lib in common-functions parse-functions; do
26   if ! source $LIB/${lib}.sh; then
27     echo "Failed to source $LIB/${lib}.sh"
28     exit 1
29   fi
30 done
31
32 vm_index=4
33 ovs_bridges="br-admin br-private br-public br-storage"
34 OPNFV_NETWORK_TYPES="admin_network private_network public_network storage_network api_network"
35
36
37 display_usage() {
38   echo -e "Usage:\n$0 [arguments] \n"
39   echo -e "   -i|--inventory : Full path to inventory yaml file. Required only for baremetal node clean"
40 }
41
42 ##translates the command line parameters into variables
43 ##params: $@ the entire command line is passed
44 ##usage: parse_cmd_line() "$@"
45 parse_cmdline() {
46   echo -e "\n\n${blue}This script is used to deploy the Apex Installer and Provision OPNFV Target System${reset}\n\n"
47   echo "Use -h to display help"
48   sleep 2
49
50   while [ "${1:0:1}" = "-" ]
51   do
52     case "$1" in
53         -h|--help)
54                 display_usage
55                 exit 0
56             ;;
57         -i|--inventory)
58                 INVENTORY_FILE=$2
59                 shift 2
60             ;;
61         *)
62                 display_usage
63                 exit 1
64             ;;
65     esac
66   done
67
68   if [[ ! -z "$INVENTORY_FILE" && ! -f "$INVENTORY_FILE" ]]; then
69     echo -e "{$red}ERROR: Inventory File: ${INVENTORY_FILE} does not exist! Exiting...${reset}"
70     exit 1
71   fi
72 }
73
74 parse_cmdline "$@"
75
76 if [ -n "$INVENTORY_FILE" ]; then
77   echo -e "${blue}INFO: Parsing inventory file...${reset}"
78   if ! python3.4 -B $LIB/python/apex_python_utils.py clean -f ${INVENTORY_FILE}; then
79     echo -e "${red}WARN: Unable to shutdown all nodes! Please check /var/log/apex.log${reset}"
80   else
81     echo -e "${blue}INFO: Node shutdown complete...${reset}"
82   fi
83 fi
84
85 # Clean off instack/undercloud VM
86 for vm in instack undercloud; do
87   virsh destroy $vm 2> /dev/null | xargs echo -n
88   virsh undefine $vm 2> /dev/null | xargs echo -n
89   /usr/bin/touch /var/lib/libvirt/images/${vm}.qcow2
90   virsh vol-delete ${vm}.qcow2 --pool default 2> /dev/null | xargs echo -n
91   rm -f /var/lib/libvirt/images/${vm}.qcow2 2> /dev/null
92 done
93
94 # Clean off baremetal VMs in case they exist
95 for i in $(seq 0 $vm_index); do
96   virsh destroy baremetal$i 2> /dev/null | xargs echo -n
97   virsh undefine baremetal$i 2> /dev/null | xargs echo -n
98   /usr/bin/touch /var/lib/libvirt/images/baremetal${i}.qcow2
99   virsh vol-delete baremetal${i}.qcow2 --pool default 2> /dev/null | xargs echo -n
100   rm -f /var/lib/libvirt/images/baremetal${i}.qcow2 2> /dev/null
101 done
102
103 for network in ${OPNFV_NETWORK_TYPES}; do
104   virsh net-destroy ${network} 2> /dev/null
105   virsh net-undefine ${network} 2> /dev/null
106 done
107
108 # Clean off created bridges
109 for bridge in ${ovs_bridges}; do
110   if detach_interface_from_ovs ${bridge} 2> /dev/null; then
111     ovs-vsctl del-br ${bridge} 2> /dev/null
112     rm -f /etc/sysconfig/network-scripts/ifcfg-${bridge}
113   fi
114 done
115
116 # clean pub keys from root's auth keys
117 sed -i '/stack@undercloud.localdomain/d' /root/.ssh/authorized_keys
118 sed -i '/virtual-power-key/d' /root/.ssh/authorized_keys
119
120
121 # force storage cleanup
122 virsh pool-refresh default
123
124 # remove temporary files
125 rm -f /tmp/network-environment.yaml
126
127 echo "Cleanup Completed"