[MOS 10.0] Update cinder to v9.0.0.0b1
[openstack-build/cinder-build.git] / tests / runtests.sh
index 2084b49cf11c52f1d2a408eaa842b69a20e59f2c..e71eafe563452262770da2854375520da13b4d8e 100755 (executable)
-#!/bin/bash -x
-echo "Testing $1"
+#! /bin/bash
+
+set -o xtrace
+
+EC=0
+MYSQL_PASSWORD="cinder"
+
+update_ec(){
+  local ec=$1
+  [ "$ec" -gt "$EC" ] && EC=$ec
+}
 
-RES=0
-SERVICE="cinder"
 
 function prepare_vm(){
-  if [[ `cat /etc/*-release | head -n 1 | awk '{print $1}'` =~ Ubuntu ]]
+  if [[ $(cat /etc/*-release | head -n 1 | awk '{print $1}') =~ Ubuntu ]]
   then
-      echo "mysql-server mysql-server/root_password select $MYSQL_PASSWORD" | sudo debconf-set-selections
-      echo "mysql-server mysql-server/root_password_again select $MYSQL_PASSWORD" | sudo debconf-set-selections
-      apt-get install -y mysql-server python-mysqldb rabbitmq-server curl screen
+    echo "mysql-server mysql-server/root_password select $MYSQL_PASSWORD" |
+      debconf-set-selections
+    echo "mysql-server mysql-server/root_password_again select $MYSQL_PASSWORD" |
+      debconf-set-selections
+    apt-get install -y mysql-server python-mysqldb rabbitmq-server curl screen nmap
+    CONF_FILE='/usr/share/cinder-common/cinder.conf'
   else
-      yum install net-tools mysql-server mysql-wsrep-client-5.6 MySQL-python -y
-
-      # workaround for `sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError)
-      # (2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)")`
-      rm -f /etc/my.cnf
-      MYSQL_PASSWORD=$(cat /root/.mysql_secret | head -1 | awk -F': ' '{print $2}')
-      service mysql start
-      /usr/bin/mysqladmin -u root -p$MYSQL_PASSWORD password $SERVICE
+    yum install -y mysql-server mysql-wsrep-client-5.6 MySQL-python nmap-ncat
+    CONF_FILE='/usr/share/cinder/cinder-dist.conf'
+    # workaround for `sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError)
+    # (2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)")`
+    rm -f /etc/my.cnf
+    local current_password=$(cat /root/.mysql_secret | head -1 | awk -F': ' '{print $2}')
+    service mysql start
+    mysqladmin -u root -p"$current_password" password "$MYSQL_PASSWORD"
   fi
-  mysql -uroot -p$SERVICE <<MYSQL_SCRIPT 
+  mysql -uroot -p"$MYSQL_PASSWORD" << MYSQL_SCRIPT
 CREATE DATABASE cinder;
-CREATE USER 'cinder'@'localhost' IDENTIFIED BY 'cinder';
-GRANT ALL PRIVILEGES ON * . * TO 'cinder'@'localhost';
-FLUSH PRIVILEGES;
+CREATE USER 'cinder'@'localhost' IDENTIFIED BY '$MYSQL_PASSWORD';
+GRANT ALL PRIVILEGES ON *.* TO 'cinder'@'localhost';
 MYSQL_SCRIPT
+  cinder-manage --config-file $CONF_FILE db sync
 }
 
+
 function test_cinder_service(){
-  echo "Starting Cinder $1..."
-  service $1 start
-  sleep 5
+  local service=$1
+  local port=$2
 
-  service_result=0
-  service_running=`netstat -nat | grep $2 | wc -l`
-  if [ $service_running -eq 0 ]; then
-    echo "Can not start Cinder $1 service"
-    tail -n 40 /var/log/messages
-    RES=1
-  else
-    echo "Cinder $1 successfully started"
-    service $1 stop
-  fi
-}
+  echo "Starting $1..."
+  service "$service" start
 
+  sleep 5
+  echo | ncat -w 5 127.0.0.1 "$port"
+  local ec=$?
+  update_ec "$ec"
 
-function check_file_exists(){
-  if [ ! -f "$1" ]; then
-    RES=1
+  if [ "$ec" -eq 0 ]
+  then
+    echo "Cinder $1 successfully started"
+  else
+    echo "$service failed to start!"
+    tail -n 40 /var/log/messages
   fi
 }
 
 
 function test_cinder_configs(){
-  declare -a files=("/etc/cinder/cinder.conf" "/etc/cinder/api-paste.ini" "/etc/cinder/policy.json")
+  local files=("/etc/cinder/cinder.conf"
+               "/etc/cinder/api-paste.ini"
+               "/etc/cinder/policy.json")
   for f in "${files[@]}"
   do
-    check_file_exists "$f"
- done
+    [ -f "$f" ] ; update_ec "$?"
 done
 }
 
 
 case $1 in
   python-cinder)
-    declare -a imports=("cinder" "cinder.volume.drivers.lvm" "cinder.volume.drivers.rbd")
-    for i in "${imports[@]}"
+    local imports=("cinder"
+                   "cinder.volume.drivers.lvm"
+                   "cinder.volume.drivers.rbd")
+    for x in "${imports[@]}"
     do
-      python -c "import $i"
-      if [ $? -ne 0 ]; then
-        RES=1
-        break
-      fi
+      python -c "import $x" ; update_ec "$?"
     done
   ;;
   openstack-cinder)
     prepare_vm
     test_cinder_configs
-
-    count=`ls -1 /usr/bin/cinder* 2>/dev/null | wc -l`
-    if [ $count -eq 0 ]; then
-        RES=1
-    fi
-
-    test_cinder_service openstack-cinder-api 8776
-    check_file_exists "/usr/bin/cinder-volume"
-    check_file_exists "/usr/bin/cinder-scheduler"
+    ls /usr/bin/cinder* ; update_ec "$?"
+    test_cinder_service openstack-cinder-api 8776 ; update_ec "$?"
+    [ -f "/usr/bin/cinder-volume" ] ; update_ec "$?"
+    [ -f "/usr/bin/cinder-scheduler" ] ; update_ec "$?"
   ;;
   cinder-common)
     test_cinder_configs
-    check_file_exists "/usr/bin/cinder-manage"
+    [ -f "/usr/bin/cinder-manage" ] ; update_ec "$?"
   ;;
   cinder-scheduler)
-    check_file_exists "/usr/bin/cinder-scheduler"
+    [ -f "/usr/bin/cinder-scheduler" ] ; update_ec "$?"
   ;;
   cinder-api)
-    check_file_exists "/usr/bin/cinder-api"
-    test_cinder_service cinder-api 8776
+    prepare_vm
+    [ -f "/usr/bin/cinder-api" ] ; update_ec "$?"
+    test_cinder_service cinder-api 8776 ; update_ec "$?"
   ;;
   cinder-volume)
-    check_file_exists "/usr/bin/cinder-volume"
+    [ -f "/usr/bin/cinder-volume" ] ; update_ec "$?"
+  ;;
+  cinder-backup)
+    [ -f "/usr/bin/cinder-backup" ] ; update_ec "$?"
   ;;
-  openstack-cinder-doc)
-    echo "No test for docs defined"
+  cinder-doc|openstack-cinder-doc)
+    echo "Skipping test for $1"
+    EC=0
   ;;
   *)
-    echo "Test is not defined, skipping..."
+    echo "Test not defined for $1"
+    EC=1
   ;;
 esac
 
-exit $RES
+exit "$EC"