Register alembic_migrations at install time

This allows neutron-db-manage to find the alembic migrations
automatically if this project is installed.

The config file alembic.ini is not needed in this project since it's
tables are in neutron's DB and so it depends on neutron's config.

Remove the l2gw-db-manage script since we will use
neutron-db-manage.

Update the alembic env to know about all neutron core tables when
generating diffs for --autogenerate.

Partial-Bug: #1470625

Depends-On: I9a06de64ce35675af28adf819de6f22dc832390d

Change-Id: I581932d333e378d91d5b581760018ec274330681
stable/ocata
Henry Gessau 7 years ago
parent 9591b6d90a
commit cc0b186a9c
  1. 2
      devstack/plugin.sh
  2. 52
      networking_l2gw/db/migration/alembic.ini
  3. 16
      networking_l2gw/db/migration/alembic_migrations/env.py
  4. 33
      networking_l2gw/db/migration/alembic_migrations/script.py.mako
  5. 3
      setup.cfg
  6. 2
      tox.ini

@ -26,7 +26,7 @@ function start_l2gw_agent {
}
function run_l2gw_alembic_migration {
$NEUTRON_BIN_DIR/neutron-l2gw-db-manage --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE upgrade head
$NEUTRON_BIN_DIR/neutron-db-manage --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE upgrade head
}
function configure_l2gw_plugin {

@ -1,52 +0,0 @@
# 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

@ -16,14 +16,15 @@
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
from neutron.db.migration.alembic_migrations import external
from neutron.db.migration.models import head # noqa
from neutron.db import model_base
MYSQL_ENGINE = None
L2GW_VERSION_TABLE = 'l2gw_alembic_version'
config = context.config
@ -43,6 +44,13 @@ def set_mysql_engine():
model_base.BASEV2.__table_args__['mysql_engine'])
def include_object(object, name, type_, reflected, compare_to):
if type_ == 'table' and name in external.TABLES:
return False
else:
return True
def run_migrations_offline():
set_mysql_engine()
@ -51,6 +59,7 @@ def run_migrations_offline():
kwargs['url'] = neutron_config.database.connection
else:
kwargs['dialect_name'] = neutron_config.database.engine
kwargs['include_object'] = include_object
kwargs['version_table'] = L2GW_VERSION_TABLE
context.configure(**kwargs)
@ -72,6 +81,7 @@ def run_migrations_online():
context.configure(
connection=connection,
target_metadata=target_metadata,
include_object=include_object,
version_table=L2GW_VERSION_TABLE
)

@ -1,4 +1,4 @@
# Copyright 2015 OpenStack Foundation
# Copyright ${create_date.year} <PUT YOUR NAME/COMPANY HERE>
#
# 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
@ -13,17 +13,24 @@
# under the License.
#
from neutron.db.migration.cli import alembic_config
from neutron.db.migration.cli import CONF
import os
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision}
Create Date: ${create_date}
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)
"""
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
% if branch_labels:
branch_labels = ${repr(branch_labels)}
%endif
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
def upgrade():
${upgrades if upgrades else "pass"}

@ -33,7 +33,8 @@ 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
neutron.db.alembic_migrations =
networking-l2gw = networking_l2gw.db.migration:alembic_migrations
[build_sphinx]
source-dir = doc/source

@ -15,7 +15,7 @@ commands = python setup.py testr --slowest --testr-args='{posargs}'
[testenv:pep8]
commands =
flake8
# neutron-l2gw-db-manage check_migration
neutron-db-manage --subproject networking-l2gw check_migration
[testenv:venv]
commands = {posargs}

Loading…
Cancel
Save