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