summaryrefslogtreecommitdiffstats
path: root/tests/test_sql_upgrade.py
diff options
context:
space:
mode:
authorBrant Knudson <bknudson@us.ibm.com>2013-06-07 14:47:49 -0500
committerBrant Knudson <bknudson@us.ibm.com>2013-07-01 11:07:40 -0500
commit052e7d525146c235f3c4ddc729ee6e1ac18a1337 (patch)
treeebdad760836d830a6a187b1b26bba6590017c486 /tests/test_sql_upgrade.py
parent6362fb73eda13e7710226a72a083ad9918410bd9 (diff)
downloadkeystone-052e7d525146c235f3c4ddc729ee6e1ac18a1337.tar.gz
keystone-052e7d525146c235f3c4ddc729ee6e1ac18a1337.tar.xz
keystone-052e7d525146c235f3c4ddc729ee6e1ac18a1337.zip
DB2 migration support
DB2 will not allow you to rename a table if it's got a constraint on it (a unique or foreign key constraint). This fix changes the migrations so that the unique or FK constraints are dropped from tables before renaming and then restoring the unique FK constraints. This works for DB2 and other DBMSs that support FK constraints such as MySQL with InnoDB and PostgreSQL. Also, for DB2, give a name to the unique constraints so that they can be manipulated. Fixes bug 1188785 Change-Id: I7cf6ab42084e43d827ed827c64025e61e72a4672
Diffstat (limited to 'tests/test_sql_upgrade.py')
-rw-r--r--tests/test_sql_upgrade.py35
1 files changed, 20 insertions, 15 deletions
diff --git a/tests/test_sql_upgrade.py b/tests/test_sql_upgrade.py
index ac4e5637..21db6ade 100644
--- a/tests/test_sql_upgrade.py
+++ b/tests/test_sql_upgrade.py
@@ -597,17 +597,19 @@ class SqlUpgradeTests(test.TestCase):
user_project_metadata_table = sqlalchemy.Table(
'user_project_metadata', self.metadata, autoload=True)
- r = session.execute('select data from metadata where '
- 'user_id=:user and tenant_id=:tenant',
- {'user': user['id'], 'tenant': project['id']})
+ s = sqlalchemy.select([metadata_table.c.data]).where(
+ (metadata_table.c.user_id == user['id']) &
+ (metadata_table.c.tenant_id == project['id']))
+ r = session.execute(s)
test_project1 = json.loads(r.fetchone()['data'])
self.assertEqual(len(test_project1['roles']), 1)
self.assertIn(role['id'], test_project1['roles'])
# Test user in project2 has role2
- r = session.execute('select data from metadata where '
- 'user_id=:user and tenant_id=:tenant',
- {'user': user['id'], 'tenant': project2['id']})
+ s = sqlalchemy.select([metadata_table.c.data]).where(
+ (metadata_table.c.user_id == user['id']) &
+ (metadata_table.c.tenant_id == project2['id']))
+ r = session.execute(s)
test_project2 = json.loads(r.fetchone()['data'])
self.assertEqual(len(test_project2['roles']), 1)
self.assertIn(role2['id'], test_project2['roles'])
@@ -615,9 +617,10 @@ class SqlUpgradeTests(test.TestCase):
# Test for user in project has role in user_project_metadata
# Migration 17 does not properly migrate this data, so this should
# be None.
- r = session.execute('select data from user_project_metadata where '
- 'user_id=:user and project_id=:project',
- {'user': user['id'], 'project': project['id']})
+ s = sqlalchemy.select([user_project_metadata_table.c.data]).where(
+ (user_project_metadata_table.c.user_id == user['id']) &
+ (user_project_metadata_table.c.project_id == project['id']))
+ r = session.execute(s)
self.assertIsNone(r.fetchone())
# Create a conflicting user-project in user_project_metadata with
@@ -638,9 +641,10 @@ class SqlUpgradeTests(test.TestCase):
# The user-project pairs should have all roles from the previous
# metadata table in addition to any roles currently in
# user_project_metadata
- r = session.execute('select data from user_project_metadata where '
- 'user_id=:user and project_id=:project',
- {'user': user['id'], 'project': project['id']})
+ s = sqlalchemy.select([user_project_metadata_table.c.data]).where(
+ (user_project_metadata_table.c.user_id == user['id']) &
+ (user_project_metadata_table.c.project_id == project['id']))
+ r = session.execute(s)
role_ids = json.loads(r.fetchone()['data'])['roles']
self.assertEqual(len(role_ids), 3)
self.assertIn(CONF.member_role_id, role_ids)
@@ -649,9 +653,10 @@ class SqlUpgradeTests(test.TestCase):
# pairs that only existed in old metadata table should be in
# user_project_metadata
- r = session.execute('select data from user_project_metadata where '
- 'user_id=:user and project_id=:project',
- {'user': user['id'], 'project': project2['id']})
+ s = sqlalchemy.select([user_project_metadata_table.c.data]).where(
+ (user_project_metadata_table.c.user_id == user['id']) &
+ (user_project_metadata_table.c.project_id == project2['id']))
+ r = session.execute(s)
role_ids = json.loads(r.fetchone()['data'])['roles']
self.assertEqual(len(role_ids), 2)
self.assertIn(CONF.member_role_id, role_ids)