From 0b65cb4b02eca8bfc36d99d8b813a55e3135b5b3 Mon Sep 17 00:00:00 2001 From: Yolanda Robla Date: Sat, 14 Feb 2015 11:11:03 +0100 Subject: [PATCH] Add tools to run integration tests According to spec in https://review.openstack.org/150743, integration tests will be launched from the backend. Add new install_test_backend.sh and destroy_test_backend.sh scripts that will be called from each integration tests. The workflow will be: - install_test_backend - run integration test - destroy_test_backend Change-Id: Ie676d3152cc4cd854ab6644e5fd281de9c2d70fd --- etc/storyboard.conf.test | 12 ++++++++++++ tools/destroy_test_backend.sh | 12 ++++++++++++ tools/install_test_backend.sh | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 etc/storyboard.conf.test create mode 100755 tools/destroy_test_backend.sh create mode 100755 tools/install_test_backend.sh diff --git a/etc/storyboard.conf.test b/etc/storyboard.conf.test new file mode 100644 index 00000000..d424d64a --- /dev/null +++ b/etc/storyboard.conf.test @@ -0,0 +1,12 @@ +[DEFAULT] +# Default log level is INFO +# verbose and debug has the same result. +# One of them will set DEBUG log level output +# debug = False +# verbose = False + +# Where to store lock files +lock_path = $state_path/lock + +[database] +connection = mysql+pymysql://#DB_USER#:#DB_PASSWORD#@127.0.0.1:3306/#DB_TEST# diff --git a/tools/destroy_test_backend.sh b/tools/destroy_test_backend.sh new file mode 100755 index 00000000..f2fbfdd6 --- /dev/null +++ b/tools/destroy_test_backend.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# This script cleans up the testing database and stops storyboard API +echo 'Killing storyboard-api...' +killall storyboard-api + +# export default vars if not defined, to be available in conf file +export DB_USER=${DB_USER:-storyboard} +export DB_PASSWORD=${DB_PASSWORD:-storyboard} +export DB_TEST=${DB_TEST:-storyboard_test} + +mysql -u $DB_USER -p$DB_PASSWORD -e "DROP DATABASE IF EXISTS $DB_TEST;" diff --git a/tools/install_test_backend.sh b/tools/install_test_backend.sh new file mode 100755 index 00000000..8b7c64be --- /dev/null +++ b/tools/install_test_backend.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +if [ -f /usr/bin/apt-get ] ; then + export DEBIAN_FRONTEND=noninteractive + sudo apt-get install -y -q mysql-server libmysqlclient-dev python-dev +else + sudo yum install -y mysql-server mysql python-devel +fi + +# export default vars if not defined, to be available in conf file +export DB_USER=${DB_USER:-storyboard} +export DB_PASSWORD=${DB_PASSWORD:-storyboard} +export DB_TEST=${DB_TEST:-storyboard_test} + +# create the user if needed +if [ $CREATE_USER ]; then + if [ $DB_ADMIN_PASSWORD ]; then + FLAG_PASS="-p$DB_ADMIN_PASSWORD" + else + FLAG_PASS="" + fi + mysql -u $DB_ADMIN_USER $FLAG_PASS -e "CREATE USER $DB_USER@'localhost' IDENTIFIED BY '$DB_PASSWORD';" + mysql -u $DB_ADMIN_USER $FLAG_PASS -e "GRANT ALL PRIVILEGES ON $DB_TEST.* TO $DB_USER@'localhost';" + mysql -u $DB_ADMIN_USER $FLAG_PASS -e "FLUSH PRIVILEGES;" +fi + +# create the test database +mysql -u $DB_USER -p$DB_PASSWORD -e "DROP DATABASE IF EXISTS $DB_TEST;" +mysql -u $DB_USER -p$DB_PASSWORD -e "CREATE DATABASE $DB_TEST;" + +# replace env vars +cd ${STORYBOARD_PATH:-storyboard} +sed -i -e "s/#DB_USER#/$DB_USER/g" -e "s/#DB_PASSWORD#/$DB_PASSWORD/g" -e "s/#DB_TEST#/$DB_TEST/g" ./etc/storyboard.conf.test +tox -e venv "storyboard-db-manage --config-file ./etc/storyboard.conf.test upgrade head" +tox -e venv "storyboard-api --config-file ./etc/storyboard.conf.test" &