unit tests don't enable Foreign Key for Sqlite

Bug #1744195 reported by wangxiyuan on 2018-01-19
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Identity (keystone)
Medium
wangxiyuan

Bug Description

Now Keystone runs unit test with sqlite backend by default. But sqlite doesn't enable Foreign Key function by default.
It means that we lost the case for all FK related test.
Even after enabled FK for the test. There still some problems:
1. We lost root domain (<<keystone.domian.root>>) when setup tests. So that a lot of tests will fail.
2. Some tests, such as test_sql_upgrade and identity.backends.test_sql, use global db engine. It means that the test will meet conflict if the FK is enabled for the global db engine.

So we should refactor our test code to satisfy sqilte FK function.
There are some steps:
1. Add FK support for the tests. Disable it by default
2. Enable FK for the test one by one.
3. Make sure the Fk is disabled for test_sql_upgrade and identity.backends.test_sql

Changed in keystone:
assignee: nobody → wangxiyuan (wangxiyuan)
status: New → In Progress
description: updated
description: updated
Changed in keystone:
importance: Undecided → Medium
Changed in keystone:
assignee: wangxiyuan (wangxiyuan) → Morgan Fainberg (mdrnstm)

Reviewed: https://review.openstack.org/126030
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=ed2b65a5ddc8536470797c39467b20e934b02dc0
Submitter: Zuul
Branch: master

commit ed2b65a5ddc8536470797c39467b20e934b02dc0
Author: David Stanek <email address hidden>
Date: Fri Oct 3 18:22:41 2014 +0000

    Force SQLite to properly deal with foreign keys

    This will help with testing since SQLite will start enforcing the
    foreign key relationships.

    We will still have a problem with migrations for tables that refer to
    each other. SQLite can't alter tables and sqlalchemy-migrates tmp table
    strategy for migrations fails in this situation.

    This patch did:
    1. Add FK support for the tests. Disable it by default.
    2. Make sure the Fk is disabled for test_sql_upgrade and
    identity.backens.test_sql

    Partial-Bug: #1744195

    Co-Authored-By: wangxiyuan<email address hidden>
    Change-Id: I276af7c0125dc2cb2c54215d54491665db1caa22

Fix proposed to branch: master
Review: https://review.openstack.org/558029

Changed in keystone:
assignee: Morgan Fainberg (mdrnstm) → wangxiyuan (wangxiyuan)

Fix proposed to branch: master
Review: https://review.openstack.org/558173

Fix proposed to branch: master
Review: https://review.openstack.org/558184

Fix proposed to branch: master
Review: https://review.openstack.org/558192

Fix proposed to branch: master
Review: https://review.openstack.org/558193

Change abandoned by wangxiyuan (<email address hidden>) on branch: master
Review: https://review.openstack.org/558192

Change abandoned by wangxiyuan (<email address hidden>) on branch: master
Review: https://review.openstack.org/558184

Change abandoned by wangxiyuan (<email address hidden>) on branch: master
Review: https://review.openstack.org/558173

tags: added: test-improvement
Changed in keystone:
assignee: wangxiyuan (wangxiyuan) → Lance Bragstad (lbragstad)
Changed in keystone:
assignee: Lance Bragstad (lbragstad) → wangxiyuan (wangxiyuan)
Changed in keystone:
assignee: wangxiyuan (wangxiyuan) → Lance Bragstad (lbragstad)
Changed in keystone:
assignee: Lance Bragstad (lbragstad) → wangxiyuan (wangxiyuan)
Changed in keystone:
assignee: wangxiyuan (wangxiyuan) → Lance Bragstad (lbragstad)

Reviewed: https://review.openstack.org/558029
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=46a28313fcb2078870024874f51d9539ce4c364e
Submitter: Zuul
Branch: master

commit 46a28313fcb2078870024874f51d9539ce4c364e
Author: wangxiyuan <email address hidden>
Date: Sat Mar 31 12:19:02 2018 +0800

    Enable Foreign keys for sql backend unit test

    Enable the sqlite foreign keys function for unit test.

    This patch is the first part to solve sql backend test issues.

    Change-Id: I5d29d05e64b76ff6530c9af5ee39a2df1b26aa03
    Partial-Bug: #1744195

Changed in keystone:
assignee: Lance Bragstad (lbragstad) → wangxiyuan (wangxiyuan)

Reviewed: https://review.openstack.org/558193
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=012dac29b8dd6ac77e707f916fc4c0ca57d58b14
Submitter: Zuul
Branch: master

commit 012dac29b8dd6ac77e707f916fc4c0ca57d58b14
Author: wangxiyuan <email address hidden>
Date: Mon Apr 2 19:28:33 2018 +0800

    Enable foreign keys for unit test

    The unit test uses sqlite for test which closes db foreign keys
    function by default. This patch enabled the sqlite foreign keys
    function for unit test by default.

    The "project" table is a self referencing FK table(id <-> domain_id
    column). So when the FK is enabled, there must exists a root record
    before insert data to this table. It's <<keystone.domain.root>>.

    Usually, the <<keystone.domain.root>> recored is inserted into the
    table once operators run "keystone-manage db_sync" command when
    deploy Keystone. But the unit test code doesn't run this command,
    it initialise the db schema by reading sqlalchemy object model, so
    the <<keystone.domain.root>> record is missed. Then we can't create
    any project record, it'll raise FK error.

    So in this patch, before creating any projects in the test, we must
    ensure the <<keystone.domain.root>> record exists first.

    Change-Id: I565d12395ca39a58ba90faf8641a9e02d986aeb9
    Closes-Bug: #1744195

Changed in keystone:
status: In Progress → Fix Released

Reviewed: https://review.openstack.org/591946
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=c3f590bc13efcdddb3fa82e8d116239f4e8d8b1f
Submitter: Zuul
Branch: master

commit c3f590bc13efcdddb3fa82e8d116239f4e8d8b1f
Author: wangxiyuan <email address hidden>
Date: Wed Aug 15 15:43:57 2018 +0800

    Add a test for idp and federated user cascade deleting

    If a idp is deleted, the related federated user should be
    cascade deleted as well.

    Change-Id: I2c9b4052413f9a31ffc22c5f3b1bee30dda2c42a
    Partial-bug: #1744195

Changed in keystone:
milestone: none → stein-2
milestone: stein-2 → stein-1

This issue was fixed in the openstack/keystone 15.0.0.0rc1 release candidate.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers