Remove hardcoded IP in check_os
[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 if [ -z $OS_AUTH_URL ];then
10     echo "ERROR: OS_AUTH_URL environment variable missing... Have you sourced the OpenStack credentials?"
11     exit 1
12 fi
13
14 echo "Checking OpenStack basic services:"
15
16 ip=$(echo $OS_AUTH_URL|sed 's/^.*http\:\/\///'|sed 's/.[^:]*$//')
17 echo ">>Pinging public keystone endpoint $ip..."
18 timeout=5
19 for i in `seq 1 $timeout`; do
20     ping -q -c 1 $ip &>/dev/null
21     RETVAL=$?
22     if [ $RETVAL -eq 0 ]; then
23         break
24     fi
25 done
26 if [ $i -eq $timeout ]; then
27     echo "ERROR: Cannot ping the endpoint $ip defined as env variable OS_AUTH_URL."
28     echo "OS_AUTH_URL=$OS_AUTH_URL"
29     exit 1
30 fi
31 echo "  ...OK"
32
33 commands=('keystone endpoint-list' 'nova list' 'neutron net-list' \
34             'glance image-list' 'cinder list')
35 for cmd in "${commands[@]}"
36 do
37     service=$(echo $cmd | awk '{print $1}')
38     echo ">>Checking $service service..."
39     $cmd &>/dev/null
40     result=$?
41     if [ $result -ne 0 ];
42     then
43
44         echo "ERROR: Failed execution $cmd. The $service does not seem to be working."
45         exit 1
46     else
47         echo "  ...OK"
48     fi
49 done
50
51 echo "OpenStack services are OK."
52 exit 0