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
Previously opportunistic db test cases used to share openstack_citest
database among all test cases, which could be run concurrently in
different test running processes.
With recent changes made to our CI, we now can create and drop
database schemas on demand in tests. Providing each opportunistic db
test case with its own DB will effectively prevent possible races.
Related-Bug: #1288916
Change-Id: I7f6e272eaeb776b6a645ba502853892e79312afd
Module openstack.common.test is obsolete, so we should use
oslotest library instead of it.
Modified tests and common database code, new requirement added.
Change-Id: I853e548f11a4c3785eaf75124510a6d789536634
We're getting hit hard with db race problems right now and the
proper fix can't go in until infra has all of their regions
updated. Using the lock fixture to serialize all of the db tests
should help with the problem until infra is ready.
Change-Id: If883832b0eba08f1508a247310b8eebd67b27971
Partial-Bug: #1288916
oslo.db is meant to be a collection of helper utilities for
SQLAlchemy. In order to behave like a 'good' library, we must
stop using global state.
This patch ensures we don't store any engine instances globally in
oslo.db. It's up to end applications to decide how to cope with
engines, not oslo.db.
Partial-Bug: #1263908
Co-authored-by: Victor Sergeyev <vsergeyev@mirantis.com>
Change-Id: I330467ec1317e1a13ff9f0237e2d8900d718e379
tests/unit/db/sqlalchemy/base.py moved to
openstack/common/db/sqlalchemy/test_base.py for further reuse in other
projects.
Change-Id: I5cf83a63f148f48ff7c38a1ad4cc714f08e60fd1
_get_connect_string() is too specific when choosing a DB API driver to be
used. We shouldn't force users to use neither psycopg2 nor MySQLdb as this is
not required for any actions provided by oslo.db. Specify only the dialect to
be used and let SQLAlchemy choose one of the DB API drivers available.
Closes-Bug: #1256835
Change-Id: I685f9eecc77f2c1f920c83c5da653f3114a83679
Database utilities are contained in
openstack/common/db/sqlalchemy/test_migrations.py which is not
appropriate to the module appointment. All the utility functions moved
to openstack/common/db/sqlalchemy/utils.py.
Change-Id: Ia5e1efd3f8e2e1f9553ca24ca7bb19bea911cdbc
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
Added testing functionality for using different db backends. Сurrently
exists ability to define backend-specific tests along with regular
tests. Assuming that the tests will be run under a variety of backend
there exists opportunity to skip backend-specific tests at
inappropriate backends. For the correct functioning of the tests required to
export environment variable with a root access database uri.
Blueprint: tests-given-db-backend
Change-Id: Ic5d3cfe8764b3c04affe79088473255c17535e54
It is the last step to replace using tests.utils with
stack.common.test.
In this patch database tests is changed for using
openstack.common.test and added needed fixtures in test classes.
Blueprint: common-unit-tests
Change-Id: I9b360f9a8dc72bc3fb697e571555775bde10ef61
Currently, SQLite DB in a file is used for testing of DB related
code. Thus, in each test case we have to ensure that tearDown()
drops all created tables, etc. It is much easier and cleaner to
guarantee that DB is in the original state by creating it in
memory instead.
Change-Id: I6f0a9735a0fb31bef30842afff50c6089fa2bf92