Add the choice of interface for keystoneclient
[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|grep -Po '(?<=:)\d+')
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
90 echo "Checking Required OpenStack services:"
91 for service in $MANDATORY_SERVICES; do
92     check_service $service "true"
93 done
94 echo "Required OpenStack services are OK."
95
96 echo "Checking Optional OpenStack services:"
97 for service in $OPTIONAL_SERVICES; do
98     check_service $service
99 done
100
101 echo "Checking External network..."
102 networks=($(neutron net-list -F id | tail -n +4 | head -n -1 | awk '{print $2}'))
103 is_external=False
104 for net in "${networks[@]}"
105 do
106     is_external=$(neutron net-show $net|grep "router:external"|awk '{print $4}')
107     if [ $is_external == "True" ]; then
108         echo "External network found: $net"
109         break
110     fi
111 done
112 if [ $is_external == "False" ]; then
113     echo "ERROR: There are no external networks in the deployment."
114     exit 1
115 fi
116
117 exit 0