Merge "Exclude SNAPS smoke for lxd scenario"
[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 check_service() {
30     local service cmd
31     service=$1
32     cmd=${service_cmd_array[$service]}
33     if [ -z "$2" ]; then
34         required='false'
35     else
36         required=$2
37     fi
38     echo ">>Checking ${service} service..."
39     if ! openstack service list | grep -i ${service} > /dev/null; then
40         if [ "$required" == 'false' ]; then
41             echo "WARN: Optional Service ${service} is not enabled!"
42             return
43         else
44             echo "ERROR: Required Service ${service} is not enabled!"
45             exit 1
46         fi
47     fi
48     $cmd &>/dev/null
49     result=$?
50     if [ $result -ne 0 ]; then
51         echo "ERROR: Failed execution $cmd. The $service does not seem to be working."
52         exit 1
53     else
54         echo "  ...OK"
55     fi
56 }
57
58 if [ -z $OS_AUTH_URL ];then
59     echo "ERROR: OS_AUTH_URL environment variable missing... Have you sourced the OpenStack credentials?"
60     exit 1
61 fi
62
63
64 echo "Checking OpenStack endpoints:"
65 publicURL=$(openstack catalog show  identity |awk '/public/ {print $4}')
66 publicIP=$(echo $publicURL|sed 's/^.*http\:\/\///'|sed 's/.[^:]*$//')
67 publicPort=$(echo $publicURL|sed 's/^.*://'|sed 's/\/.*$//')
68 echo ">>Verifying connectivity to the public endpoint $publicIP:$publicPort..."
69 verify_connectivity $publicIP $publicPort
70 RETVAL=$?
71 if [ $RETVAL -ne 0 ]; then
72     echo "ERROR: Cannot talk to the public endpoint $publicIP:$publicPort ."
73     echo "OS_AUTH_URL=$OS_AUTH_URL"
74     exit 1
75 fi
76 echo "  ...OK"
77
78 adminURL=$(openstack catalog show  identity |awk '/admin/ {print $4}')
79 if [ -z ${adminURL} ]; then
80     echo "ERROR: Cannot determine the admin URL."
81     openstack catalog show identity
82     exit 1
83 fi
84 adminIP=$(echo $adminURL|sed 's/^.*http\:\/\///'|sed 's/.[^:]*$//')
85 adminPort=$(echo $adminURL|sed 's/^.*://'|sed 's/.[^\/]*$//')
86 echo ">>Verifying connectivity to the admin endpoint $adminIP:$adminPort..."
87 verify_connectivity $adminIP $adminPort
88 RETVAL=$?
89 if [ $RETVAL -ne 0 ]; then
90     echo "ERROR: Cannot talk to the admin endpoint $adminIP:$adminPort ."
91     echo "$adminURL"
92     exit 1
93 fi
94 echo "  ...OK"
95
96
97 echo "Checking Required OpenStack services:"
98 for service in $MANDATORY_SERVICES; do
99     check_service $service "true"
100 done
101 echo "Required OpenStack services are OK."
102
103 echo "Checking Optional OpenStack services:"
104 for service in $OPTIONAL_SERVICES; do
105     check_service $service
106 done
107
108 echo "Checking External network..."
109 networks=($(neutron net-list -F id | tail -n +4 | head -n -1 | awk '{print $2}'))
110 is_external=False
111 for net in "${networks[@]}"
112 do
113     is_external=$(neutron net-show $net|grep "router:external"|awk '{print $4}')
114     if [ $is_external == "True" ]; then
115         echo "External network found: $net"
116         break
117     fi
118 done
119 if [ $is_external == "False" ]; then
120     echo "ERROR: There are no external networks in the deployment."
121     exit 1
122 fi
123
124 exit 0