Run unit tests against PostgreSQL
* Creates a new tox env py-pgsql * Adds a new script setupt-test-env-postgresql.sh to set up postgresql * Renames the MySQLDbManager into SQLManage, used by both mysql and postgresql tests * Creates a new scenario for posgresql in the MixinTestsWithBackendScenarios Related to blueprint sql-unit-tests-on-real-backend Co-Authored-By: Ala Rezmerita <ala.rezmerita@cloudwatt.com> Change-Id: I60af82d5d8b5750884ba0d1ca726645f8b31448b
This commit is contained in:
parent
1278d067ef
commit
52598e1272
@ -63,13 +63,13 @@ class MongoDbManager(fixtures.Fixture):
|
||||
}
|
||||
|
||||
|
||||
class MySQLDbManager(fixtures.Fixture):
|
||||
class SQLManager(fixtures.Fixture):
|
||||
|
||||
def __init__(self, url):
|
||||
self._url = url
|
||||
|
||||
def setUp(self):
|
||||
super(MySQLDbManager, self).setUp()
|
||||
super(SQLManager, self).setUp()
|
||||
self.connection = storage.get_connection(
|
||||
self.url, 'ceilometer.metering.storage')
|
||||
self.alarm_connection = storage.get_connection(
|
||||
@ -135,7 +135,8 @@ class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase):
|
||||
|
||||
DRIVER_MANAGERS = {
|
||||
'mongodb': MongoDbManager,
|
||||
'mysql': MySQLDbManager,
|
||||
'mysql': SQLManager,
|
||||
'postgresql': SQLManager,
|
||||
'db2': MongoDbManager,
|
||||
'sqlite': SQLiteManager,
|
||||
'hbase': HBaseManager,
|
||||
@ -222,7 +223,7 @@ class MixinTestsWithBackendScenarios(object):
|
||||
('sqlite', {'db_url': 'sqlite://'}),
|
||||
]
|
||||
|
||||
for db in ('MONGODB', 'MYSQL', 'HBASE', 'DB2'):
|
||||
for db in ('MONGODB', 'MYSQL', 'PGSQL', 'HBASE', 'DB2'):
|
||||
if os.environ.get('CEILOMETER_TEST_%s_URL' % db):
|
||||
scenarios.append(
|
||||
(db.lower(), {'db_url': os.environ.get(
|
||||
|
27
setup-test-env-postgresql.sh
Normal file
27
setup-test-env-postgresql.sh
Normal file
@ -0,0 +1,27 @@
|
||||
#!/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 pg_config
|
||||
|
||||
# Start PostgreSQL process for tests
|
||||
PGSQL_DATA=`mktemp -d /tmp/CEILO-PGSQL-XXXXX`
|
||||
trap "clean_exit ${PGSQL_DATA}" EXIT
|
||||
PGSQL_PATH=`pg_config --bindir`
|
||||
${PGSQL_PATH}/initdb ${PGSQL_DATA}
|
||||
mkfifo ${PGSQL_DATA}/out
|
||||
${PGSQL_PATH}/postgres -N 100 -F -k ${PGSQL_DATA} -D ${PGSQL_DATA} -p 9823 &> ${PGSQL_DATA}/out &
|
||||
# Wait for PostgreSQL to start listening to connections
|
||||
wait_for_line "database system is ready to accept connections" ${PGSQL_DATA}/out
|
||||
export CEILOMETER_TEST_PGSQL_URL="postgresql:///?host=${PGSQL_DATA}&port=9823&dbname=template1"
|
||||
|
||||
# Yield execution to venv command
|
||||
$*
|
@ -15,6 +15,7 @@ MySQL-python
|
||||
# Docs Requirements
|
||||
oslosphinx>=2.2.0 # Apache-2.0
|
||||
oslotest>=1.1.0 # Apache-2.0
|
||||
psycopg2
|
||||
pymongo>=2.5
|
||||
python-subunit>=0.0.18
|
||||
sphinx>=1.1.2,!=1.2.0,<1.3
|
||||
|
8
tox.ini
8
tox.ini
@ -1,7 +1,7 @@
|
||||
[tox]
|
||||
minversion = 1.6
|
||||
skipsdist = True
|
||||
envlist = py26,py27,py27-mysql,py33,pep8
|
||||
envlist = py26,py27,py33,py-mysql,py-pgsql,pep8
|
||||
|
||||
[testenv]
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
@ -16,10 +16,14 @@ commands =
|
||||
downloadcache = {toxworkdir}/_download
|
||||
whitelist_externals = bash
|
||||
|
||||
[testenv:py27-mysql]
|
||||
[testenv:py-mysql]
|
||||
commands =
|
||||
bash -x {toxinidir}/setup-test-env-mysql.sh python setup.py testr --slowest --testr-args="{posargs}"
|
||||
|
||||
[testenv:py-pgsql]
|
||||
commands =
|
||||
bash -x {toxinidir}/setup-test-env-postgresql.sh python setup.py testr --slowest --testr-args="{posargs}"
|
||||
|
||||
[testenv:py33]
|
||||
deps = -r{toxinidir}/requirements-py3.txt
|
||||
-r{toxinidir}/test-requirements-py3.txt
|
||||
|
Loading…
Reference in New Issue
Block a user