Commit c8dd0947 authored by Jenkins's avatar Jenkins Committed by Gerrit Code Review

Merge "Use overtest to setup functional backends"

parents 23fd1b75 36c5b870
......@@ -64,6 +64,17 @@ class MongoDbManager(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):
super(SQLManager, self).setUp()
self.connection = storage.get_connection(
......@@ -71,37 +82,19 @@ class SQLManager(fixtures.Fixture):
self.event_connection = storage.get_connection(
self.url, 'ceilometer.event.storage')
@property
def url(self):
return self._url.replace('template1', self._db_name)
class PgSQLManager(SQLManager):
def __init__(self, url):
self._url = url
self._db_name = 'ceilometer_%s' % uuid.uuid4().hex
self._engine = sqlalchemy.create_engine(self._url)
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()
@staticmethod
def _create_database(conn, db_name):
conn.connection.set_isolation_level(0)
conn.execute('CREATE DATABASE %s WITH TEMPLATE template0;' % db_name)
conn.connection.set_isolation_level(1)
class MySQLManager(SQLManager):
def __init__(self, url):
self._url = url
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()
@staticmethod
def _create_database(conn, db_name):
conn.execute('CREATE DATABASE %s;' % db_name)
class ElasticSearchManager(fixtures.Fixture):
......@@ -188,8 +181,8 @@ class TestBase(test_base.BaseTestCase):
def setUp(self):
super(TestBase, self).setUp()
db_url = os.environ.get('CEILOMETER_TEST_STORAGE_URL',
"sqlite://")
db_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:
......
......@@ -49,7 +49,8 @@ class ConfigFixture(fixture.GabbiFixture):
self.conf = None
# 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:
raise case.SkipTest('No database connection configured')
......
......@@ -2,11 +2,10 @@
set -e
# Use a mongodb backend by default
if [ -z $CEILOMETER_TEST_BACKEND ]; then
CEILOMETER_TEST_BACKEND="mongodb"
fi
echo $CEILOMETER_TEST_BACKEND
for backend in $CEILOMETER_TEST_BACKEND; do
./setup-test-env-${backend}.sh ./tools/pretty_tox.sh $*
overtest $backend ./tools/pretty_tox.sh $*
done
#!/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})
#!/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
$*
#!/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
$*
#!/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
$*
......@@ -20,6 +20,7 @@ oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0
reno>=0.1.1 # Apache2
oslotest>=1.10.0 # Apache-2.0
oslo.vmware>=1.16.0 # Apache-2.0
overtest>=0.10.0 # Apache-2.0
psycopg2>=2.5 # LGPL/ZPL
pylint==1.4.5 # GNU GPL v2
pymongo>=3.0.2 # Apache-2.0
......
......@@ -22,24 +22,20 @@ whitelist_externals = bash
[testenv:py-mongodb]
setenv = OS_TEST_PATH=ceilometer/tests/functional/
commands =
bash -x {toxinidir}/setup-test-env-mongodb.sh {toxinidir}/tools/pretty_tox.sh "{posargs}"
commands = overtest mongodb {toxinidir}/tools/pretty_tox.sh "{posargs}"
[testenv:py-mysql]
setenv = OS_TEST_PATH=ceilometer/tests/functional/
commands =
bash -x {toxinidir}/setup-test-env-mysql.sh {toxinidir}/tools/pretty_tox.sh "{posargs}"
commands = overtest mysql {toxinidir}/tools/pretty_tox.sh "{posargs}"
[testenv:py-pgsql]
setenv = OS_TEST_PATH=ceilometer/tests/functional/
commands =
bash -x {toxinidir}/setup-test-env-postgresql.sh {toxinidir}/tools/pretty_tox.sh "{posargs}"
commands = overtest postgresql {toxinidir}/tools/pretty_tox.sh "{posargs}"
# Functional tests for elastic search
[testenv:py-elastic]
setenv = OS_TEST_PATH=ceilometer/tests/functional/
commands =
bash -x {toxinidir}/setup-test-env-es.sh {toxinidir}/tools/pretty_tox.sh "{posargs}"
commands = overtest elasticsearch {toxinidir}/tools/pretty_tox.sh "{posargs}"
[testenv:functional]
setenv = VIRTUAL_ENV={envdir}
......@@ -75,8 +71,7 @@ commands =
[testenv:gabbi]
setenv = OS_TEST_PATH=ceilometer/tests/functional/gabbi
passenv = CEILOMETER_*
commands =
bash -x {toxinidir}/setup-test-env-mongodb.sh {toxinidir}/tools/pretty_tox.sh "{posargs}"
commands = overtest mongodb {toxinidir}/tools/pretty_tox.sh "{posargs}"
[testenv:cover]
setenv = OS_TEST_PATH=ceilometer/tests
......@@ -111,19 +106,19 @@ commands = bash -x oslo_debug_helper {posargs}
[testenv:debug-mongodb]
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]
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]
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]
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]
ignore =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment