Added opportunistic DB test cases
These test cases are meant to be run opportunistically within the general test suite, i.e. only when openstack_citest database is available (which is always true for our CI infrastructure, but might not be true for developers machines). This is similar to how we run migrations tests in all OpenStack projects Blueprint: tests-given-db-backend Change-Id: Ic3706763c8fc56c0fcf4d1964ed1c5f17a662be6
This commit is contained in:
parent
8a01dd8e68
commit
42ef1d7b9a
@ -13,13 +13,16 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import abc
|
||||
from functools import wraps
|
||||
import os
|
||||
|
||||
import fixtures
|
||||
from oslo.config import cfg
|
||||
import six
|
||||
|
||||
from openstack.common.db.sqlalchemy import session
|
||||
from openstack.common.db.sqlalchemy import test_migrations as tm
|
||||
from tests import utils as test_utils
|
||||
|
||||
|
||||
@ -90,3 +93,62 @@ def backend_specific(*dialects):
|
||||
return f(self)
|
||||
return ins_wrap
|
||||
return wrap
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class OpportunisticFixture(DbFixture):
|
||||
"""Base fixture to use default CI databases.
|
||||
|
||||
The databases exist in OpenStack CI infrastructure. But for the
|
||||
correct functioning in local environment the databases must be
|
||||
created manually.
|
||||
"""
|
||||
|
||||
DRIVER = abc.abstractproperty(lambda: None)
|
||||
DBNAME = PASSWORD = USERNAME = 'openstack_citest'
|
||||
|
||||
def _get_uri(self):
|
||||
return tm._get_connect_string(backend=self.DRIVER,
|
||||
user=self.USERNAME,
|
||||
passwd=self.PASSWORD,
|
||||
database=self.DBNAME)
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class OpportunisticTestCase(DbTestCase):
|
||||
"""Base test case to use default CI databases.
|
||||
|
||||
The subclasses of the test case are running only when openstack_citest
|
||||
database is available otherwise a tests will be skipped.
|
||||
"""
|
||||
|
||||
FIXTURE = abc.abstractproperty(lambda: None)
|
||||
|
||||
def setUp(self):
|
||||
credentials = (
|
||||
self.FIXTURE.DRIVER,
|
||||
self.FIXTURE.USERNAME,
|
||||
self.FIXTURE.PASSWORD,
|
||||
self.FIXTURE.DBNAME)
|
||||
|
||||
if self.FIXTURE.DRIVER and not tm._is_backend_avail(*credentials):
|
||||
msg = '%s backend is not available.' % self.FIXTURE.DRIVER
|
||||
return self.skip(msg)
|
||||
|
||||
super(OpportunisticTestCase, self).setUp()
|
||||
|
||||
|
||||
class MySQLOpportunisticFixture(OpportunisticFixture):
|
||||
DRIVER = 'mysql'
|
||||
|
||||
|
||||
class PostgreSQLOpportunisticFixture(OpportunisticFixture):
|
||||
DRIVER = 'postgresql'
|
||||
|
||||
|
||||
class MySQLOpportunisticTestCase(OpportunisticTestCase):
|
||||
FIXTURE = MySQLOpportunisticFixture
|
||||
|
||||
|
||||
class PostgreSQLOpportunisticTestCase(OpportunisticTestCase):
|
||||
FIXTURE = PostgreSQLOpportunisticFixture
|
||||
|
Loading…
Reference in New Issue
Block a user