summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-05-11 00:19:04 +0000
committerGerrit Code Review <review@openstack.org>2013-05-11 00:19:04 +0000
commit7cb353e8d264fe51845b690df42d5597fe063293 (patch)
tree9c0c075a56d37b0b1818112b4b6a7c8c2f0bbde3 /nova/tests
parent260d7efce73d2f175a8f647e61d3ff5b71e0f885 (diff)
parenta9b8fbc0e963bc81c4f4dc47dfcc9f31f3d8ef2e (diff)
Merge "Add sqlalchemy migration utils.check_shadow_table method"
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/test_migration_utils.py87
-rw-r--r--nova/tests/test_migrations.py7
2 files changed, 86 insertions, 8 deletions
diff --git a/nova/tests/test_migration_utils.py b/nova/tests/test_migration_utils.py
index 1096be0d3..d98b3952b 100644
--- a/nova/tests/test_migration_utils.py
+++ b/nova/tests/test_migration_utils.py
@@ -18,16 +18,24 @@
from migrate.changeset import UniqueConstraint
from sqlalchemy import Integer, DateTime, String
from sqlalchemy import MetaData, Table, Column
+from sqlalchemy.exc import NoSuchTableError
from sqlalchemy.exc import SAWarning
from sqlalchemy.sql import select
from sqlalchemy.types import UserDefinedType
+from nova.db.sqlalchemy import api as db
from nova.db.sqlalchemy import utils
from nova import exception
from nova.tests import test_migrations
import warnings
+class CustomType(UserDefinedType):
+ """Dummy column type for testing unsupported types."""
+ def get_col_spec(self):
+ return "CustomType"
+
+
class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
"""Class for testing utils that are used in db migrations."""
@@ -75,11 +83,6 @@ class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
def test_util_drop_unique_constraint_with_not_supported_sqlite_type(self):
- class CustomType(UserDefinedType):
- """Dummy column type for testing unsupported types."""
- def get_col_spec(self):
- return "CustomType"
-
table_name = "__test_tmp_table__"
uc_name = 'uniq_foo'
values = [
@@ -235,3 +238,77 @@ class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
len(values) - len(row_ids))
for value in soft_deleted_values:
self.assertTrue(value['id'] in deleted_rows_ids)
+
+ def test_check_shadow_table(self):
+ table_name = 'abc'
+ for key, engine in self.engines.items():
+ meta = MetaData()
+ meta.bind = engine
+
+ table = Table(table_name, meta,
+ Column('id', Integer, primary_key=True),
+ Column('a', Integer),
+ Column('c', String(256)))
+ table.create()
+
+ #check missing shadow table
+ self.assertRaises(NoSuchTableError,
+ utils.check_shadow_table, engine, table_name)
+
+ shadow_table = Table(db._SHADOW_TABLE_PREFIX + table_name, meta,
+ Column('id', Integer),
+ Column('a', Integer))
+ shadow_table.create()
+
+ # check missing column
+ self.assertRaises(exception.NovaException,
+ utils.check_shadow_table, engine, table_name)
+
+ # check when all is ok
+ c = Column('c', String(256))
+ shadow_table.create_column(c)
+ self.assertTrue(utils.check_shadow_table(engine, table_name))
+
+ # check extra column
+ d = Column('d', Integer)
+ shadow_table.create_column(d)
+ self.assertRaises(exception.NovaException,
+ utils.check_shadow_table, engine, table_name)
+
+ def test_check_shadow_table_different_types(self):
+ table_name = 'abc'
+ for key, engine in self.engines.items():
+ meta = MetaData()
+ meta.bind = engine
+
+ table = Table(table_name, meta,
+ Column('id', Integer, primary_key=True),
+ Column('a', Integer))
+ table.create()
+
+ shadow_table = Table(db._SHADOW_TABLE_PREFIX + table_name, meta,
+ Column('id', Integer, primary_key=True),
+ Column('a', String(256)))
+ shadow_table.create()
+ self.assertRaises(exception.NovaException,
+ utils.check_shadow_table, engine, table_name)
+
+ def test_check_shadow_table_with_unsupported_type(self):
+ table_name = 'abc'
+ for key, engine in self.engines.items():
+ meta = MetaData()
+ meta.bind = engine
+
+ table = Table(table_name, meta,
+ Column('id', Integer, primary_key=True),
+ Column('a', Integer),
+ Column('c', CustomType))
+ table.create()
+
+ shadow_table = Table(db._SHADOW_TABLE_PREFIX + table_name, meta,
+ Column('id', Integer, primary_key=True),
+ Column('a', Integer),
+ Column('c', CustomType))
+ shadow_table.create()
+
+ self.assertTrue(utils.check_shadow_table(engine, table_name))
diff --git a/nova/tests/test_migrations.py b/nova/tests/test_migrations.py
index d03e18160..b2319cc09 100644
--- a/nova/tests/test_migrations.py
+++ b/nova/tests/test_migrations.py
@@ -56,6 +56,7 @@ from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects import sqlite
import sqlalchemy.exc
+from nova.db.sqlalchemy import api as db
import nova.db.sqlalchemy.migrate_repo
from nova.openstack.common import lockutils
from nova.openstack.common import log as logging
@@ -855,13 +856,13 @@ class TestNovaMigrations(BaseMigrationTestCase, CommonTestsMixIn):
meta.reflect(engine)
table_names = set(meta.tables.keys())
for table_name in table_names:
- if table_name.startswith("shadow_"):
+ if table_name.startswith(db._SHADOW_TABLE_PREFIX):
shadow_name = table_name
- base_name = table_name.replace("shadow_", "")
+ base_name = table_name.replace(db._SHADOW_TABLE_PREFIX, "")
self.assertIn(base_name, table_names)
else:
base_name = table_name
- shadow_name = "shadow_" + table_name
+ shadow_name = db._SHADOW_TABLE_PREFIX + table_name
self.assertIn(shadow_name, table_names)
shadow_table = get_table(engine, shadow_name)
base_table = get_table(engine, base_name)