Merge "Clean redundant error logs of refstack_defcore in the console"
[functest.git] / functest / ci / check_os.sh
1 #!/bin/bash
2 #
3 # Simple script to check the basic OpenStack clients
4 #
5 # Author:
6 #    jose.lausuch@ericsson.com
7 #
8
9 declare -A service_cmd_array
10 service_cmd_array['nova']='openstack server list'
11 service_cmd_array['neutron']='openstack network list'
12 service_cmd_array['keystone']='openstack endpoint list'
13 service_cmd_array['cinder']='openstack volume list'
14 service_cmd_array['glance']='openstack image list'
15
16 MANDATORY_SERVICES='nova neutron keystone glance'
17 OPTIONAL_SERVICES='cinder'
18
19 verify_connectivity() {
20     for i in $(seq 0 9); do
21         if echo "test" | nc -v -w 10 $1 $2 &>/dev/null; then
22             return 0
23         fi
24         sleep 1
25     done
26     return 1
27 }
28
29 verify_SSL_connectivity() {
30     openssl s_client -connect $1:$2 &>/dev/null
31     return $?
32 }
33
34 check_service() {
35     local service cmd
36     service=$1
37     cmd=${service_cmd_array[$service]}
38     if [ -z "$2" ]; then
39         required='false'
40     else
41         required=$2
42     fi
43     echo ">>Checking ${service} service..."
44     if ! openstack service list | grep -i ${service} > /dev/null; then
45         if [ "$required" == 'false' ]; then
46             echo "WARN: Optional Service ${service} is not enabled!"
47             return
48         else
49             echo "ERROR: Required Service ${service} is not enabled!"
50             exit 1
51         fi
52     fi
53     $cmd &>/dev/null
54     result=$?
55     if [ $result -ne 0 ]; then
56         echo "ERROR: Failed execution $cmd. The $service does not seem to be working."
57         exit 1
58     else
59         echo "  ...OK"
60     fi
61 }
62
63 if [ -z $OS_AUTH_URL ];then
64     echo "ERROR: OS_AUTH_URL environment variable missing... Have you sourced the OpenStack credentials?"
65     exit 1
66 fi
67
68
69 echo "Checking OpenStack endpoints:"
70 publicURL=$(openstack catalog show  identity |awk '/public/ {print $4}')
71 publicIP=$(echo $publicURL|sed 's/^.*http.*\:\/\///'|sed 's/.[^:]*$//')
72 publicPort=$(echo $publicURL|sed 's/^.*://'|sed 's/\/.*$//')
73 https_enabled=$(echo $publicURL | grep 'https')
74 if [[ -n $https_enabled ]]; then
75     echo ">>Verifying SSL connectivity to the public endpoint $publicIP:$publicPort..."
76     verify_SSL_connectivity $publicIP $publicPort
77 else
78     echo ">>Verifying connectivity to the public endpoint $publicIP:$publicPort..."
79     verify_connectivity $publicIP $publicPort
80 fi
81 RETVAL=$?
82 if [ $RETVAL -ne 0 ]; then
83     echo "ERROR: Cannot talk to the public endpoint $publicIP:$publicPort ."
84     echo "OS_AUTH_URL=$OS_AUTH_URL"
85     exit 1
86 fi
87 echo "  ...OK"
88
89 adminURL=$(openstack catalog show  identity |awk '/admin/ {print $4}')
90 if [ -z ${adminURL} ]; then
91     echo "ERROR: Cannot determine the admin URL."
92     openstack catalog show identity
93     exit 1
94 fi
95 adminIP=$(echo $adminURL|sed 's/^.*http.*\:\/\///'|sed 's/.[^:]*$//')
96 adminPort=$(echo $adminURL|sed 's/^.*://'|sed 's/.[^\/]*$//')
97 https_enabled=$(echo $adminURL | grep 'https')
98 if [[ -n $https_enabled ]]; then
99     echo ">>Verifying SSL connectivity to the admin endpoint $adminIP:$adminPort..."
100     verify_SSL_connectivity $adminIP $adminPort
101 else
102     echo ">>Verifying connectivity to the admin endpoint $adminIP:$adminPort..."
103     verify_connectivity $adminIP $adminPort
104 fi
105 RETVAL=$?
106 if [ $RETVAL -ne 0 ]; then
107     echo "ERROR: Cannot talk to the admin endpoint $adminIP:$adminPort ."
108     echo "$adminURL"
109     exit 1
110 fi
111 echo "  ...OK"
112
113
114 echo "Checking Required OpenStack services:"
115 for service in $MANDATORY_SERVICES; do
116     check_service $service "true"
117 done
118 echo "Required OpenStack services are OK."
119
120 echo "Checking Optional OpenStack services:"
121 for service in $OPTIONAL_SERVICES; do
122     check_service $service
123 done
124
125 echo "Checking External network..."
126 networks=($(neutron net-list -F id | tail -n +4 | head -n -1 | awk '{print $2}'))
127 is_external=False
128 for net in "${networks[@]}"
129 do
130     is_external=$(neutron net-show $net|grep "router:external"|awk '{print $4}')
131     if [ $is_external == "True" ]; then
132         echo "External network found: $net"
133         break
134     fi
135 done
136 if [ $is_external == "False" ]; then
137     echo "ERROR: There are no external networks in the deployment."
138     exit 1
139 fi
140
141 exit 0