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:[email protected]/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

1class DbFixture(fixtures.Fixture):

2        """Basic database fixture.

3

4Allows to run testson various db backends, such as SQLite, MySQL and

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

6uri set env variableOS_TEST_DBAPI_ADMIN_CONNECTION with database admin

7credentials 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:[email protected]/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.




猜你喜欢

转载自blog.csdn.net/chenwei8280/article/details/52699821