migration of endpoint_filter fails due to foreign key constraint

Bug #1399768 reported by Adam Young
22
This bug affects 3 people
Affects Status Importance Assigned to Milestone
OpenStack Identity (keystone)
Fix Released
High
Dave Chen
Juno
Fix Released
High
Steve Martinelli

Bug Description

 keystone-manage db_sync --extension endpoint_filter 2

fails with

2014-12-05 13:54:39.295 11241 TRACE keystone OperationalError: (OperationalError) (1005, "Can't create table 'keystone.project_endpoint_group' (errno: 150)") '\nCREATE TABLE project_endpoint_group (\n\tendpoint_group_id VARCHAR(64) NOT NULL, \n\tproject_id VARCHAR(64) NOT NULL, \n\tPRIMARY KEY (endpoint_group_id, project_id), \n\tFOREIGN KEY(endpoint_group_id) REFERENCES endpoint_group (id)\n)\n\n' ()

Migration 1 fails executing the below sql.

CREATE TABLE project_endpoint_group (endpoint_group_id VARCHAR(64) NOT NULL, project_id VARCHAR(64) NOT NULL, PRIMARY KEY (endpoint_group_id, project_id), FOREIGN KEY(endpoint_group_id) REFERENCES endpoint_group (id));
ERROR 1005 (HY000): Can't create table 'keystone.project_endpoint_group' (errno: 150)

Removing the clause FOREIGN KEY(endpoint_group_id) REFERENCES endpoint_group (id)) makes it work.

THis is on Fedora 20 and I mariadb flavor of MySQL.

Revision history for this message
Adam Young (ayoung) wrote :

Looks like I had an old .pyc file causing this

Changed in keystone:
status: New → Invalid
Revision history for this message
Dag Stenstad (dag-stenstad) wrote :

Are you sure? I think the problem here is that the endpoint_group table does not have a primary key/index.

If I set endpoint_group.id as the primary key, this migration step works. If not, it fails.

Revision history for this message
Dave Chen (wei-d-chen) wrote :
Download full text (5.7 KiB)

Hit the same issue with follow error message, will look into the issue and check whether this is caused by the old .pyc as ayong methioned.

/usr/local/bin/keystone-manage db_sync --extension endpoint_filter

31365 TRACE keystone Traceback (most recent call last):
31365 TRACE keystone File "/usr/local/bin/keystone-manage", line 6, in <module>
31365 TRACE keystone exec(compile(open(__file__).read(), __file__, 'exec'))
31365 TRACE keystone File "/opt/stack/keystone/bin/keystone-manage", line 44, in <module>
31365 TRACE keystone cli.main(argv=sys.argv, config_files=config_files)
31365 TRACE keystone File "/opt/stack/keystone/keystone/cli.py", line 311, in main
31365 TRACE keystone CONF.command.cmd_class.main()
31365 TRACE keystone File "/opt/stack/keystone/keystone/cli.py", line 74, in main
31365 TRACE keystone migration_helpers.sync_database_to_version(extension, version)
31365 TRACE keystone File "/opt/stack/keystone/keystone/common/sql/migration_helpers.py", line 211, in sync_database_to_version
31365 TRACE keystone _sync_extension_repo(extension, version)
31365 TRACE keystone File "/opt/stack/keystone/keystone/common/sql/migration_helpers.py", line 199, in _sync_extension_repo
31365 TRACE keystone init_version=init_version)
31365 TRACE keystone File "/usr/local/lib/python2.7/dist-packages/oslo_db/sqlalchemy/migration.py", line 79, in db_sync
31365 TRACE keystone return versioning_api.upgrade(engine, repository, version)
31365 TRACE keystone File "/usr/local/lib/python2.7/dist-packages/migrate/versioning/api.py", line 186, in upgrade
31365 TRACE keystone return _migrate(url, repository, version, upgrade=True, err=err, **opts)
31365 TRACE keystone File "<string>", line 2, in _migrate
31365 TRACE keystone File "/usr/local/lib/python2.7/dist-packages/migrate/versioning/util/__init__.py", line 160, in with_engine
31365 TRACE keystone return f(*a, **kw)
31365 TRACE keystone File "/usr/local/lib/python2.7/dist-packages/migrate/versioning/api.py", line 366, in _migrate
31365 TRACE keystone schema.runchange(ver, change, changeset.step)
31365 TRACE keystone File "/usr/local/lib/python2.7/dist-packages/migrate/versioning/schema.py", line 93, in runchange
31365 TRACE keystone change.run(self.engine, step)
31365 TRACE keystone File "/usr/local/lib/python2.7/dist-packages/migrate/versioning/script/py.py", line 148, in run
31365 TRACE keystone script_func(engine)
31365 TRACE keystone File "/opt/stack/keystone/keystone/contrib/endpoint_filter/migrate_repo/versions/002_add_endpoint_groups.py", line 41, in upgrade
31365 TRACE keystone project_endpoint_group_table.create(migrate_engine, checkfirst=True)
31365 TRACE keystone File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/schema.py", line 707, in create
31365 TRACE keystone checkfirst=checkfirst)
31365 TRACE keystone File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1616, in _run_visitor
31365 TRACE keystone conn._run_visitor(visitorcallable, element, **kwargs)
31365 TRACE keystone File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1245, in _run_visi...

Read more...

Changed in keystone:
status: Invalid → New
assignee: nobody → Dave Chen (wei-d-chen)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to keystone (master)

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

Changed in keystone:
status: New → In Progress
Changed in keystone:
importance: Undecided → High
milestone: none → kilo-3
Changed in keystone:
assignee: Dave Chen (wei-d-chen) → Steve Martinelli (stevemar)
Changed in keystone:
assignee: Steve Martinelli (stevemar) → Dave Chen (wei-d-chen)
summary: - migration ofr endpoint_filter failes due to foreign key constraint
+ migration of endpoint_filter fails due to foreign key constraint
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to keystone (master)

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

commit 676457bdca63260ecf675848e34cb01e34822051
Author: Dave Chen <email address hidden>
Date: Mon Feb 2 04:16:30 2015 +0800

    Fix the syntax issue on creating table `endpoint_group`

    Migration of `endpoint_filter` to version 2 will fail when the backend
    DB is MYSQL instead of SQLite, `primary_key` need to be explicitly specified
    in order to setup the ForeignKey relationship between two tables.

    Current testcase `keystone.tests.test_sql_migrate_extensions.
    EndpointFilterExtension.test_upgrade` can pass the verification since SQLite
    don't check this when emitting CREATE statements for tables.

    Closes-Bug: #1399768
    Change-Id: I82b3fddb921c7c2d2fdecf8add981da37f5319f7

Changed in keystone:
status: In Progress → Fix Committed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to keystone (stable/juno)

Fix proposed to branch: stable/juno
Review: https://review.openstack.org/155512

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

Reviewed: https://review.openstack.org/155512
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=d8b145eac18e6b8f5df37341c1a959ff82cacfaf
Submitter: Jenkins
Branch: stable/juno

commit d8b145eac18e6b8f5df37341c1a959ff82cacfaf
Author: Dave Chen <email address hidden>
Date: Mon Feb 2 04:16:30 2015 +0800

    Fix the syntax issue on creating table `endpoint_group`

    Migration of `endpoint_filter` to version 2 will fail when the backend
    DB is MYSQL instead of SQLite, `primary_key` need to be explicitly specified
    in order to setup the ForeignKey relationship between two tables.

    Current testcase `keystone.tests.test_sql_migrate_extensions.
    EndpointFilterExtension.test_upgrade` can pass the verification since SQLite
    don't check this when emitting CREATE statements for tables.

    (cherry picked from commit 676457bdca63260ecf675848e34cb01e34822051)

    Closes-Bug: #1399768
    Change-Id: I82b3fddb921c7c2d2fdecf8add981da37f5319f7

Thierry Carrez (ttx)
Changed in keystone:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in keystone:
milestone: kilo-3 → 2015.1.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

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