summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Pavlovic <boris@pavlovic.me>2013-05-13 14:46:50 +0400
committerBoris Pavlovic <boris@pavlovic.me>2013-05-24 14:57:45 +0400
commit6eec18975dec823eec513f451492f1befb2e60d0 (patch)
treee70dbd3b71eb7b3175280fc07c351d7bcbc4a4f6
parentbf4142bc7083120563638d3eaf0e2463ecbfc40b (diff)
downloadnova-6eec18975dec823eec513f451492f1befb2e60d0.tar.gz
nova-6eec18975dec823eec513f451492f1befb2e60d0.tar.xz
nova-6eec18975dec823eec513f451492f1befb2e60d0.zip
Sync shadow table for 175 and 176 migration
To be able to use db archiving our table and shadow table should have the same columns. fixes bug 1176443 Change-Id: I461a6d0e3661e2b60c266dffff38e3317784c113
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/180_fix_175_and_176_migration_sync_shadow_table.py61
-rw-r--r--nova/tests/test_migrations.py4
2 files changed, 65 insertions, 0 deletions
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/180_fix_175_and_176_migration_sync_shadow_table.py b/nova/db/sqlalchemy/migrate_repo/versions/180_fix_175_and_176_migration_sync_shadow_table.py
new file mode 100644
index 000000000..a88109307
--- /dev/null
+++ b/nova/db/sqlalchemy/migrate_repo/versions/180_fix_175_and_176_migration_sync_shadow_table.py
@@ -0,0 +1,61 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2013 Mirantis, Inc.
+# Copyright 2013 OpenStack Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# @author: Boris Pavlovic, Mirantis Inc
+
+from sqlalchemy import MetaData, Integer, String, Table, Column
+
+
+def upgrade(migrate_engine):
+ meta = MetaData()
+ meta.bind = migrate_engine
+
+ shadow_volume_usage_cache = Table('shadow_volume_usage_cache', meta,
+ autoload=True)
+ # fix for 175 migration
+ shadow_volume_usage_cache.drop_column('instance_id')
+
+ instance_id = Column('instance_uuid', String(36))
+ project_id = Column('project_id', String(36))
+ user_id = Column('user_id', String(36))
+
+ shadow_volume_usage_cache.create_column(instance_id)
+ shadow_volume_usage_cache.create_column(project_id)
+ shadow_volume_usage_cache.create_column(user_id)
+
+ # fix for 176 migration
+ availability_zone = Column('availability_zone', String(255))
+ shadow_volume_usage_cache.create_column(availability_zone)
+
+
+def downgrade(migrate_engine):
+ meta = MetaData()
+ meta.bind = migrate_engine
+
+ shadow_volume_usage_cache = Table('shadow_volume_usage_cache', meta,
+ autoload=True)
+
+ # fix for 175 migration
+ shadow_volume_usage_cache.drop_column('instance_uuid')
+ shadow_volume_usage_cache.drop_column('user_id')
+ shadow_volume_usage_cache.drop_column('project_id')
+
+ instance_id = Column('instance_id', Integer)
+ shadow_volume_usage_cache.create_column(instance_id)
+
+ # fix for 176 migration
+ shadow_volume_usage_cache.drop_column('availability_zone')
diff --git a/nova/tests/test_migrations.py b/nova/tests/test_migrations.py
index 688db500d..d78928790 100644
--- a/nova/tests/test_migrations.py
+++ b/nova/tests/test_migrations.py
@@ -1328,6 +1328,10 @@ class TestNovaMigrations(BaseMigrationTestCase, CommonTestsMixIn):
cell = cells.select(cells.c.id == 5).execute().first()
self.assertEqual(0, cell.deleted)
+ def _check_180(self, engine, data):
+ self.assertTrue(db_utils.check_shadow_table(engine,
+ "volume_usage_cache"))
+
class TestBaremetalMigrations(BaseMigrationTestCase, CommonTestsMixIn):
"""Test sqlalchemy-migrate migrations."""