d26c49f187c2c65abebaa7c59b748fbb05ce20c8
[openstack-build/cinder-build.git] / tests / runtests.sh
1 #!/bin/bash -x
2 echo "Testing $1"
3
4 RES=0
5
6
7 function test_cinder_service(){
8   echo "Starting Cinder $1..."
9   /etc/init.d/$1 start
10   sleep 5
11
12   if [ "$1" == "api" ]; then
13     service_running=`netstat -nat | grep $2 | wc -l`
14   else
15       service_running=`ps -Af | grep cinder-$2 | wc -l`
16   fi
17
18   if [ service_running ]; then
19     echo "Cinder API successfully started"
20     /etc/init.d/$1 stop
21   else
22     echo "Can not start Cinder $1 service"
23     RES=1
24   fi
25 }
26
27
28 function check_file_exists(){
29   if [ ! -f "$1" ]; then
30     RES=1
31   fi
32 }
33
34
35 function test_cinder_configs(){
36   declare -a files=("/etc/cinder/cinder.conf" "/etc/cinder/api-paste.ini" "/etc/cinder/policy.json")
37   for f in "${files[@]}"
38   do
39     check_file_exists "$f"
40  done
41 }
42
43
44 case $1 in
45   python-cinder)
46     declare -a imports=("cinder" "cinder.volume.drivers.lvm" "cinder.volume.drivers.rbd")
47     for i in "${imports[@]}"
48     do
49       python -c "import $i"
50       if [ $? -ne 0 ]; then
51         RES=1
52         break
53       fi
54     done
55   ;;
56   openstack-cinder)
57     test_cinder_configs
58
59     count=`ls -1 /usr/bin/cinder* 2>/dev/null | wc -l`
60     if [ $count -eq 0 ]; then
61         RES=1
62     fi
63
64     test_cinder_service openstack-cinder-api 8776
65     test_cinder_service openstack-cinder-volume
66     test_cinder_service openstack-cinder-scheduler
67   ;;
68   cinder-common)
69     test_cinder_configs
70     check_file_exists "/usr/bin/cinder-manage"
71   ;;
72   cinder-scheduler)
73     check_file_exists "/usr/bin/cinder-scheduler"
74     test_cinder_service cinder-scheduler
75   ;;
76   cinder-api)
77     check_file_exists "/usr/bin/cinder-api"
78     test_cinder_service cinder-api 8776
79   ;;
80   cinder-volume)
81     check_file_exists "/usr/bin/cinder-api"
82     test_cinder_service cinder-volume
83   ;;
84   openstack-cinder-doc)
85     echo "No test for docs defined"
86   ;;
87   *)
88     echo "Test is not defined, skipping..."
89   ;;
90 esac
91
92 exit $RES