053796d9884e270d366a5358c13a2ece19bf36ff
[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 verify_connectivity() {
10     for i in $(seq 0 9); do
11         if echo "test" | nc -v -w 10 $1 $2 &>/dev/null; then
12             return 0
13         fi
14         sleep 1
15     done
16     return 1
17 }
18
19
20 if [ -z $OS_AUTH_URL ];then
21     echo "ERROR: OS_AUTH_URL environment variable missing... Have you sourced the OpenStack credentials?"
22     exit 1
23 fi
24
25
26 echo "Checking OpenStack endpoints:"
27 publicURL=$OS_AUTH_URL
28 publicIP=$(echo $publicURL|sed 's/^.*http\:\/\///'|sed 's/.[^:]*$//')
29 publicPort=$(echo $publicURL|sed 's/^.*://'|sed 's/\/.*$//')
30 echo ">>Verifying connectivity to the public endpoint $publicIP:$publicPort..."
31 verify_connectivity $publicIP $publicPort
32 RETVAL=$?
33 if [ $RETVAL -ne 0 ]; then
34     echo "ERROR: Cannot talk to the public endpoint $publicIP:$publicPort ."
35     echo "OS_AUTH_URL=$OS_AUTH_URL"
36     exit 1
37 fi
38 echo "  ...OK"
39
40 adminURL=$(openstack catalog show  identity |awk '/admin/ {print $4}')
41 if [ -z ${adminURL} ]; then
42     echo "ERROR: Cannot determine the admin URL."
43     openstack catalog show identity
44     exit 1
45 fi
46 adminIP=$(echo $adminURL|sed 's/^.*http\:\/\///'|sed 's/.[^:]*$//')
47 adminPort=$(echo $adminURL|sed 's/^.*://'|sed 's/.[^\/]*$//')
48 echo ">>Verifying connectivity to the admin endpoint $adminIP:$adminPort..."
49 verify_connectivity $adminIP $adminPort
50 RETVAL=$?
51 if [ $RETVAL -ne 0 ]; then
52     echo "ERROR: Cannot talk to the admin endpoint $adminIP:$adminPort ."
53     echo "$adminURL"
54     exit 1
55 fi
56 echo "  ...OK"
57
58
59 echo "Checking OpenStack basic services:"
60 commands=('openstack endpoint list' 'nova list' 'neutron net-list' \
61             'glance image-list' 'cinder list')
62 for cmd in "${commands[@]}"
63 do
64     service=$(echo $cmd | awk '{print $1}')
65     echo ">>Checking $service service..."
66     $cmd &>/dev/null
67     result=$?
68     if [ $result -ne 0 ];
69     then
70         echo "ERROR: Failed execution $cmd. The $service does not seem to be working."
71         exit 1
72     else
73         echo "  ...OK"
74     fi
75 done
76
77 echo "OpenStack services are OK."
78
79 echo "Checking External network..."
80 networks=($(neutron net-list -F id | tail -n +4 | head -n -1 | awk '{print $2}'))
81 is_external=False
82 for net in "${networks[@]}"
83 do
84     is_external=$(neutron net-show $net|grep "router:external"|awk '{print $4}')
85     if [ $is_external == "True" ]; then
86         echo "External network found: $net"
87         break
88     fi
89 done
90 if [ $is_external == "False" ]; then
91     echo "ERROR: There are no external networks in the deployment."
92     exit 1
93 fi
94
95 exit 0