Browse Source

Merge "Added alembic DB migration framework"

changes/47/310747/4
Jenkins 6 years ago
committed by Gerrit Code Review
parent
commit
70da5ae1a1
  1. 0
      neutron_dynamic_routing/db/__init__.py
  2. 2
      neutron_dynamic_routing/db/migration/README
  3. 0
      neutron_dynamic_routing/db/migration/__init__.py
  4. 0
      neutron_dynamic_routing/db/migration/alembic_migrations/__init__.py
  5. 88
      neutron_dynamic_routing/db/migration/alembic_migrations/env.py
  6. 36
      neutron_dynamic_routing/db/migration/alembic_migrations/script.py.mako
  7. 1
      neutron_dynamic_routing/db/migration/alembic_migrations/versions/CONTRACT_HEAD
  8. 1
      neutron_dynamic_routing/db/migration/alembic_migrations/versions/EXPAND_HEAD
  9. 37
      neutron_dynamic_routing/db/migration/alembic_migrations/versions/newton/contract/61cc795e43e8_initial.py
  10. 37
      neutron_dynamic_routing/db/migration/alembic_migrations/versions/newton/expand/f399fa0f5f25_initial.py
  11. 30
      neutron_dynamic_routing/db/migration/alembic_migrations/versions/start_neutron_dynamic_routing.py
  12. 0
      neutron_dynamic_routing/db/migration/models/__init__.py
  13. 19
      neutron_dynamic_routing/db/migration/models/head.py
  14. 4
      setup.cfg
  15. 4
      tox.ini

0
neutron_dynamic_routing/db/__init__.py

2
neutron_dynamic_routing/db/migration/README

@ -0,0 +1,2 @@
For details refer to:
http://docs.openstack.org/developer/neutron-dynamic-routing/alembic_migration.html

0
neutron_dynamic_routing/db/migration/__init__.py

0
neutron_dynamic_routing/db/migration/alembic_migrations/__init__.py

88
neutron_dynamic_routing/db/migration/alembic_migrations/env.py

@ -0,0 +1,88 @@
# Copyright 2016 Huawei Technologies India Pvt Limited.
#
# 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
from neutron_dynamic_routing.db.migration.models import head # noqa
MYSQL_ENGINE = None
DR_VERSION_TABLE = 'alembic_version_dr'
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'] = DR_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=DR_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()

36
neutron_dynamic_routing/db/migration/alembic_migrations/script.py.mako

@ -0,0 +1,36 @@
# Copyright 2016 Huawei Technologies India Pvt Limited.
#
# 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}
Revises: ${down_revision}
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"}

1
neutron_dynamic_routing/db/migration/alembic_migrations/versions/CONTRACT_HEAD

@ -0,0 +1 @@
61cc795e43e8

1
neutron_dynamic_routing/db/migration/alembic_migrations/versions/EXPAND_HEAD

@ -0,0 +1 @@
f399fa0f5f25

37
neutron_dynamic_routing/db/migration/alembic_migrations/versions/newton/contract/61cc795e43e8_initial.py

@ -0,0 +1,37 @@
# Copyright 2016 Huawei Technologies India Pvt Limited.
#
# 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.
#
"""initial
Revision ID: 61cc795e43e8
Revises: start_neutron_dynamic_routing
Create Date: 2016-05-03 08:30:18.421995
"""
from neutron.db import migration
from neutron.db.migration import cli
# revision identifiers, used by Alembic.
revision = '61cc795e43e8'
down_revision = 'start_neutron_dynamic_routing'
branch_labels = (cli.CONTRACT_BRANCH,)
# milestone identifier, used by neutron-db-manage
neutron_milestone = [migration.NEWTON]
def upgrade():
pass

37
neutron_dynamic_routing/db/migration/alembic_migrations/versions/newton/expand/f399fa0f5f25_initial.py

@ -0,0 +1,37 @@
# Copyright 2016 Huawei Technologies India Pvt Limited.
#
# 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.
#
"""initial
Revision ID: f399fa0f5f25
Revises: None
Create Date: 2016-05-03 08:30:18.421995
"""
from neutron.db import migration
from neutron.db.migration import cli
# revision identifiers, used by Alembic.
revision = 'f399fa0f5f25'
down_revision = 'start_neutron_dynamic_routing'
branch_labels = (cli.EXPAND_BRANCH,)
# milestone identifier, used by neutron-db-manage
neutron_milestone = [migration.NEWTON]
def upgrade():
pass

30
neutron_dynamic_routing/db/migration/alembic_migrations/versions/start_neutron_dynamic_routing.py

@ -0,0 +1,30 @@
# Copyright 2016 Huawei Technologies India Pvt Limited.
#
# 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.
#
"""start neutron-dynamic-routing chain
Revision ID: start_neutron_dynamic_routing
Revises: None
Create Date: 2016-04-26 18:42:08.262632
"""
# revision identifiers, used by Alembic.
revision = 'start_neutron_dynamic_routing'
down_revision = None
def upgrade():
pass

0
neutron_dynamic_routing/db/migration/models/__init__.py

19
neutron_dynamic_routing/db/migration/models/head.py

@ -0,0 +1,19 @@
# Copyright 2016 Huawei Technologies India Pvt Limited.
#
# 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 import model_base
def get_metadata():
return model_base.BASEV2.metadata

4
setup.cfg

@ -24,6 +24,10 @@ packages =
setup-hooks =
pbr.hooks.setup_hook
[entry_points]
neutron.db.alembic_migrations =
neutron-dynamic-routing = neutron_dynamic_routing.db.migration:alembic_migrations
[build_sphinx]
all_files = 1
build-dir = doc/build

4
tox.ini

@ -24,7 +24,9 @@ install_command = {toxinidir}/tools/tox_install.sh unconstrained {opts} {package
commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html
[testenv:pep8]
commands = flake8
commands =
flake8
neutron-db-manage --subproject neutron-dynamic-routing --database-connection sqlite:// check_migration
[testenv:i18n]
commands = python ./tools/check_i18n.py ./neutron-dynamic-routing ./tools/i18n_cfg.py

Loading…
Cancel
Save