From 0a401529947c98ab761256e233b157071a57ab70 Mon Sep 17 00:00:00 2001 From: Nachiappan VR N Date: Mon, 22 Jul 2013 15:50:33 -0700 Subject: Fixing broken credential schema in sqlite. Credential table has foreign key constraint referring to tenant table which is dropped. Since sqlite does not support alter table drop constraint, the foreign key constraint was not dropped. When we try to load credential table using sqlite backend it fails because tenant table does not exist. Fix is provided such that the credential table is recreated without foreign key constraint and the data is moved from old credential table to the new credential table. Fixes Bug #1190383 Change-Id: I3afb04254f33e12fccb7da84c8674feba36622c8 --- tests/test_sql_upgrade.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests') diff --git a/tests/test_sql_upgrade.py b/tests/test_sql_upgrade.py index 64bf53c8..ed00deae 100644 --- a/tests/test_sql_upgrade.py +++ b/tests/test_sql_upgrade.py @@ -1122,6 +1122,46 @@ class SqlUpgradeTests(test.TestCase): self.assertEqual(len(data['roles']), 1) self.assertIn(role_list[5]['id'], data['roles']) + def test_drop_credential_constraint(self): + ec2_credential = { + 'id': '100', + 'user_id': 'foo', + 'project_id': 'bar', + 'type': 'ec2', + 'blob': json.dumps({ + "access": "12345", + "secret": "12345" + }) + } + user = { + 'id': 'foo', + 'name': 'FOO', + 'password': 'foo2', + 'enabled': True, + 'email': 'foo@bar.com', + 'extra': json.dumps({'enabled': True}) + } + tenant = { + 'id': 'bar', + 'name': 'BAR', + 'description': 'description', + 'enabled': True, + 'extra': json.dumps({'enabled': True}) + } + session = self.Session() + self.upgrade(7) + self.insert_dict(session, 'user', user) + self.insert_dict(session, 'tenant', tenant) + self.insert_dict(session, 'credential', ec2_credential) + session.commit() + self.upgrade(30) + cred_table = sqlalchemy.Table('credential', + self.metadata, + autoload=True) + cred = session.query(cred_table).filter("id='100'").one() + self.assertEqual(cred.user_id, + ec2_credential['user_id']) + def populate_user_table(self, with_pass_enab=False, with_pass_enab_domain=False): # Populate the appropriate fields in the user -- cgit