From 6b6249b5ff6112a7150f6f609480e268fe42ea4d Mon Sep 17 00:00:00 2001 From: wanghao Date: Tue, 8 Mar 2016 13:57:15 +0800 Subject: [PATCH] Add volumes table definition when migrating to 67 When migrating DB to 67 readd_iscsi_targets_table, we will add foreign key "volumes.id", but we miss to define the volumes table, that will cause the migrating process fail: 'NoReferencedTableError'. Fix this issue by adding volume table definition before creating iscsi_targets table. test is added as well. Change-Id: Id0e0970517a5d3414e0ed124b2b7b3a5b1973761 Closes-Bug: #1554329 --- .../migrate_repo/versions/067_readd_iscsi_targets_table.py | 1 + cinder/tests/unit/test_migrations.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/cinder/db/sqlalchemy/migrate_repo/versions/067_readd_iscsi_targets_table.py b/cinder/db/sqlalchemy/migrate_repo/versions/067_readd_iscsi_targets_table.py index 4efe0ed48..c0ba4f3a3 100644 --- a/cinder/db/sqlalchemy/migrate_repo/versions/067_readd_iscsi_targets_table.py +++ b/cinder/db/sqlalchemy/migrate_repo/versions/067_readd_iscsi_targets_table.py @@ -17,6 +17,7 @@ from sqlalchemy import Integer, MetaData, String, Table def upgrade(migrate_engine): meta = MetaData() meta.bind = migrate_engine + Table('volumes', meta, autoload=True) table = Table( 'iscsi_targets', meta, diff --git a/cinder/tests/unit/test_migrations.py b/cinder/tests/unit/test_migrations.py index 50f3eca28..b6d977369 100644 --- a/cinder/tests/unit/test_migrations.py +++ b/cinder/tests/unit/test_migrations.py @@ -744,6 +744,11 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin): self.assertIsInstance(reservations.c.allocated_id.type, self.INTEGER_TYPE) + def _check_067(self, engine, data): + iscsi_targets = db_utils.get_table(engine, 'iscsi_targets') + fkey, = iscsi_targets.c.volume_id.foreign_keys + self.assertIsNotNone(fkey) + def test_walk_versions(self): self.walk_versions(False, False) -- 2.45.2