summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Podoliaka <rpodolyaka@mirantis.com>2014-06-12 12:22:49 +0300
committerRoman Podoliaka <rpodolyaka@mirantis.com>2014-06-13 15:04:45 +0300
commit314496a5815f9e946f1ec87e6e6610c44bfc07bd (patch)
tree6c9038c06f3abdc2af79c611c2e43b691cc60dd5
parent5c9f7b7ecdf05a44c35fa563f6aa7071c0d566a7 (diff)
downloadoslo-db-314496a5815f9e946f1ec87e6e6610c44bfc07bd.tar.gz
Prevent races in opportunistic db test cases
Opportunistic db test cases create schemas on demand, so that each test case which inherits the base test case class, will get its own db schema (i. e. races between tests are not possible). In order to do schema provisioning we have to connect to RDBMS server first. So far we've been connecting to the openstack_citest database, which is guaranteed to exist on CI nodes. It turns out, there are a few test cases in Nova (maybe in other projects as well), that drop and recreate the openstack_citest database. If they happen to do that when the opportunistic db fixture is in the middle of provisioning a schema, those tests will fail (as there is an an open session to the database and thus it can't be dropped). This can be solved easily by changing the way we provision new schemas in opportunistic db test cases as actually, we don't have to connect to the openstack_citest database at all: - for MySQL we can use an empty db name to connect to MySQL server, but not to a particular database - PostgreSQL requires us to specify the database name. We can use the service postgres database here (PostgreSQL shell utils such as createdb, createuser, etc use it for the very same reason) Closes-Bug: #1328997 Change-Id: I0dc0becc5cb40d3dab3289c865a96113522a0b9a
-rw-r--r--oslo/db/sqlalchemy/test_base.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/oslo/db/sqlalchemy/test_base.py b/oslo/db/sqlalchemy/test_base.py
index 7664faa..544568e 100644
--- a/oslo/db/sqlalchemy/test_base.py
+++ b/oslo/db/sqlalchemy/test_base.py
@@ -151,10 +151,12 @@ class OpportunisticTestCase(DbTestCase):
class MySQLOpportunisticFixture(OpportunisticFixture):
DRIVER = 'mysql'
+ DBNAME = '' # connect to MySQL server, but not to the openstack_citest db
class PostgreSQLOpportunisticFixture(OpportunisticFixture):
DRIVER = 'postgresql'
+ DBNAME = 'postgres' # PostgreSQL requires the db name here,use service one
class MySQLOpportunisticTestCase(OpportunisticTestCase):