Check DB scheme prior to migration to Ml2

When using migration tool from LB/OVS plugin to Ml2, there is no
guarantee current scheme is supported by migration tool. This patch
checks version stored in DB by alembic and compares whether version
is supported.

Closes-bug: #1307720

Change-Id: I4519a0e5a0f3027675958a68d1f9e0440b177229
This commit is contained in:
Jakub Libosvar 2014-05-28 18:39:47 +02:00
parent f7654c3b4c
commit 2139f28ae9

View File

@ -76,6 +76,29 @@ OPENVSWITCH = 'openvswitch'
ICEHOUSE = 'icehouse' ICEHOUSE = 'icehouse'
SUPPORTED_SCHEMA_VERSIONS = [ICEHOUSE]
def check_db_schema_version(engine, metadata):
"""Check that current version of the db schema is supported."""
version_table = sa.Table(
'alembic_version', metadata, autoload=True, autoload_with=engine)
versions = [v[0] for v in engine.execute(version_table.select())]
if not versions:
raise ValueError(_("Missing version in alembic_versions table"))
elif len(versions) > 1:
raise ValueError(_("Multiple versions in alembic_versions table: %s")
% versions)
current_version = versions[0]
if current_version not in SUPPORTED_SCHEMA_VERSIONS:
raise SystemError(_("Unsupported database schema %(current)s. "
"Please migrate your database to one of following "
"versions: %(supported)s")
% {'current': current_version,
'supported': ', '.join(SUPPORTED_SCHEMA_VERSIONS)}
)
# Duplicated from neutron.plugins.linuxbridge.common.constants to # Duplicated from neutron.plugins.linuxbridge.common.constants to
# avoid having any dependency on the linuxbridge plugin being # avoid having any dependency on the linuxbridge plugin being
# installed. # installed.
@ -104,9 +127,9 @@ class BaseMigrateToMl2_Icehouse(object):
def __call__(self, connection_url, save_tables=False, tunnel_type=None, def __call__(self, connection_url, save_tables=False, tunnel_type=None,
vxlan_udp_port=None): vxlan_udp_port=None):
engine = sa.create_engine(connection_url) engine = sa.create_engine(connection_url)
#TODO(marun) Check for the db version to ensure that it can be
# safely migrated from.
metadata = sa.MetaData() metadata = sa.MetaData()
check_db_schema_version(engine, metadata)
self.define_ml2_tables(metadata) self.define_ml2_tables(metadata)
# Autoload the ports table to ensure that foreign keys to it and # Autoload the ports table to ensure that foreign keys to it and