Merge "Creates one database per sql test"
This commit is contained in:
commit
6ed5229dd1
@ -28,6 +28,7 @@ from oslo.config import fixture as fixture_config
|
||||
from oslotest import mockpatch
|
||||
import six
|
||||
from six.moves.urllib import parse as urlparse
|
||||
import sqlalchemy
|
||||
import testscenarios.testcase
|
||||
from testtools import testcase
|
||||
|
||||
@ -66,10 +67,6 @@ class MongoDbManager(fixtures.Fixture):
|
||||
|
||||
|
||||
class SQLManager(fixtures.Fixture):
|
||||
|
||||
def __init__(self, url):
|
||||
self._url = url
|
||||
|
||||
def setUp(self):
|
||||
super(SQLManager, self).setUp()
|
||||
self.connection = storage.get_connection(
|
||||
@ -81,7 +78,31 @@ class SQLManager(fixtures.Fixture):
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return self._url
|
||||
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)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
class HBaseManager(fixtures.Fixture):
|
||||
@ -143,8 +164,8 @@ class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase):
|
||||
|
||||
DRIVER_MANAGERS = {
|
||||
'mongodb': MongoDbManager,
|
||||
'mysql': SQLManager,
|
||||
'postgresql': SQLManager,
|
||||
'mysql': MySQLManager,
|
||||
'postgresql': PgSQLManager,
|
||||
'db2': MongoDbManager,
|
||||
'sqlite': SQLiteManager,
|
||||
'hbase': HBaseManager,
|
||||
|
@ -22,9 +22,7 @@ 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_MYSQL_URL="mysql://root@localhost/ceilometer?unix_socket=${MYSQL_DATA}/mysql.socket&charset=utf8"
|
||||
|
||||
mysql -S ${MYSQL_DATA}/mysql.socket -e 'CREATE DATABASE ceilometer;'
|
||||
export CEILOMETER_TEST_MYSQL_URL="mysql://root@localhost/template1?unix_socket=${MYSQL_DATA}/mysql.socket&charset=utf8"
|
||||
|
||||
# Yield execution to venv command
|
||||
$*
|
||||
|
Loading…
Reference in New Issue
Block a user