alembic migration scripts for networking_l2gw

This patchset enables to provide the migration script
'neutron-l2gw-db-manage' for create database tables for
networking_l2gw project.

Change-Id: I89eb370996c5ae416484df1135e0b7b3517a8b1f
stable/ocata
Selvakumar S 8 years ago
parent 73e7bca07b
commit 5273c82a28
  1. 7
      devstack/plugin.sh
  2. 52
      networking_l2gw/db/migration/alembic.ini
  3. 1
      networking_l2gw/db/migration/alembic_migrations/README
  4. 89
      networking_l2gw/db/migration/alembic_migrations/env.py
  5. 29
      networking_l2gw/db/migration/cli.py
  6. 1
      setup.cfg

@ -25,6 +25,10 @@ function start_l2gw_agent {
run_process l2gw-agent "python $L2GW_AGENT_BINARY --config-file $NEUTRON_CONF --config-file=$L2GW_CONF_FILE"
}
function run_l2gw_alembic_migration {
$NEUTRON_BIN_DIR/neutron-l2gw-db-manage --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE upgrade head
}
function configure_l2gw_plugin {
_neutron_service_plugin_class_add $L2GW_PLUGIN
}
@ -38,8 +42,7 @@ if is_service_enabled l2gw-plugin; then
install_l2gw
configure_l2gw_plugin
elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
#no-op
:
run_l2gw_alembic_migration
elif [[ "$1" == "stack" && "$2" == "post-extra" ]]; then
# no-op
:

@ -0,0 +1,52 @@
# A generic, single database configuration.
[alembic]
# path to migration scripts
script_location = %(here)s/alembic
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
# default to an empty string because the Neutron migration cli will
# extract the correct value and set it programatically before alemic is fully
# invoked.
sqlalchemy.url =
# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = console
qualname =
[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
[logger_alembic]
level = INFO
handlers =
qualname = alembic
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S

@ -0,0 +1 @@
This directory contains the migration scripts for the networking_l2gw project.

@ -0,0 +1,89 @@
# Copyright 2015 OpenStack Foundation
#
# 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 neutron.db import model_base
from oslo.config import cfg
from oslo.db.sqlalchemy import session
import sqlalchemy as sa
from sqlalchemy import event
MYSQL_ENGINE = None
L2GW_VERSION_TABLE = 'l2gw_alembic_version'
config = context.config
neutron_config = config.neutron_config
logging_config.fileConfig(config.config_file_name)
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 run_migrations_offline():
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['version_table'] = L2GW_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():
set_mysql_engine()
engine = session.create_engine(neutron_config.database.connection)
connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata,
version_table=L2GW_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()

@ -0,0 +1,29 @@
# Copyright 2015 OpenStack Foundation
#
# 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 neutron.db.migration.cli import alembic_config
from neutron.db.migration.cli import CONF
import os
def main():
config = alembic_config.Config(
os.path.join(os.path.dirname(__file__), 'alembic.ini'))
config.set_main_option(
'script_location',
'networking_l2gw.db.migration:alembic_migrations')
config.neutron_config = CONF
CONF()
CONF.command.func(config, CONF.command.name)

@ -32,6 +32,7 @@ data_files =
console_scripts =
neutron-l2gateway-agent = networking_l2gw.cmd.eventlet.agent:main
neutron-l2gw = networking_l2gw.l2gatewayclient.shell:main
neutron-l2gw-db-manage = networking_l2gw.db.migration.cli:main
[build_sphinx]
source-dir = doc/source

Loading…
Cancel
Save