Added unit tests for vping.
[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 if [[ ${OS_INSECURE,,} == "true" ]]; then
10     options='--insecure'
11 else
12     options=''
13 fi
14
15 declare -A service_cmd_array
16 service_cmd_array['nova']="openstack $options server list"
17 service_cmd_array['neutron']="openstack $options network list"
18 service_cmd_array['keystone']="openstack $options endpoint list"
19 service_cmd_array['cinder']="openstack $options volume list"
20 service_cmd_array['glance']="openstack $options image list"
21
22 MANDATORY_SERVICES='nova neutron keystone glance'
23 OPTIONAL_SERVICES='cinder'
24
25 verify_connectivity() {
26     for i in $(seq 0 9); do
27         if echo "test" | nc -v -w 10 $1 $2 &>/dev/null; then
28             return 0
29         fi
30         sleep 1
31     done
32     return 1
33 }
34
35 verify_SSL_connectivity() {
36     openssl s_client -connect $1:$2 &>/dev/null
37     return $?
38 }
39
40 check_service() {
41     local service cmd
42     service=$1
43     cmd=${service_cmd_array[$service]}
44     if [ -z "$2" ]; then
45         required='false'
46     else
47         required=$2
48     fi
49     echo ">>Checking ${service} service..."
50     if ! openstack $options service list | grep -i ${service} > /dev/null; then
51         if [ "$required" == 'false' ]; then
52             echo "WARN: Optional Service ${service} is not enabled!"
53             return
54         else
55             echo "ERROR: Required Service ${service} is not enabled!"
56             exit 1
57         fi
58     fi
59     $cmd &>/dev/null
60     result=$?
61     if [ $result -ne 0 ]; then
62         echo "ERROR: Failed execution $cmd. The $service does not seem to be working."
63         exit 1
64     else
65         echo "  ...OK"
66     fi
67 }
68
69 if [ -z $OS_AUTH_URL ];then
70     echo "ERROR: OS_AUTH_URL environment variable missing... Have you sourced the OpenStack credentials?"
71     exit 1
72 fi
73
74
75 echo "Checking OpenStack endpoints:"
76 publicURL=$(openstack $options catalog show identity |awk '/public/ {print $4}')
77 publicIP=$(echo $publicURL|sed 's/^.*http.*\:\/\///'|sed 's/.[^:]*$//')
78 publicPort=$(echo $publicURL|grep -Po '(?<=:)\d+')
79 https_enabled=$(echo $publicURL | grep 'https')
80 if [[ -n $https_enabled ]]; then
81     echo ">>Verifying SSL connectivity to the public endpoint $publicIP:$publicPort..."
82     verify_SSL_connectivity $publicIP $publicPort
83 else
84     echo ">>Verifying connectivity to the public endpoint $publicIP:$publicPort..."
85     verify_connectivity $publicIP $publicPort
86 fi
87 RETVAL=$?
88 if [ $RETVAL -ne 0 ]; then
89     echo "ERROR: Cannot talk to the public endpoint $publicIP:$publicPort ."
90     echo "OS_AUTH_URL=$OS_AUTH_URL"
91     exit 1
92 fi
93 echo "  ...OK"
94
95
96 echo "Checking Required OpenStack services:"
97 for service in $MANDATORY_SERVICES; do
98     check_service $service "true"
99 done
100 echo "Required OpenStack services are OK."
101
102 echo "Checking Optional OpenStack services:"
103 for service in $OPTIONAL_SERVICES; do
104     check_service $service
105 done
106
107 echo "Checking External network..."
108 networks=($(neutron $options net-list -F id | tail -n +4 | head -n -1 | awk '{print $2}'))
109 is_external=False
110 for net in "${networks[@]}"
111 do
112     is_external=$(neutron $options net-show $net|grep "router:external"|awk '{print $4}')
113     if [ $is_external == "True" ]; then
114         echo "External network found: $net"
115         break
116     fi
117 done
118 if [ $is_external == "False" ]; then
119     echo "ERROR: There are no external networks in the deployment."
120     exit 1
121 fi
122
123 exit 0