Use overtest to setup functional backends
This patches leverage overtest to setup the database environment needed. Change-Id: I8198041b4a87bf187d8f6499f0c7c1a43d4dcac2 Depends-On: I29e480611e743ddc645fd067ca2c63b51b11b518
This commit is contained in:
@@ -64,6 +64,17 @@ class MongoDbManager(fixtures.Fixture):
|
|||||||
|
|
||||||
|
|
||||||
class SQLManager(fixtures.Fixture):
|
class SQLManager(fixtures.Fixture):
|
||||||
|
def __init__(self, url):
|
||||||
|
db_name = 'ceilometer_%s' % uuid.uuid4().hex
|
||||||
|
engine = sqlalchemy.create_engine(url)
|
||||||
|
conn = engine.connect()
|
||||||
|
self._create_database(conn, db_name)
|
||||||
|
conn.close()
|
||||||
|
engine.dispose()
|
||||||
|
parsed = list(urlparse.urlparse(url))
|
||||||
|
parsed[2] = '/' + db_name
|
||||||
|
self.url = urlparse.urlunparse(parsed)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(SQLManager, self).setUp()
|
super(SQLManager, self).setUp()
|
||||||
self.connection = storage.get_connection(
|
self.connection = storage.get_connection(
|
||||||
@@ -71,37 +82,19 @@ class SQLManager(fixtures.Fixture):
|
|||||||
self.event_connection = storage.get_connection(
|
self.event_connection = storage.get_connection(
|
||||||
self.url, 'ceilometer.event.storage')
|
self.url, 'ceilometer.event.storage')
|
||||||
|
|
||||||
@property
|
|
||||||
def url(self):
|
|
||||||
return self._url.replace('template1', self._db_name)
|
|
||||||
|
|
||||||
|
|
||||||
class PgSQLManager(SQLManager):
|
class PgSQLManager(SQLManager):
|
||||||
|
@staticmethod
|
||||||
def __init__(self, url):
|
def _create_database(conn, db_name):
|
||||||
self._url = url
|
conn.connection.set_isolation_level(0)
|
||||||
self._db_name = 'ceilometer_%s' % uuid.uuid4().hex
|
conn.execute('CREATE DATABASE %s WITH TEMPLATE template0;' % db_name)
|
||||||
self._engine = sqlalchemy.create_engine(self._url)
|
conn.connection.set_isolation_level(1)
|
||||||
self._conn = self._engine.connect()
|
|
||||||
self._conn.connection.set_isolation_level(0)
|
|
||||||
self._conn.execute(
|
|
||||||
'CREATE DATABASE %s WITH TEMPLATE template0;' % self._db_name)
|
|
||||||
self._conn.connection.set_isolation_level(1)
|
|
||||||
self._conn.close()
|
|
||||||
self._engine.dispose()
|
|
||||||
|
|
||||||
|
|
||||||
class MySQLManager(SQLManager):
|
class MySQLManager(SQLManager):
|
||||||
|
@staticmethod
|
||||||
def __init__(self, url):
|
def _create_database(conn, db_name):
|
||||||
self._url = url
|
conn.execute('CREATE DATABASE %s;' % db_name)
|
||||||
self._db_name = 'ceilometer_%s' % uuid.uuid4().hex
|
|
||||||
self._engine = sqlalchemy.create_engine(
|
|
||||||
self._url.replace('template1', ''))
|
|
||||||
self._conn = self._engine.connect()
|
|
||||||
self._conn.execute('CREATE DATABASE %s;' % self._db_name)
|
|
||||||
self._conn.close()
|
|
||||||
self._engine.dispose()
|
|
||||||
|
|
||||||
|
|
||||||
class ElasticSearchManager(fixtures.Fixture):
|
class ElasticSearchManager(fixtures.Fixture):
|
||||||
@@ -188,8 +181,8 @@ class TestBase(test_base.BaseTestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestBase, self).setUp()
|
super(TestBase, self).setUp()
|
||||||
db_url = os.environ.get('CEILOMETER_TEST_STORAGE_URL',
|
db_url = os.environ.get('OVERTEST_URL', "sqlite://").replace(
|
||||||
"sqlite://")
|
"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:
|
||||||
|
@@ -47,7 +47,8 @@ class ConfigFixture(fixture.GabbiFixture):
|
|||||||
self.conf = None
|
self.conf = None
|
||||||
|
|
||||||
# Determine the database connection.
|
# Determine the database connection.
|
||||||
db_url = os.environ.get('CEILOMETER_TEST_STORAGE_URL')
|
db_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')
|
||||||
|
|
||||||
|
5
run-functional-tests.sh
Normal file → Executable file
5
run-functional-tests.sh
Normal file → Executable file
@@ -2,11 +2,10 @@
|
|||||||
set -e
|
set -e
|
||||||
# Use a mongodb backend by default
|
# Use a mongodb backend by default
|
||||||
|
|
||||||
|
|
||||||
if [ -z $CEILOMETER_TEST_BACKEND ]; then
|
if [ -z $CEILOMETER_TEST_BACKEND ]; then
|
||||||
CEILOMETER_TEST_BACKEND="mongodb"
|
CEILOMETER_TEST_BACKEND="mongodb"
|
||||||
fi
|
fi
|
||||||
echo $CEILOMETER_TEST_BACKEND
|
|
||||||
for backend in $CEILOMETER_TEST_BACKEND; do
|
for backend in $CEILOMETER_TEST_BACKEND; do
|
||||||
./setup-test-env-${backend}.sh ./tools/pretty_tox.sh $*
|
overtest $backend ./tools/pretty_tox.sh $*
|
||||||
done
|
done
|
||||||
|
@@ -1,41 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
source functions.sh
|
|
||||||
|
|
||||||
if [ "$1" = "--coverage" ]; then
|
|
||||||
COVERAGE_ARG="$1"
|
|
||||||
shift
|
|
||||||
fi
|
|
||||||
|
|
||||||
export PATH=$PATH:/usr/share/elasticsearch/bin
|
|
||||||
|
|
||||||
check_for_cmd elasticsearch
|
|
||||||
|
|
||||||
# check for Java
|
|
||||||
if [ -x "$JAVA_HOME/bin/java" ]; then
|
|
||||||
JAVA="$JAVA_HOME/bin/java"
|
|
||||||
else
|
|
||||||
JAVA=`which java`
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -x "$JAVA" ]; then
|
|
||||||
echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Start ElasticSearch process for tests
|
|
||||||
ES_DATA=`mktemp -d /tmp/CEILO-ES-XXXXX`
|
|
||||||
ES_PORT=9200
|
|
||||||
ES_PID=${ES_DATA}/elasticsearch.pid
|
|
||||||
elasticsearch -p ${ES_PID} -Des.http.port=${ES_PORT} -Des.path.logs=${ES_DATA}/logs -Des.path.data=${ES_DATA} -Des.path.conf=/etc/elasticsearch &> ${ES_DATA}/out &
|
|
||||||
# Wait for ElasticSearch to start listening to connections
|
|
||||||
sleep 3
|
|
||||||
wait_for_line "started" ${ES_DATA}/out
|
|
||||||
export CEILOMETER_TEST_STORAGE_URL="es://localhost:${ES_PORT}"
|
|
||||||
|
|
||||||
# Yield execution to venv command
|
|
||||||
$*
|
|
||||||
|
|
||||||
# Kill ElasticSearch
|
|
||||||
kill $(cat ${ES_PID})
|
|
@@ -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/CEILO-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 CEILOMETER_TEST_STORAGE_URL="mongodb://localhost:${MONGO_PORT}/ceilometer"
|
|
||||||
|
|
||||||
# Yield execution to venv command
|
|
||||||
$*
|
|
@@ -1,28 +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/CEILO-MYSQL-XXXXX`
|
|
||||||
trap "clean_exit ${MYSQL_DATA}" EXIT
|
|
||||||
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 CEILOMETER_TEST_STORAGE_URL="mysql+pymysql://root@localhost/template1?unix_socket=${MYSQL_DATA}/mysql.socket&charset=utf8"
|
|
||||||
|
|
||||||
# Yield execution to venv command
|
|
||||||
$*
|
|
@@ -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/CEILO-PGSQL-XXXXX`
|
|
||||||
PGSQL_PATH=`pg_config --bindir`
|
|
||||||
PGSQL_PORT=9823
|
|
||||||
${PGSQL_PATH}/initdb -E UTF8 ${PGSQL_DATA}
|
|
||||||
trap "clean_exit_pgsql ${PGSQL_PATH} ${PGSQL_DATA} ${PGSQL_PORT}" EXIT
|
|
||||||
|
|
||||||
LANGUAGE=C ${PGSQL_PATH}/pg_ctl -w -D ${PGSQL_DATA} -o "-F -k ${PGSQL_DATA} -p ${PGSQL_PORT}" start
|
|
||||||
export CEILOMETER_TEST_STORAGE_URL="postgresql:///?host=${PGSQL_DATA}&port=${PGSQL_PORT}&dbname=template1"
|
|
||||||
|
|
||||||
# Yield execution to venv command
|
|
||||||
$*
|
|
@@ -19,6 +19,7 @@ oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0
|
|||||||
reno>=0.1.1 # Apache2
|
reno>=0.1.1 # Apache2
|
||||||
oslotest>=1.10.0 # Apache-2.0
|
oslotest>=1.10.0 # Apache-2.0
|
||||||
oslo.vmware>=1.16.0 # Apache-2.0
|
oslo.vmware>=1.16.0 # Apache-2.0
|
||||||
|
overtest>=0.10.0 # Apache-2.0
|
||||||
psycopg2>=2.5 # LGPL/ZPL
|
psycopg2>=2.5 # LGPL/ZPL
|
||||||
pylint==1.4.5 # GNU GPL v2
|
pylint==1.4.5 # GNU GPL v2
|
||||||
pymongo>=3.0.2 # Apache-2.0
|
pymongo>=3.0.2 # Apache-2.0
|
||||||
|
23
tox.ini
23
tox.ini
@@ -22,24 +22,20 @@ whitelist_externals = bash
|
|||||||
|
|
||||||
[testenv:py-mongodb]
|
[testenv:py-mongodb]
|
||||||
setenv = OS_TEST_PATH=ceilometer/tests/functional/
|
setenv = OS_TEST_PATH=ceilometer/tests/functional/
|
||||||
commands =
|
commands = overtest mongodb {toxinidir}/tools/pretty_tox.sh "{posargs}"
|
||||||
bash -x {toxinidir}/setup-test-env-mongodb.sh {toxinidir}/tools/pretty_tox.sh "{posargs}"
|
|
||||||
|
|
||||||
[testenv:py-mysql]
|
[testenv:py-mysql]
|
||||||
setenv = OS_TEST_PATH=ceilometer/tests/functional/
|
setenv = OS_TEST_PATH=ceilometer/tests/functional/
|
||||||
commands =
|
commands = overtest mysql {toxinidir}/tools/pretty_tox.sh "{posargs}"
|
||||||
bash -x {toxinidir}/setup-test-env-mysql.sh {toxinidir}/tools/pretty_tox.sh "{posargs}"
|
|
||||||
|
|
||||||
[testenv:py-pgsql]
|
[testenv:py-pgsql]
|
||||||
setenv = OS_TEST_PATH=ceilometer/tests/functional/
|
setenv = OS_TEST_PATH=ceilometer/tests/functional/
|
||||||
commands =
|
commands = overtest postgresql {toxinidir}/tools/pretty_tox.sh "{posargs}"
|
||||||
bash -x {toxinidir}/setup-test-env-postgresql.sh {toxinidir}/tools/pretty_tox.sh "{posargs}"
|
|
||||||
|
|
||||||
# Functional tests for elastic search
|
# Functional tests for elastic search
|
||||||
[testenv:py-elastic]
|
[testenv:py-elastic]
|
||||||
setenv = OS_TEST_PATH=ceilometer/tests/functional/
|
setenv = OS_TEST_PATH=ceilometer/tests/functional/
|
||||||
commands =
|
commands = overtest elasticsearch {toxinidir}/tools/pretty_tox.sh "{posargs}"
|
||||||
bash -x {toxinidir}/setup-test-env-es.sh {toxinidir}/tools/pretty_tox.sh "{posargs}"
|
|
||||||
|
|
||||||
[testenv:functional]
|
[testenv:functional]
|
||||||
setenv = VIRTUAL_ENV={envdir}
|
setenv = VIRTUAL_ENV={envdir}
|
||||||
@@ -75,8 +71,7 @@ commands =
|
|||||||
[testenv:gabbi]
|
[testenv:gabbi]
|
||||||
setenv = OS_TEST_PATH=ceilometer/tests/functional/gabbi
|
setenv = OS_TEST_PATH=ceilometer/tests/functional/gabbi
|
||||||
passenv = CEILOMETER_*
|
passenv = CEILOMETER_*
|
||||||
commands =
|
commands = overtest mongodb {toxinidir}/tools/pretty_tox.sh "{posargs}"
|
||||||
bash -x {toxinidir}/setup-test-env-mongodb.sh {toxinidir}/tools/pretty_tox.sh "{posargs}"
|
|
||||||
|
|
||||||
[testenv:cover]
|
[testenv:cover]
|
||||||
setenv = OS_TEST_PATH=ceilometer/tests
|
setenv = OS_TEST_PATH=ceilometer/tests
|
||||||
@@ -111,19 +106,19 @@ commands = bash -x oslo_debug_helper {posargs}
|
|||||||
|
|
||||||
[testenv:debug-mongodb]
|
[testenv:debug-mongodb]
|
||||||
setenv = OS_TEST_PATH=ceilometer/tests/functional
|
setenv = OS_TEST_PATH=ceilometer/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]
|
||||||
setenv = OS_TEST_PATH=ceilometer/tests/functional
|
setenv = OS_TEST_PATH=ceilometer/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]
|
||||||
setenv = OS_TEST_PATH=ceilometer/tests/functional
|
setenv = OS_TEST_PATH=ceilometer/tests/functional
|
||||||
commands = bash -x {toxinidir}/setup-test-env-pgsql.sh oslo_debug_helper {posargs}
|
commands = overtest postgresql oslo_debug_helper {posargs}
|
||||||
|
|
||||||
[testenv:debug-elastic]
|
[testenv:debug-elastic]
|
||||||
setenv = OS_TEST_PATH=ceilometer/tests/functional
|
setenv = OS_TEST_PATH=ceilometer/tests/functional
|
||||||
commands = bash -x {toxinidir}/setup-test-env-es.sh oslo_debug_helper {posargs}
|
commands = overtest elasticsearch oslo_debug_helper {posargs}
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
ignore =
|
ignore =
|
||||||
|
Reference in New Issue
Block a user