Merge "tests: replace bash scripts with overtest"

This commit is contained in:
Jenkins 2016-01-21 12:43:00 +00:00 committed by Gerrit Code Review
commit bcab4a2668
9 changed files with 38 additions and 133 deletions

View File

@ -50,22 +50,22 @@ class SQLManager(fixtures.Fixture):
self.conf = conf
db_name = 'aodh_%s' % uuid.uuid4().hex
import sqlalchemy
self._engine = sqlalchemy.create_engine(
conf.database.connection.replace(self.url_dbname_placeholder,
self.url_dbname_createstring))
self._engine = sqlalchemy.create_engine(conf.database.connection)
self._conn = self._engine.connect()
self._create_db(self._conn, db_name)
self._conn.close()
self._engine.dispose()
self.url = conf.database.connection.replace(
self.url_dbname_placeholder, db_name)
parsed = list(urlparse.urlparse(conf.database.connection))
# NOTE(jd) We need to set an host otherwise urlunparse() will not
# construct a proper URL
if parsed[1] == '':
parsed[1] = 'localhost'
parsed[2] = '/' + db_name
self.url = urlparse.urlunparse(parsed)
class PgSQLManager(SQLManager):
url_dbname_placeholder = 'template1'
url_dbname_createstring = url_dbname_placeholder
@staticmethod
def _create_db(conn, db_name):
conn.connection.set_isolation_level(0)
@ -75,9 +75,6 @@ class PgSQLManager(SQLManager):
class MySQLManager(SQLManager):
url_dbname_placeholder = 'test'
url_dbname_createstring = ''
@staticmethod
def _create_db(conn, db_name):
conn.execute('CREATE DATABASE %s;' % db_name)
@ -133,7 +130,11 @@ class TestBase(test_base.BaseTestCase):
def setUp(self):
super(TestBase, self).setUp()
db_url = os.environ.get('AODH_TEST_STORAGE_URL', 'sqlite://')
db_url = os.environ.get(
'AODH_TEST_STORAGE_URL',
os.environ.get(
"OVERTEST_URL", 'sqlite://').replace(
"mysql://", "mysql+pymysql://"))
engine = urlparse.urlparse(db_url).scheme
# In case some drivers have additional specification, for example:
# PyMySQL will have scheme mysql+pymysql.

View File

@ -44,7 +44,11 @@ class ConfigFixture(fixture.GabbiFixture):
self.conf = None
# Determine the database connection.
db_url = os.environ.get('AODH_TEST_STORAGE_URL')
db_url = os.environ.get(
'AODH_TEST_STORAGE_URL',
os.environ.get(
"OVERTEST_URL", 'sqlite://').replace(
"mysql://", "mysql+pymysql://"))
if not db_url:
raise case.SkipTest('No database connection configured')

18
run-functional-tests.sh Normal file → Executable file
View File

@ -1,11 +1,13 @@
#!/bin/bash -x
set -e
# Use a mongodb backend by default
if [ -z "$AODH_TEST_BACKEND" ]; then
AODH_TEST_BACKEND="mongodb"
fi
echo $AODH_TEST_BACKEND
for backend in $AODH_TEST_BACKEND; do
./setup-test-env-${backend}.sh ./tools/pretty_tox.sh $*
done
case $AODH_TEST_BACKEND in
hbase)
export AODH_TEST_STORAGE_URL="hbase://__test__"
;;
*)
source $(which overtest) $AODH_TEST_BACKEND
;;
esac
$*

View File

@ -1,12 +0,0 @@
#!/bin/bash
set -e
if [ "$1" = "--coverage" ]; then
COVERAGE_ARG="$1"
shift
fi
export AODH_TEST_STORAGE_URL="hbase://__test__"
# Yield execution to venv command
$*

View File

@ -1,27 +0,0 @@
#!/bin/bash
set -e
source functions.sh
if [ "$1" = "--coverage" ]; then
COVERAGE_ARG="$1"
shift
fi
export PATH=${PATH:+$PATH:}/sbin:/usr/sbin
check_for_cmd mongod
# Start MongoDB process for tests
MONGO_DATA=`mktemp -d /tmp/AODH-MONGODB-XXXXX`
MONGO_PORT=29000
trap "clean_exit ${MONGO_DATA}" EXIT
mkfifo ${MONGO_DATA}/out
mongod --maxConns 32 --nojournal --noprealloc --smallfiles --quiet --noauth --port ${MONGO_PORT} --dbpath "${MONGO_DATA}" --bind_ip localhost --config /dev/null &>${MONGO_DATA}/out &
# Wait for Mongo to start listening to connections
wait_for_line "waiting for connections on port ${MONGO_PORT}" ${MONGO_DATA}/out
# Read the fifo for ever otherwise mongod would block
cat ${MONGO_DATA}/out > /dev/null &
export AODH_TEST_STORAGE_URL="mongodb://localhost:${MONGO_PORT}/AODH"
# Yield execution to venv command
$*

View File

@ -1,29 +0,0 @@
#!/bin/bash
set -e
source functions.sh
if [ "$1" = "--coverage" ]; then
COVERAGE_ARG="$1"
shift
fi
export PATH=${PATH:+$PATH:}/sbin:/usr/sbin
# On systems like Fedora here's where mysqld can be found
export PATH=$PATH:/usr/libexec
check_for_cmd mysqld
# Start MySQL process for tests
MYSQL_DATA=`mktemp -d /tmp/AODH-MYSQL-XXXXX`
trap "clean_exit ${MYSQL_DATA}" EXIT
mysqld --initialize-insecure --datadir=${MYSQL_DATA} || true
mkfifo ${MYSQL_DATA}/out
mysqld --datadir=${MYSQL_DATA} --pid-file=${MYSQL_DATA}/mysql.pid --socket=${MYSQL_DATA}/mysql.socket --skip-networking --skip-grant-tables &> ${MYSQL_DATA}/out &
# Wait for MySQL to start listening to connections
wait_for_line "mysqld: ready for connections." ${MYSQL_DATA}/out
export AODH_TEST_STORAGE_URL="mysql+pymysql://root@localhost/test?unix_socket=${MYSQL_DATA}/mysql.socket&charset=utf8"
# Yield execution to venv command
$*

View File

@ -1,34 +0,0 @@
#!/bin/bash
set -e
source functions.sh
if [ "$1" = "--coverage" ]; then
COVERAGE_ARG="$1"
shift
fi
function clean_exit_pgsql(){
ret=$?
${1}/pg_ctl -w -D ${2} -o "-p ${3}" stop
rm -rf ${2}
return ${ret}
}
#export PATH=${PATH:+$PATH:}/sbin:/usr/sbin
check_for_cmd pg_config
# Start PostgreSQL process for tests
PGSQL_DATA=`mktemp -d /tmp/AODH-PGSQL-XXXXX`
PGSQL_PATH=`pg_config --bindir`
PGSQL_PORT=9823
${PGSQL_PATH}/pg_ctl initdb -D ${PGSQL_DATA}
trap "clean_exit_pgsql ${PGSQL_PATH} ${PGSQL_DATA} ${PGSQL_PORT}" EXIT
LANGUAGE=C ${PGSQL_PATH}/pg_ctl -w -D ${PGSQL_DATA} -o "-k ${PGSQL_DATA} -p ${PGSQL_PORT}" start
export AODH_TEST_STORAGE_URL="postgresql:///?host=${PGSQL_DATA}&port=${PGSQL_PORT}&dbname=template1"
# Yield execution to venv command
$*

View File

@ -52,6 +52,7 @@ doc =
sphinxcontrib-pecanwsme>=0.8
test =
overtest>=0.7.0
oslotest>=1.5.1 # Apache-2.0
coverage>=3.6
fixtures>=1.3.1

19
tox.ini
View File

@ -28,19 +28,19 @@ setenv = OS_TEST_PATH=aodh/tests/functional/
deps = .[mongodb,test]
setenv = OS_TEST_PATH=aodh/tests/functional/
commands =
bash -x {toxinidir}/setup-test-env-mongodb.sh python setup.py testr --slowest --testr-args="{posargs}"
overtest mongodb python setup.py testr --slowest --testr-args="{posargs}"
[testenv:py27-mysql]
deps = .[mysql,test]
setenv = OS_TEST_PATH=aodh/tests/functional/
commands =
bash -x {toxinidir}/setup-test-env-mysql.sh python setup.py testr --slowest --testr-args="{posargs}"
overtest mysql python setup.py testr --slowest --testr-args="{posargs}"
[testenv:py27-pgsql]
deps = .[postgresql,test]
setenv = OS_TEST_PATH=aodh/tests/functional/
commands =
bash -x {toxinidir}/setup-test-env-postgresql.sh python setup.py testr --slowest --testr-args="{posargs}"
overtest postgresql python setup.py testr --slowest --testr-args="{posargs}"
[testenv:functional]
deps = .[mysql,postgresql,mongodb,test]
@ -49,7 +49,7 @@ setenv = VIRTUAL_ENV={envdir}
GABBI_LIVE_FAIL_IF_NO_TEST=1
passenv = {[testenv]passenv} AODH_*
commands =
bash -x {toxinidir}/run-functional-tests.sh "{posargs}"
{toxinidir}/run-functional-tests.sh ./tools/pretty_tox.sh "{posargs}"
# NOTE(chdent): The gabbi tests are also run under the primary tox
# targets. This target simply provides a target to directly run just
@ -59,11 +59,10 @@ commands =
deps = .[mongodb,test]
setenv = OS_TEST_PATH=aodh/tests/functional/gabbi
commands =
bash -x {toxinidir}/setup-test-env-mongodb.sh \
python setup.py testr --testr-args="{posargs}"
overtest mongodb python setup.py testr --testr-args="{posargs}"
[testenv:cover]
commands = bash -x {toxinidir}/setup-test-env-mongodb.sh python setup.py testr --slowest --coverage --testr-args="{posargs}"
commands = overtest mongodb python setup.py testr --slowest --coverage --testr-args="{posargs}"
[testenv:pep8]
deps = hacking<0.11,>=0.10.0
@ -95,17 +94,17 @@ commands = bash -x oslo_debug_helper {posargs}
[testenv:debug-mongodb]
deps = .[mongodb,test]
setenv = OS_TEST_PATH=aodh/tests/functional/
commands = bash -x {toxinidir}/setup-test-env-mongodb.sh oslo_debug_helper {posargs}
commands = overtest mongodb oslo_debug_helper {posargs}
[testenv:debug-mysql]
deps = .[mysql,test]
setenv = OS_TEST_PATH=aodh/tests/functional/
commands = bash -x {toxinidir}/setup-test-env-mysql.sh oslo_debug_helper {posargs}
commands = overtest mysql oslo_debug_helper {posargs}
[testenv:debug-pgsql]
deps = .[postgresql,test]
setenv = OS_TEST_PATH=aodh/tests/functional/
commands = bash -x {toxinidir}/setup-test-env-postgresql.sh oslo_debug_helper {posargs}
commands = overtest postgresql oslo_debug_helper {posargs}
[flake8]
ignore =