How to run keystone testcase against the DB backend other than SQLITE

前端之家收集整理的这篇文章主要介绍了How to run keystone testcase against the DB backend other than SQLITE前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Keystone has the testcase that need run against real live DB such as MysqL or Postgresql other than sqlITE.


But it just skipped when you try to run the testcase in the usual way like this.


$ python -m unittest keystone.tests.unit.test_sql_upgrade.MysqLOpportunisticFullMigration.test_trust_fk_on_delete_cascade_enforced
s
----------------------------------------------------------------------
Ran 1 test in 0.053s


OK (skipped=1)



Before Keystone Newtone release,we have the configure file that support to configure the connection string and let the testcase run with that connections.


Example in the Mitaka:

diff --git a/keystone/tests/unit/config_files/backend_MysqL.conf b/keystone/tests/unit/config_files/backend_MysqL.conf

index2495f03..65b22d3 100644

---a/keystone/tests/unit/config_files/backend_MysqL.conf

+++b/keystone/tests/unit/config_files/backend_MysqL.conf

@@-1,4 +1,5 @@

#Used for running the Migrate tests against alive MysqL Server

#See _sql_livetest.py

[database]

-connection= MysqL+pyMysqL://keystone:keystone@localhost/keystone_test?charset=utf8

+#connection= MysqL+pyMysqL://keystone:keystone@localhost/keystone_test?charset=utf8

+connection= MysqL+pyMysqL://root:zaq12wsx@127.0.0.1/abc?charset=utf8



But we have have dropped all these support in Newton,so how to do with it if there is a need to run these live testcases?


Based on the manual from oslo.db,we can get some clue on that. It says we should set the DB connection string to make it use the real live DB.

Quote:

#oslo.db\oslo_db\sqlalchemy\test_base.py

1 class DbFixture(fixtures.Fixture):

2 """Basic database fixture.

3

4 Allows to run testson varIoUs db backends,such as sqlite,MysqL and

5 Postgresql. Bydefault use sqlite backend. To override default backend

6 uri set env variableOS_TEST_DBAPI_ADMIN_CONNECTION with database admin

7 credentials forspecific backend.

8 """

9

10 DRIVER= "sqlite"

So,before you run the live test,you should set the connection string by set the ENV as this:

exportOS_TEST_DBAPI_ADMIN_CONNECTION=MysqL+pyMysqL://root:zaq12wsx@127.0.0.1/abc?charset=utf8

Then runthe testcase in your usual way

testr runkeystone.tests.unit.test_sql_upgrade.MysqLOpportunisticFullMigration.test_trust_fk_on_delete_cascade_enforced

Or for the dubug mode:

python -m unittestkeystone.tests.unit.test_sql_upgrade.MysqLOpportunisticFullMigration.test_trust_fk_on_delete_cascade_enforced

Then it will use the live DB for test.

猜你在找的Sqlite相关文章