Wrong migration step run when file names are the same

Bug #1658116 reported by Ron De Rose
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Identity (keystone)
Fix Released
High
Ron De Rose

Bug Description

We've seen a couple instances now where the wrong migration step is run in tests, when the migration file names in each repo are the same. For example, in the following patch, expand was called, yet the contract file was the one actually run:

Traceback (most recent call last):
  File "keystone/tests/unit/test_sql_upgrade.py", line 1964, in test_migration_013_add_domain_id_to_user
    self.expand(13)
  File "keystone/tests/unit/test_sql_upgrade.py", line 228, in expand
    self.repos[EXPAND_REPO].upgrade(*args, **kwargs)
  File "keystone/common/sql/upgrades.py", line 63, in upgrade
    self.schema_.runchange(ver, change, changeset.step)
  File "/home/jenkins/workspace/gate-keystone-python27-db-ubuntu-xenial/.tox/py27/local/lib/python2.7/site-packages/migrate/versioning/schema.py", line 93, in runchange
    change.run(self.engine, step)
  File "/home/jenkins/workspace/gate-keystone-python27-db-ubuntu-xenial/.tox/py27/local/lib/python2.7/site-packages/migrate/versioning/script/py.py", line 148, in run
    script_func(engine)
  File "/home/jenkins/workspace/gate-keystone-python27-db-ubuntu-xenial/keystone/common/sql/contract_repo/versions/013_add_domain_id_to_user.py", line 43, in upgrade
    migrate.UniqueConstraint(user.c.id, user.c.domain_id,
  File "/home/jenkins/workspace/gate-keystone-python27-db-ubuntu-xenial/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/util/_collections.py", line 212, in __getattr__
    raise AttributeError(key)
AttributeError: domain_id

http://logs.openstack.org/74/409874/29/check/gate-keystone-python27-db-ubuntu-xenial/d2a60fd/testr_results.html.gz

Likewise, morgan was seeing a similar issue here, where the expand migration file wasn't being run, so the test failed the table exist check:
https://review.openstack.org/#/c/422817/3/keystone/tests/unit/test_sql_upgrade.py

http://eavesdrop.openstack.org/irclogs/%23openstack-keystone/%23openstack-keystone.2017-01-20.log.html

However, both patches would run successfully locally.

As a workaround, making the repo file names unique fixes the problem, suggesting that perhaps this is related to the files being cached.

description: updated
description: updated
description: updated
Changed in keystone:
assignee: nobody → Ron De Rose (ronald-de-rose)
tags: added: sql
Revision history for this message
Rodrigo Duarte (rodrigodsousa) wrote :

good catch! that's why we see some strange behavior in the banned operations tests

Dolph Mathews (dolph)
Changed in keystone:
importance: Undecided → High
Revision history for this message
David Stanek (dstanek) wrote :

This looks somewhat related to an issue I fixes a while ago in the tests: https://review.openstack.org/#/c/371075/

Revision history for this message
Steve Martinelli (stevemar) wrote :

I believe this only affects tests, can someone confirm? We can lower the severity if thats the case

tags: added: test-improvement
Changed in keystone:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix proposed to keystone (master)

Related fix proposed to branch: master
Review: https://review.openstack.org/433644

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix merged to keystone (master)

Reviewed: https://review.openstack.org/433644
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=2b0050af2050f9b98d4a3d6a36c8decfc59f32ea
Submitter: Jenkins
Branch: master

commit 2b0050af2050f9b98d4a3d6a36c8decfc59f32ea
Author: Rodrigo Duarte Sousa <email address hidden>
Date: Tue Feb 14 10:26:54 2017 -0300

    Rename protocol cascade delete migration file

    Due the related bug, the file names weren't being correctly processed.
    This patch renames the files to use different names accordingly to their
    phases. Renaming the files also enables the possibility of removing the
    migration from the data_migration banned tests.

    Change-Id: I2413686cd8c89c88397fd3923fe9491015a8c534
    Related-Bug: 1658116

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to keystone (master)

Reviewed: https://review.openstack.org/429912
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=eb1c186f10a4d0cfdcc53fbcf49c005cd9c4349d
Submitter: Jenkins
Branch: master

commit eb1c186f10a4d0cfdcc53fbcf49c005cd9c4349d
Author: Ronald De Rose <email address hidden>
Date: Mon Feb 6 22:45:14 2017 +0000

    Ensure migration file names are unique to avoid caching errors

    This patch requires migration files to include a prefix (expand,
    migrate, contract) in order to keep them unique and prevent a bug
    related to caching. Here is the standard format:
    [version]_[prefix]_[description]

    For example:
    * 001_expand_new_fk_constraint.py
    * 001_migrate_new_fk_constraint.py
    * 001_contract_new_fk_constraint.py

    Closes-Bug: #1658116
    Change-Id: I3431381abfe4d9fd15512c5c7beb6ab0028dc38e

Changed in keystone:
status: In Progress → Fix Released
Changed in keystone:
milestone: none → pike-1
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/keystone 12.0.0.0b1

This issue was fixed in the openstack/keystone 12.0.0.0b1 development milestone.

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

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.