online bottlenecks soak throughtputs
[releng.git] / utils / get_sdn_type.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
4 # jose.lausuch@ericsson.com
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
12 CMD_ODL="/opt/opendaylight/bin/client -u karaf info 2>/dev/null | grep -i opendaylight | wc -l"
13 CMD_ONOS="/opt/opendaylight/bin/client -u karaf info 2>/dev/null | grep -i onos | wc -l"
14 CMD_CONTRAIL="/opt/opendaylight/bin/client -u karaf info 2>/dev/null | grep -i contrail | wc -l"
15
16 usage() {
17     echo "usage: $0 -i <installer_type> -a <installer_ip>" >&2
18 }
19
20 info ()  {
21     logger -s -t "get_sdn_type.info" "$*"
22 }
23
24
25 error () {
26     logger -s -t "get_sdn_type.error" "$*"
27     exit 1
28 }
29
30
31 verify_connectivity() {
32     local ip=$1
33     info "Verifying connectivity to $ip..."
34     for i in $(seq 0 10); do
35         if ping -c 1 -W 1 $ip > /dev/null; then
36             info "$ip is reachable!"
37             return 0
38         fi
39         sleep 1
40     done
41     error "Can not talk to $ip."
42 }
43
44
45
46 #Get options
47 while getopts ":d:i:a:h:" optchar; do
48     case "${optchar}" in
49         i) installer_type=${OPTARG} ;;
50         a) installer_ip=${OPTARG} ;;
51         *) echo "Non-option argument: '-${OPTARG}'" >&2
52            usage
53            exit 2
54            ;;
55     esac
56 done
57
58 # set vars from env if not provided by user as options
59 installer_type=${installer_type:-$INSTALLER_TYPE}
60 installer_ip=${installer_ip:-$INSTALLER_IP}
61
62 if [ -z $installer_type ] || [ -z $installer_ip ]; then
63     usage
64     exit 2
65 fi
66
67
68 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
69
70 # Start fetching the files
71 if [ "$installer_type" == "fuel" ]; then
72     #ip_fuel="10.20.0.2"
73     verify_connectivity $installer_ip
74
75     # Check if controller is alive (online='True')
76     controller_ips=$(sshpass -p r00tme ssh 2>/dev/null $ssh_options root@${installer_ip} \
77         'fuel node | grep controller | grep True | awk "{print \$10}"') &> /dev/null
78
79     if [ -z "$controller_ips" ]; then
80         error "Controller IPs not found. Please check that the POD is correctly deployed."
81     fi
82
83
84     info "Checking Karaf in each controller..."
85     for ip in $controller_ips;
86     do
87         info "Checking type of controller ${ip}.."
88         result=$(sshpass -p r00tme ssh 2>/dev/null $ssh_options root@${installer_ip} \
89         "ssh ${ssh_options} ${ip} ${CMD_ODL}")
90         if [ $result -gt 0 ]; then
91             info "ODL controller found!"
92             exit 0
93         fi
94         result=$(sshpass -p r00tme ssh 2>/dev/null $ssh_options root@${installer_ip} \
95         "ssh ${ssh_options} ${ip} ${CMD_ONOS}")
96         if [ $result -gt 0 ]; then
97             info "ONOS controller found!"
98             exit 0
99         fi
100         result=$(sshpass -p r00tme ssh 2>/dev/null $ssh_options root@${installer_ip} \
101         "ssh ${ssh_options} ${ip} ${CMD_CONTRAIL}")
102         if [ $result -gt 0 ]; then
103             info "OpenContrail controller found!"
104             exit 0
105         fi
106     done
107     info "None of the 3 supported controllers has been found."
108
109 elif [ "$installer_type" == "apex" ]; then
110     echo "not implemented"
111
112 elif [ "$installer_type" == "compass" ]; then
113     echo "not implemented"
114
115 elif [ "$installer_type" == "joid" ]; then
116     echo "not implemented"
117
118
119 else
120     error "Installer $installer is not supported by this script"
121 fi
122
123
124
125 exit 0