NSX: Register migrations at install time
This allows neutron-db-manage to find alembic migrations for vmware-nsx repo. Partial-Bug: #1470625 Change-Id: Icf2d68002ec79c75b4897f6b0bee5180570abe67
This commit is contained in:
parent
750d72c09f
commit
9054c32d83
1
tox.ini
1
tox.ini
@ -42,6 +42,7 @@ downloadcache = ~/cache/pip
|
||||
commands =
|
||||
sh ./tools/check_bash.sh
|
||||
flake8
|
||||
neutron-db-manage --subproject vmware-nsx check_migration
|
||||
whitelist_externals = sh
|
||||
|
||||
[testenv:i18n]
|
||||
|
0
vmware_nsx/neutron/db/__init__.py
Normal file
0
vmware_nsx/neutron/db/__init__.py
Normal file
0
vmware_nsx/neutron/db/migration/__init__.py
Normal file
0
vmware_nsx/neutron/db/migration/__init__.py
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright 2015 VMware, Inc
|
||||
#
|
||||
# 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.
|
||||
VERSION_TABLE = 'vmware_alembic_version'
|
124
vmware_nsx/neutron/db/migration/alembic_migrations/env.py
Normal file
124
vmware_nsx/neutron/db/migration/alembic_migrations/env.py
Normal file
@ -0,0 +1,124 @@
|
||||
# Copyright 2015 VMware, Inc
|
||||
#
|
||||
# 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.
|
||||
|
||||
from logging import config as logging_config
|
||||
|
||||
from alembic import context
|
||||
from oslo_config import cfg
|
||||
from oslo_db.sqlalchemy import session
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import event
|
||||
|
||||
from neutron.db.migration.alembic_migrations import external
|
||||
from neutron.db.migration.models import head # noqa
|
||||
from neutron.db import model_base
|
||||
|
||||
from vmware_nsx.neutron.db.migration import alembic_migrations
|
||||
|
||||
|
||||
MYSQL_ENGINE = None
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
neutron_config = config.neutron_config
|
||||
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
logging_config.fileConfig(config.config_file_name)
|
||||
|
||||
# set the target for 'autogenerate' support
|
||||
target_metadata = model_base.BASEV2.metadata
|
||||
|
||||
|
||||
def set_mysql_engine():
|
||||
try:
|
||||
mysql_engine = neutron_config.command.mysql_engine
|
||||
except cfg.NoSuchOptError:
|
||||
mysql_engine = None
|
||||
|
||||
global MYSQL_ENGINE
|
||||
MYSQL_ENGINE = (mysql_engine or
|
||||
model_base.BASEV2.__table_args__['mysql_engine'])
|
||||
|
||||
|
||||
def include_object(object, name, type_, reflected, compare_to):
|
||||
if (type_ == 'table' and
|
||||
name in set(external.TABLES) - set(external.REPO_VMWARE_TABLES)):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def run_migrations_offline():
|
||||
"""Run migrations in 'offline' mode.
|
||||
|
||||
This configures the context with either a URL
|
||||
or an Engine.
|
||||
|
||||
Calls to context.execute() here emit the given string to the
|
||||
script output.
|
||||
|
||||
"""
|
||||
set_mysql_engine()
|
||||
|
||||
kwargs = dict()
|
||||
if neutron_config.database.connection:
|
||||
kwargs['url'] = neutron_config.database.connection
|
||||
else:
|
||||
kwargs['dialect_name'] = neutron_config.database.engine
|
||||
kwargs['include_object'] = include_object
|
||||
kwargs['version_table'] = alembic_migrations.VERSION_TABLE
|
||||
context.configure(**kwargs)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
@event.listens_for(sa.Table, 'after_parent_attach')
|
||||
def set_storage_engine(target, parent):
|
||||
if MYSQL_ENGINE:
|
||||
target.kwargs['mysql_engine'] = MYSQL_ENGINE
|
||||
|
||||
|
||||
def run_migrations_online():
|
||||
"""Run migrations in 'online' mode.
|
||||
|
||||
In this scenario we need to create an Engine
|
||||
and associate a connection with the context.
|
||||
|
||||
"""
|
||||
set_mysql_engine()
|
||||
engine = session.create_engine(neutron_config.database.connection)
|
||||
|
||||
connection = engine.connect()
|
||||
context.configure(
|
||||
connection=connection,
|
||||
target_metadata=target_metadata,
|
||||
include_object=include_object,
|
||||
version_table=alembic_migrations.VERSION_TABLE
|
||||
)
|
||||
|
||||
try:
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
finally:
|
||||
connection.close()
|
||||
engine.dispose()
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
@ -1,3 +1,2 @@
|
||||
393bf843b96
|
||||
53a3254aa95e
|
||||
kilo
|
||||
|
@ -0,0 +1,31 @@
|
||||
# Copyright 2015 VMware, Inc
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
"""kilo
|
||||
|
||||
Revision ID: kilo
|
||||
Revises: None
|
||||
Create Date: 2015-04-16 00:00:00.000000
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'kilo'
|
||||
down_revision = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""A no-op migration for marking the Kilo release."""
|
||||
pass
|
@ -16,16 +16,18 @@
|
||||
"""Initial Liberty no-op contract script.
|
||||
|
||||
Revision ID: 393bf843b96
|
||||
Revises: None
|
||||
Revises: kilo
|
||||
Create Date: 2015-08-13 07:26:21.891165
|
||||
|
||||
"""
|
||||
|
||||
from neutron.db.migration import cli
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '393bf843b96'
|
||||
down_revision = None
|
||||
branch_labels = ('liberty_contract',)
|
||||
depends_on = ('kilo',)
|
||||
down_revision = 'kilo'
|
||||
branch_labels = (cli.CONTRACT_BRANCH,)
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
@ -16,16 +16,18 @@
|
||||
"""Initial Liberty no-op expand script.
|
||||
|
||||
Revision ID: 53a3254aa95e
|
||||
Revises: None
|
||||
Revises: kilo
|
||||
Create Date: 2015-08-13 06:34:29.842396
|
||||
|
||||
"""
|
||||
|
||||
from neutron.db.migration import cli
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '53a3254aa95e'
|
||||
down_revision = None
|
||||
branch_labels = ('liberty_expand',)
|
||||
depends_on = ('kilo',)
|
||||
down_revision = 'kilo'
|
||||
branch_labels = (cli.EXPAND_BRANCH,)
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
Loading…
Reference in New Issue
Block a user