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 self.conf = conf
db_name = 'aodh_%s' % uuid.uuid4().hex db_name = 'aodh_%s' % uuid.uuid4().hex
import sqlalchemy import sqlalchemy
self._engine = sqlalchemy.create_engine( self._engine = sqlalchemy.create_engine(conf.database.connection)
conf.database.connection.replace(self.url_dbname_placeholder,
self.url_dbname_createstring))
self._conn = self._engine.connect() self._conn = self._engine.connect()
self._create_db(self._conn, db_name) self._create_db(self._conn, db_name)
self._conn.close() self._conn.close()
self._engine.dispose() self._engine.dispose()
self.url = conf.database.connection.replace( parsed = list(urlparse.urlparse(conf.database.connection))
self.url_dbname_placeholder, db_name) # 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): class PgSQLManager(SQLManager):
url_dbname_placeholder = 'template1'
url_dbname_createstring = url_dbname_placeholder
@staticmethod @staticmethod
def _create_db(conn, db_name): def _create_db(conn, db_name):
conn.connection.set_isolation_level(0) conn.connection.set_isolation_level(0)
@ -75,9 +75,6 @@ class PgSQLManager(SQLManager):
class MySQLManager(SQLManager): class MySQLManager(SQLManager):
url_dbname_placeholder = 'test'
url_dbname_createstring = ''
@staticmethod @staticmethod
def _create_db(conn, db_name): def _create_db(conn, db_name):
conn.execute('CREATE DATABASE %s;' % db_name) conn.execute('CREATE DATABASE %s;' % db_name)
@ -133,7 +130,11 @@ class TestBase(test_base.BaseTestCase):
def setUp(self): def setUp(self):
super(TestBase, self).setUp() 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 engine = urlparse.urlparse(db_url).scheme
# In case some drivers have additional specification, for example: # In case some drivers have additional specification, for example:
# PyMySQL will have scheme mysql+pymysql. # PyMySQL will have scheme mysql+pymysql.

View File

@ -44,7 +44,11 @@ class ConfigFixture(fixture.GabbiFixture):
self.conf = None self.conf = None
# Determine the database connection. # 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: if not db_url:
raise case.SkipTest('No database connection configured') 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 #!/bin/bash -x
set -e set -e
# Use a mongodb backend by default case $AODH_TEST_BACKEND in
if [ -z "$AODH_TEST_BACKEND" ]; then hbase)
AODH_TEST_BACKEND="mongodb" export AODH_TEST_STORAGE_URL="hbase://__test__"
fi ;;
echo $AODH_TEST_BACKEND *)
for backend in $AODH_TEST_BACKEND; do source $(which overtest) $AODH_TEST_BACKEND
./setup-test-env-${backend}.sh ./tools/pretty_tox.sh $* ;;
done 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 sphinxcontrib-pecanwsme>=0.8
test = test =
overtest>=0.7.0
oslotest>=1.5.1 # Apache-2.0 oslotest>=1.5.1 # Apache-2.0
coverage>=3.6 coverage>=3.6
fixtures>=1.3.1 fixtures>=1.3.1

19
tox.ini
View File

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