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

本文介绍如何配置并运行Keystone针对MySQL或PostgreSQL的真实数据库测试案例,而非默认的SQLite数据库。通过设置环境变量OS_TEST_DBAPI_ADMIN_CONNECTION指定数据库连接字符串,可以启用对真实数据库的支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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: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.




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值