summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorBoris Pavlovic <boris@pavlovic.me>2013-05-22 16:57:47 +0400
committerBoris Pavlovic <boris@pavlovic.me>2013-05-24 14:57:27 +0400
commit7238438ef218d79a31acb07ea004fca8c2e78798 (patch)
tree6424423d6c16a18004601ad62bfc87f6a97b72f9 /nova/db
parent05be719ec76adf60a151b56d695c59fd832cb22b (diff)
Fix tests for sqlalchemy utils
This fix tests to be able to run it with postgresql and mysql. Some tests should be run only on sqlite Method create_shadow_tables raises different exception in different backends (when we try to create duplicate table): In postgresql it is ProgrammingError In sqlite and mysql it is OperationalError So create new Exception that will be raised in both cases. bp db-common-migration-and-utils Change-Id: I11be23106bc01bd3c72dad30edfb31a17177bb34
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/sqlalchemy/utils.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/nova/db/sqlalchemy/utils.py b/nova/db/sqlalchemy/utils.py
index f0eece661..84a24b94f 100644
--- a/nova/db/sqlalchemy/utils.py
+++ b/nova/db/sqlalchemy/utils.py
@@ -16,12 +16,18 @@
# under the License.
from migrate.changeset import UniqueConstraint
+from sqlalchemy import Column
from sqlalchemy.engine import reflection
+from sqlalchemy.exc import OperationalError
+from sqlalchemy.exc import ProgrammingError
from sqlalchemy.ext.compiler import compiles
from sqlalchemy import func
-from sqlalchemy import MetaData, Table, Column, Index
-from sqlalchemy.sql.expression import UpdateBase, literal_column
+from sqlalchemy import Index
+from sqlalchemy import MetaData
+from sqlalchemy.sql.expression import literal_column
+from sqlalchemy.sql.expression import UpdateBase
from sqlalchemy.sql import select
+from sqlalchemy import Table
from sqlalchemy.types import NullType
from nova.db.sqlalchemy import api as db
@@ -256,11 +262,15 @@ def create_shadow_table(migrate_engine, table_name=None, table=None,
else:
columns.append(column.copy())
- shadow_table = Table(db._SHADOW_TABLE_PREFIX + table.name, meta, *columns,
+ shadow_table_name = db._SHADOW_TABLE_PREFIX + table.name
+ shadow_table = Table(shadow_table_name, meta, *columns,
mysql_engine='InnoDB')
try:
shadow_table.create()
+ except (OperationalError, ProgrammingError):
+ LOG.info(repr(shadow_table))
+ LOG.exception(_('Exception while creating table.'))
+ raise exception.ShadowTableExists(name=shadow_table_name)
except Exception:
LOG.info(repr(shadow_table))
LOG.exception(_('Exception while creating table.'))
- raise