diff --git a/neutron_dynamic_routing/db/__init__.py b/neutron_dynamic_routing/db/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/neutron_dynamic_routing/db/migration/README b/neutron_dynamic_routing/db/migration/README new file mode 100644 index 00000000..93d94de4 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/neutron_dynamic_routing/db/migration/__init__.py b/neutron_dynamic_routing/db/migration/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/neutron_dynamic_routing/db/migration/alembic_migrations/__init__.py b/neutron_dynamic_routing/db/migration/alembic_migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/neutron_dynamic_routing/db/migration/alembic_migrations/env.py b/neutron_dynamic_routing/db/migration/alembic_migrations/env.py new file mode 100644 index 00000000..43b565d8 --- /dev/null +++ b/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() diff --git a/neutron_dynamic_routing/db/migration/alembic_migrations/script.py.mako b/neutron_dynamic_routing/db/migration/alembic_migrations/script.py.mako new file mode 100644 index 00000000..0e7830ae --- /dev/null +++ b/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"} diff --git a/neutron_dynamic_routing/db/migration/alembic_migrations/versions/CONTRACT_HEAD b/neutron_dynamic_routing/db/migration/alembic_migrations/versions/CONTRACT_HEAD new file mode 100644 index 00000000..2d217581 --- /dev/null +++ b/neutron_dynamic_routing/db/migration/alembic_migrations/versions/CONTRACT_HEAD @@ -0,0 +1 @@ +61cc795e43e8 diff --git a/neutron_dynamic_routing/db/migration/alembic_migrations/versions/EXPAND_HEAD b/neutron_dynamic_routing/db/migration/alembic_migrations/versions/EXPAND_HEAD new file mode 100644 index 00000000..6177b331 --- /dev/null +++ b/neutron_dynamic_routing/db/migration/alembic_migrations/versions/EXPAND_HEAD @@ -0,0 +1 @@ +f399fa0f5f25 diff --git a/neutron_dynamic_routing/db/migration/alembic_migrations/versions/newton/contract/61cc795e43e8_initial.py b/neutron_dynamic_routing/db/migration/alembic_migrations/versions/newton/contract/61cc795e43e8_initial.py new file mode 100644 index 00000000..a98181eb --- /dev/null +++ b/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 diff --git a/neutron_dynamic_routing/db/migration/alembic_migrations/versions/newton/expand/f399fa0f5f25_initial.py b/neutron_dynamic_routing/db/migration/alembic_migrations/versions/newton/expand/f399fa0f5f25_initial.py new file mode 100644 index 00000000..32940962 --- /dev/null +++ b/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 diff --git a/neutron_dynamic_routing/db/migration/alembic_migrations/versions/start_neutron_dynamic_routing.py b/neutron_dynamic_routing/db/migration/alembic_migrations/versions/start_neutron_dynamic_routing.py new file mode 100644 index 00000000..d3cabbbe --- /dev/null +++ b/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 diff --git a/neutron_dynamic_routing/db/migration/models/__init__.py b/neutron_dynamic_routing/db/migration/models/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/neutron_dynamic_routing/db/migration/models/head.py b/neutron_dynamic_routing/db/migration/models/head.py new file mode 100644 index 00000000..25ad4968 --- /dev/null +++ b/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 diff --git a/setup.cfg b/setup.cfg index b734bba1..37dbef8e 100644 --- a/setup.cfg +++ b/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 diff --git a/tox.ini b/tox.ini index cdb0b915..f1bb025f 100644 --- a/tox.ini +++ b/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