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