Merge "Use repos_dir env variable in all Functest scripts"
[functest.git] / testcases / VIM / OpenStack / CI / libraries / 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 10); do
11         if nc -vz $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=$(keystone catalog --service identity 2>/dev/null|grep adminURL|awk '{print $4}')
41 adminIP=$(echo $adminURL|sed 's/^.*http\:\/\///'|sed 's/.[^:]*$//')
42 adminPort=$(echo $adminURL|sed 's/^.*://'|sed 's/.[^\/]*$//')
43 echo ">>Verifying connectivity to the admin endpoint $adminIP:$adminPort..."
44 verify_connectivity $adminIP $adminPort
45 RETVAL=$?
46 if [ $RETVAL -ne 0 ]; then
47     echo "ERROR: Cannot talk to the admin endpoint adminIP:$adminPort ."
48     echo "adminURL"
49     exit 1
50 fi
51 echo "  ...OK"
52
53
54 echo "Checking OpenStack basic services:"
55 commands=('keystone endpoint-list' 'nova list' 'neutron net-list' \
56             'glance image-list' 'cinder list')
57 for cmd in "${commands[@]}"
58 do
59     service=$(echo $cmd | awk '{print $1}')
60     echo ">>Checking $service service..."
61     $cmd &>/dev/null
62     result=$?
63     if [ $result -ne 0 ];
64     then
65
66         echo "ERROR: Failed execution $cmd. The $service does not seem to be working."
67         exit 1
68     else
69         echo "  ...OK"
70     fi
71 done
72
73 echo "OpenStack services are OK."
74 exit 0