From d985550e8b0a6dd906e1927c48c4c35ed6d00d80 Mon Sep 17 00:00:00 2001 From: Thomas Morin Date: 2015年9月25日 14:06:01 +0200 Subject: [PATCH] Alembic migration update/cleanup This change updates and cleans up our alembic migration code: - we now use an alembic migration entry point, instead of shipping our own db management tool - use expand/contract alembic branches - downgrade is not supported anymore, drop it Change-Id: I8eb68075c720cd7252bd178c1bf08ef0947cd0d0 Closes-Bug: 1489876 --- devstack/plugin.sh | 5 +- .../neutron/db/migration/alembic.ini | 59 ------------------ .../migration/alembic_migrations/__init__.py | 0 .../alembic_migrations/script.py.mako | 23 +++++-- .../alembic_migrations/versions/HEAD | 1 - .../alembic_migrations/versions/HEADS | 2 + .../alembic_migrations/versions/__init__.py | 0 .../versions/liberty/__init__.py | 0 .../liberty/contract/180baa4183e0_initial.py} | 27 +++++---- .../versions/liberty/contract/__init__.py | 0 .../liberty/expand/17d9fd4fddee_initial.py | 60 +++++++++++++++++++ .../versions/liberty/expand/__init__.py | 0 .../versions/start_networking_bgpvpn.py | 44 +++----------- setup.cfg | 3 +- tox.ini | 4 +- 15 files changed, 112 insertions(+), 116 deletions(-) delete mode 100644 networking_bgpvpn/neutron/db/migration/alembic.ini create mode 100644 networking_bgpvpn/neutron/db/migration/alembic_migrations/__init__.py delete mode 100644 networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/HEAD create mode 100644 networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/HEADS create mode 100644 networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/__init__.py create mode 100644 networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/__init__.py rename networking_bgpvpn/neutron/db/migration/{cli.py => alembic_migrations/versions/liberty/contract/180baa4183e0_initial.py} (57%) create mode 100644 networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/contract/__init__.py create mode 100644 networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/expand/17d9fd4fddee_initial.py create mode 100644 networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/expand/__init__.py diff --git a/devstack/plugin.sh b/devstack/plugin.sh index f314a211..79e0188c 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -14,9 +14,8 @@ elif [[ "1ドル" == "stack" && "2ドル" == "install" ]]; then elif [[ "1ドル" == "stack" && "2ドル" == "pre-install" ]]; then _neutron_service_plugin_class_add $BGPVPN_PLUGIN_CLASS elif [[ "1ドル" == "stack" && "2ドル" == "post-config" ]]; then - if is_service_enabled q-svc; then - bgpvpn-db-manage --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE upgrade head - fi + #no-op + : fi if [[ "1ドル" == "unstack" ]]; then #no-op diff --git a/networking_bgpvpn/neutron/db/migration/alembic.ini b/networking_bgpvpn/neutron/db/migration/alembic.ini deleted file mode 100644 index c7875e74..00000000 --- a/networking_bgpvpn/neutron/db/migration/alembic.ini +++ /dev/null @@ -1,59 +0,0 @@ -# A generic, single database configuration. - -[alembic] -# path to migration scripts -script_location = alembic_migrations - -# template used to generate migration files -# file_template = %%(rev)s_%%(slug)s - -# max length of characters to apply to the -# "slug" field -#truncate_slug_length = 40 - -# set to 'true' to run the environment during -# the 'revision' command, regardless of autogenerate -# revision_environment = false - -# set to 'true' to allow .pyc and .pyo files without -# a source .py file to be detected as revisions in the -# versions/ directory -# sourceless = false - -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 diff --git a/networking_bgpvpn/neutron/db/migration/alembic_migrations/__init__.py b/networking_bgpvpn/neutron/db/migration/alembic_migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/networking_bgpvpn/neutron/db/migration/alembic_migrations/script.py.mako b/networking_bgpvpn/neutron/db/migration/alembic_migrations/script.py.mako index 95702017..99d229b9 100644 --- a/networking_bgpvpn/neutron/db/migration/alembic_migrations/script.py.mako +++ b/networking_bgpvpn/neutron/db/migration/alembic_migrations/script.py.mako @@ -1,3 +1,18 @@ +# Copyright ${create_date.year} +# +# 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. +# + """${message} Revision ID: ${up_revision} @@ -9,14 +24,14 @@ Create Date: ${create_date} # 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"} - - -def downgrade(): - ${downgrades if downgrades else "pass"} diff --git a/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/HEAD b/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/HEAD deleted file mode 100644 index 9a3007fb..00000000 --- a/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/HEAD +++ /dev/null @@ -1 +0,0 @@ -start_networking_bgpvpn diff --git a/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/HEADS b/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/HEADS new file mode 100644 index 00000000..9872aed0 --- /dev/null +++ b/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/HEADS @@ -0,0 +1,2 @@ +17d9fd4fddee +180baa4183e0 diff --git a/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/__init__.py b/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/__init__.py b/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/networking_bgpvpn/neutron/db/migration/cli.py b/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/contract/180baa4183e0_initial.py similarity index 57% rename from networking_bgpvpn/neutron/db/migration/cli.py rename to networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/contract/180baa4183e0_initial.py index 1799bc20..31e80b0a 100644 --- a/networking_bgpvpn/neutron/db/migration/cli.py +++ b/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/contract/180baa4183e0_initial.py @@ -1,3 +1,5 @@ +# Copyright 2015 Orange +# # 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 @@ -9,16 +11,21 @@ # 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 * # noqa +"""contract initial +Revision ID: 180baa4183e0 +Revises: start_networking_bgpvpn +Create Date: 2015年10月01日 17:35:11.000000 +""" + +from neutron.db.migration import cli + +# revision identifiers, used by Alembic. +revision = '180baa4183e0' +down_revision = 'start_networking_bgpvpn' +branch_labels = (cli.CONTRACT_BRANCH,) -def main(): - config = alembic_config.Config( - os.path.join(os.path.dirname(__file__), 'alembic.ini')) - config.set_main_option('script_location', - ('networking_bgpvpn.neutron.db.migration:' - 'alembic_migrations')) - config.neutron_config = CONF - CONF() - CONF.command.func(config, CONF.command.name) +def upgrade(): + pass diff --git a/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/contract/__init__.py b/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/contract/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/expand/17d9fd4fddee_initial.py b/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/expand/17d9fd4fddee_initial.py new file mode 100644 index 00000000..791d1996 --- /dev/null +++ b/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/expand/17d9fd4fddee_initial.py @@ -0,0 +1,60 @@ +# Copyright 2015 Orange +# +# 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 alembic import op +import sqlalchemy as sa + +from neutron.db.migration import cli + +"""expand initial +Revision ID: 17d9fd4fddee +Revises: start_networking_bgpvpn +Create Date: 2015年10月01日 17:35:11.000000 +""" + +# revision identifiers, used by Alembic. +revision = '17d9fd4fddee' +down_revision = 'start_networking_bgpvpn' +branch_labels = (cli.EXPAND_BRANCH,) + +vpn_types = sa.Enum("l2", "l3", name="vpn_types") + + +def upgrade(active_plugins=None, options=None): + op.create_table( + 'bgpvpns', + sa.Column('name', sa.String(255), nullable=True), + sa.Column('id', sa.String(length=36), nullable=False), + sa.Column('tenant_id', sa.String(length=255), nullable=True), + sa.Column('type', vpn_types, nullable=False), + sa.Column('route_targets', sa.String(255), nullable=False), + sa.Column('import_targets', sa.String(255), nullable=True), + sa.Column('export_targets', sa.String(255), nullable=True), + sa.Column('route_distinguishers', sa.String(255), nullable=True), + sa.Column('auto_aggregate', sa.Boolean(), nullable=False), + sa.PrimaryKeyConstraint('id'), + mysql_default_charset='utf8', + mysql_engine='InnoDB' + ) + op.create_table( + 'bgpvpn_net_associations', + sa.Column('bgpvpn_id', sa.String(36), nullable=False), + sa.Column('network_id', sa.String(36), nullable=True), + sa.ForeignKeyConstraint(['network_id'], ['networks.id'], + ondelete='CASCADE'), + sa.ForeignKeyConstraint(['bgpvpn_id'], ['bgpvpns.id'], + ondelete='CASCADE'), + sa.PrimaryKeyConstraint('network_id', 'bgpvpn_id'), + ) diff --git a/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/expand/__init__.py b/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/liberty/expand/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/start_networking_bgpvpn.py b/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/start_networking_bgpvpn.py index 4c26541e..43de0c4a 100644 --- a/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/start_networking_bgpvpn.py +++ b/networking_bgpvpn/neutron/db/migration/alembic_migrations/versions/start_networking_bgpvpn.py @@ -13,46 +13,16 @@ # under the License. # -from alembic import op -import sqlalchemy as sa - +"""start networking_bgpvpn chain +Revision ID: start_networking_bgpvpn +Revises: None +Create Date: 2015年10月01日 18:04:17.265514 +""" # revision identifiers, used by Alembic. revision = 'start_networking_bgpvpn' down_revision = None -vpn_types = sa.Enum("l2", "l3", name="vpn_types") - -def upgrade(active_plugins=None, options=None): - op.create_table( - 'bgpvpns', - sa.Column('name', sa.String(255), nullable=True), - sa.Column('id', sa.String(length=36), nullable=False), - sa.Column('tenant_id', sa.String(length=255), nullable=True), - sa.Column('type', vpn_types, nullable=False), - sa.Column('route_targets', sa.String(255), nullable=False), - sa.Column('import_targets', sa.String(255), nullable=True), - sa.Column('export_targets', sa.String(255), nullable=True), - sa.Column('route_distinguishers', sa.String(255), nullable=True), - sa.Column('auto_aggregate', sa.Boolean(), nullable=False), - sa.PrimaryKeyConstraint('id'), - mysql_default_charset='utf8', - mysql_engine='InnoDB' - ) - op.create_table( - 'bgpvpn_net_associations', - sa.Column('bgpvpn_id', sa.String(36), nullable=False), - sa.Column('network_id', sa.String(36), nullable=True), - sa.ForeignKeyConstraint(['network_id'], ['networks.id'], - ondelete='CASCADE'), - sa.ForeignKeyConstraint(['bgpvpn_id'], ['bgpvpns.id'], - ondelete='CASCADE'), - sa.PrimaryKeyConstraint('network_id', 'bgpvpn_id'), - ) - - -def downgrade(active_plugins=None, options=None): - op.drop_table('bgpvpns') - op.drop_table('bgpvpn_net_associations') - vpn_types.drop(op.get_bind(), checkfirst=False) +def upgrade(): + pass diff --git a/setup.cfg b/setup.cfg index c52e561b..85116986 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,10 +31,11 @@ data_files = [entry_points] console_scripts= - bgpvpn-db-manage = networking_bgpvpn.neutron.db.migration.cli:main neutron-bagpipe-openvswitch-agent = networking_bgpvpn.neutron.services.service_drivers.bagpipe.ovs_agent.ovs_bagpipe_neutron_agent:main neutronclient.extension= bgpvpn = networking_bgpvpn.neutronclient.neutron.v2_0.bgpvpn.bgpvpn +neutron.db.alembic_migrations= + networking-bgpvpn = networking_bgpvpn.neutron.db.migration:alembic_migrations [build_sphinx] source-dir = doc/source diff --git a/tox.ini b/tox.ini index 84c1f6f6..a5dba43a 100644 --- a/tox.ini +++ b/tox.ini @@ -13,7 +13,9 @@ deps = -r{toxinidir}/requirements.txt commands = python setup.py testr --slowest --testr-args='{posargs}' [testenv:pep8] -commands = flake8 +commands = + flake8 + neutron-db-manage --subproject networking-bgpvpn --database-connection sqlite:// check_migration [testenv:venv] commands = {posargs}

AltStyle によって変換されたページ (->オリジナル) /