CentOS 7: Update to 8.0.0.0b3
[openstack-build/cinder-build.git] / tests / runtests.sh
index d26c49f187c2c65abebaa7c59b748fbb05ce20c8..162b145cae3fb0b1a05577d211c57d8a94c3da6a 100755 (executable)
-#!/bin/bash -x
-echo "Testing $1"
+#! /bin/bash
 
-RES=0
+set -o xtrace
 
+EC=0
+MYSQL_PASSWORD="cinder"
 
-function test_cinder_service(){
-  echo "Starting Cinder $1..."
-  /etc/init.d/$1 start
-  sleep 5
+update_ec(){
+  local ec=$1
+  [ "$ec" -gt "$EC" ] && EC=$ec
+}
 
-  if [ "$1" == "api" ]; then
-    service_running=`netstat -nat | grep $2 | wc -l`
-  else
-      service_running=`ps -Af | grep cinder-$2 | wc -l`
-  fi
 
-  if [ service_running ]; then
-    echo "Cinder API successfully started"
-    /etc/init.d/$1 stop
+function prepare_vm(){
+  if [[ $(cat /etc/*-release | head -n 1 | awk '{print $1}') =~ Ubuntu ]]
+  then
+    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
   else
-    echo "Can not start Cinder $1 service"
-    RES=1
+    yum install -y mysql-server mysql-wsrep-client-5.6 MySQL-python nmap-ncat
+    # 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"$MYSQL_PASSWORD" << MYSQL_SCRIPT
+CREATE DATABASE cinder;
+CREATE USER 'cinder'@'localhost' IDENTIFIED BY '$MYSQL_PASSWORD';
+GRANT ALL PRIVILEGES ON *.* TO 'cinder'@'localhost';
+MYSQL_SCRIPT
+  cinder-manage --config-file /usr/share/cinder/cinder-dist.conf db sync
 }
 
 
-function check_file_exists(){
-  if [ ! -f "$1" ]; then
-    RES=1
+function test_cinder_service(){
+  local service=$1
+  local port=$2
+
+  echo "Starting $1..."
+  service "$service" start
+
+  sleep 5
+  echo | ncat -w 5 localhost "$port"
+  local ec=$?
+  update_ec "$ec"
+
+  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
-    test_cinder_service openstack-cinder-volume
-    test_cinder_service openstack-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"
-    test_cinder_service cinder-scheduler
+    [ -f "/usr/bin/cinder-scheduler" ] ; update_ec "$?"
   ;;
   cinder-api)
-    check_file_exists "/usr/bin/cinder-api"
-    test_cinder_service cinder-api 8776
+    EC=0
+    # Should be fixed with next update of Ubuntu package.  
+    # 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-api"
-    test_cinder_service 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"