summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJoe Gordon <jogo@cloudscaling.com>2012-09-19 20:54:33 +0000
committerJoe Gordon <jogo@cloudscaling.com>2012-09-19 21:51:36 +0000
commita5dbdb53da470916248c8ef8715ef6e06dfa1d0f (patch)
tree3c2f635a0a9bb86e98f2d576c916cba59e908acd /nova
parent2934799fda4ca62337833a3ed736da5dce1210ae (diff)
downloadnova-a5dbdb53da470916248c8ef8715ef6e06dfa1d0f.tar.gz
nova-a5dbdb53da470916248c8ef8715ef6e06dfa1d0f.tar.xz
nova-a5dbdb53da470916248c8ef8715ef6e06dfa1d0f.zip
Fix aggregate_hosts.host migration for sqlite
* Make sure data is not lost during migration * Changes migration 111_general_aggregates * Adds test for change Fix bug 1053131 Change-Id: Idbf0cbd5fdb7758ea1794019807d83d159270cba
Diffstat (limited to 'nova')
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/111_general_aggregates.py3
-rw-r--r--nova/tests/test_migrations.py24
2 files changed, 25 insertions, 2 deletions
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/111_general_aggregates.py b/nova/db/sqlalchemy/migrate_repo/versions/111_general_aggregates.py
index 0c97112ce..df4a83843 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/111_general_aggregates.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/111_general_aggregates.py
@@ -43,8 +43,7 @@ def upgrade(migrate_engine):
aggregate_hosts = Table('aggregate_hosts', meta, autoload=True)
if dialect.startswith('sqlite'):
- aggregate_hosts.drop_column('host')
- aggregate_hosts.create_column(Column('host', String(255)))
+ aggregate_hosts.c.host.alter(unique=False)
elif dialect.startswith('postgres'):
ucon = UniqueConstraint('host',
name='aggregate_hosts_host_key',
diff --git a/nova/tests/test_migrations.py b/nova/tests/test_migrations.py
index 73b50c280..1e8714b94 100644
--- a/nova/tests/test_migrations.py
+++ b/nova/tests/test_migrations.py
@@ -456,3 +456,27 @@ class TestMigrations(test.TestCase):
sm_vols = sqlalchemy.select([sm_volume.c.id]).execute().fetchall()
self.assertEqual(set([sm_vol.id for sm_vol in sm_vols]),
set([vol1_id]))
+
+ def test_migration_111(self):
+ for key, engine in self.engines.items():
+ migration_api.version_control(engine, TestMigrations.REPOSITORY,
+ migration.INIT_VERSION)
+ migration_api.upgrade(engine, TestMigrations.REPOSITORY, 110)
+
+ metadata = sqlalchemy.schema.MetaData()
+ metadata.bind = engine
+ aggregate_hosts = sqlalchemy.Table('aggregate_hosts', metadata,
+ autoload=True)
+ host = 'host'
+ aggregate_hosts.insert().values(id=1,
+ aggregate_id=1, host=host).execute()
+
+ migration_api.upgrade(engine, TestMigrations.REPOSITORY, 111)
+ agg = sqlalchemy.select([aggregate_hosts.c.host]).execute().first()
+ self.assertEqual(host, agg.host)
+ aggregate_hosts.insert().values(id=2,
+ aggregate_id=2, host=host).execute()
+
+ migration_api.downgrade(engine, TestMigrations.REPOSITORY, 111)
+ agg = sqlalchemy.select([aggregate_hosts.c.host]).execute().first()
+ self.assertEqual(host, agg.host)