162b145cae3fb0b1a05577d211c57d8a94c3da6a
[openstack-build/cinder-build.git] / tests / runtests.sh
1 #! /bin/bash
2
3 set -o xtrace
4
5 EC=0
6 MYSQL_PASSWORD="cinder"
7
8 update_ec(){
9   local ec=$1
10   [ "$ec" -gt "$EC" ] && EC=$ec
11 }
12
13
14 function prepare_vm(){
15   if [[ $(cat /etc/*-release | head -n 1 | awk '{print $1}') =~ Ubuntu ]]
16   then
17     echo "mysql-server mysql-server/root_password select $MYSQL_PASSWORD" |
18       debconf-set-selections
19     echo "mysql-server mysql-server/root_password_again select $MYSQL_PASSWORD" |
20       debconf-set-selections
21     apt-get install -y mysql-server python-mysqldb rabbitmq-server curl screen nmap
22   else
23     yum install -y mysql-server mysql-wsrep-client-5.6 MySQL-python nmap-ncat
24     # workaround for `sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError)
25     # (2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)")`
26     rm -f /etc/my.cnf
27     local current_password=$(cat /root/.mysql_secret | head -1 | awk -F': ' '{print $2}')
28     service mysql start
29     mysqladmin -u root -p"$current_password" password "$MYSQL_PASSWORD"
30   fi
31   mysql -uroot -p"$MYSQL_PASSWORD" << MYSQL_SCRIPT
32 CREATE DATABASE cinder;
33 CREATE USER 'cinder'@'localhost' IDENTIFIED BY '$MYSQL_PASSWORD';
34 GRANT ALL PRIVILEGES ON *.* TO 'cinder'@'localhost';
35 MYSQL_SCRIPT
36   cinder-manage --config-file /usr/share/cinder/cinder-dist.conf db sync
37 }
38
39
40 function test_cinder_service(){
41   local service=$1
42   local port=$2
43
44   echo "Starting $1..."
45   service "$service" start
46
47   sleep 5
48   echo | ncat -w 5 localhost "$port"
49   local ec=$?
50   update_ec "$ec"
51
52   if [ "$ec" -eq 0 ]
53   then
54     echo "Cinder $1 successfully started"
55   else
56     echo "$service failed to start!"
57     tail -n 40 /var/log/messages
58   fi
59 }
60
61
62 function test_cinder_configs(){
63   local files=("/etc/cinder/cinder.conf"
64                "/etc/cinder/api-paste.ini"
65                "/etc/cinder/policy.json")
66   for f in "${files[@]}"
67   do
68     [ -f "$f" ] ; update_ec "$?"
69   done
70 }
71
72
73 case $1 in
74   python-cinder)
75     local imports=("cinder"
76                    "cinder.volume.drivers.lvm"
77                    "cinder.volume.drivers.rbd")
78     for x in "${imports[@]}"
79     do
80       python -c "import $x" ; update_ec "$?"
81     done
82   ;;
83   openstack-cinder)
84     prepare_vm
85     test_cinder_configs
86     ls /usr/bin/cinder* ; update_ec "$?"
87     test_cinder_service openstack-cinder-api 8776 ; update_ec "$?"
88     [ -f "/usr/bin/cinder-volume" ] ; update_ec "$?"
89     [ -f "/usr/bin/cinder-scheduler" ] ; update_ec "$?"
90   ;;
91   cinder-common)
92     test_cinder_configs
93     [ -f "/usr/bin/cinder-manage" ] ; update_ec "$?"
94   ;;
95   cinder-scheduler)
96     [ -f "/usr/bin/cinder-scheduler" ] ; update_ec "$?"
97   ;;
98   cinder-api)
99     EC=0
100     # Should be fixed with next update of Ubuntu package.  
101     # prepare_vm
102     # [ -f "/usr/bin/cinder-api" ] ; update_ec "$?"
103     # test_cinder_service cinder-api 8776 ; update_ec "$?"
104   ;;
105   cinder-volume)
106     [ -f "/usr/bin/cinder-volume" ] ; update_ec "$?"
107   ;;
108   cinder-backup)
109     [ -f "/usr/bin/cinder-backup" ] ; update_ec "$?"
110   ;;
111   cinder-doc|openstack-cinder-doc)
112     echo "Skipping test for $1"
113     EC=0
114   ;;
115   *)
116     echo "Test not defined for $1"
117     EC=1
118   ;;
119 esac
120
121 exit "$EC"