Tests for Cinder packages
authorIvan Kolodyazhny <e0ne@e0ne.info>
Sat, 13 Sep 2014 13:37:51 +0000 (16:37 +0300)
committerIvan Kolodyazhny <e0ne@e0ne.info>
Fri, 26 Sep 2014 16:59:12 +0000 (19:59 +0300)
Testing imports, configs and binaries installation
Check that services could be started

Change-Id: Ibfd0af3db166bc76c2bc12df5edb1b9b56817f79

tests/runtests.sh [new file with mode: 0755]

diff --git a/tests/runtests.sh b/tests/runtests.sh
new file mode 100755 (executable)
index 0000000..6691d04
--- /dev/null
@@ -0,0 +1,86 @@
+#!/bin/bash -x
+echo "Testing $1"
+
+RES=0
+
+
+function test_cinder_service(){
+  echo "Starting Cinder $1..."
+  service $1 start
+  sleep 5
+
+  service_result=0
+  service_running=`netstat -nat | grep $2 | wc -l`
+  if [ $service_running -eq 0 ]; then
+    echo "Can not start Cinder $1 service"
+    RES=1
+  else
+    echo "Cinder $1 successfully started"
+    service $1 stop
+  fi
+}
+
+
+function check_file_exists(){
+  if [ ! -f "$1" ]; then
+    RES=1
+  fi
+}
+
+
+function test_cinder_configs(){
+  declare -a files=("/etc/cinder/cinder.conf" "/etc/cinder/api-paste.ini" "/etc/cinder/policy.json")
+  for f in "${files[@]}"
+  do
+    check_file_exists "$f"
+ done
+}
+
+
+case $1 in
+  python-cinder)
+    declare -a imports=("cinder" "cinder.volume.drivers.lvm" "cinder.volume.drivers.rbd")
+    for i in "${imports[@]}"
+    do
+      python -c "import $i"
+      if [ $? -ne 0 ]; then
+        RES=1
+        break
+      fi
+    done
+  ;;
+  openstack-cinder)
+    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"
+  ;;
+  cinder-common)
+    test_cinder_configs
+    check_file_exists "/usr/bin/cinder-manage"
+  ;;
+  cinder-scheduler)
+    check_file_exists "/usr/bin/cinder-scheduler"
+  ;;
+  cinder-api)
+    check_file_exists "/usr/bin/cinder-api"
+    test_cinder_service cinder-api 8776
+  ;;
+  cinder-volume)
+    check_file_exists "/usr/bin/cinder-volume"
+  ;;
+  openstack-cinder-doc)
+    echo "No test for docs defined"
+  ;;
+  *)
+    echo "Test is not defined, skipping..."
+  ;;
+esac
+
+exit $RES