diff --git a/neutron_vpnaas/db/migration/alembic_migrations/__init__.py b/neutron_vpnaas/db/migration/alembic_migrations/__init__.py new file mode 100644 index 000000000..8e61f01d7 --- /dev/null +++ b/neutron_vpnaas/db/migration/alembic_migrations/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2015 Mirantis Inc. +# +# 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. + +VPNAAS_VERSION_TABLE = 'alembic_version_vpnaas' diff --git a/neutron_vpnaas/db/migration/alembic_migrations/env.py b/neutron_vpnaas/db/migration/alembic_migrations/env.py index cdc245d85..dfaa695dc 100644 --- a/neutron_vpnaas/db/migration/alembic_migrations/env.py +++ b/neutron_vpnaas/db/migration/alembic_migrations/env.py @@ -12,18 +12,19 @@ # 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 logging import config as logging_config from oslo_config import cfg from oslo_db.sqlalchemy import session import sqlalchemy as sa from sqlalchemy import event +from neutron.db import model_base + +from neutron_vpnaas.db.migration import alembic_migrations + MYSQL_ENGINE = None -VPNAAS_VERSION_TABLE = 'alembic_version_vpnaas' config = context.config neutron_config = config.neutron_config logging_config.fileConfig(config.config_file_name) @@ -49,7 +50,7 @@ def run_migrations_offline(): kwargs['url'] = neutron_config.database.connection else: kwargs['dialect_name'] = neutron_config.database.engine - kwargs['version_table'] = VPNAAS_VERSION_TABLE + kwargs['version_table'] = alembic_migrations.VPNAAS_VERSION_TABLE context.configure(**kwargs) with context.begin_transaction(): @@ -70,7 +71,7 @@ def run_migrations_online(): context.configure( connection=connection, target_metadata=target_metadata, - version_table=VPNAAS_VERSION_TABLE + version_table=alembic_migrations.VPNAAS_VERSION_TABLE ) try: with context.begin_transaction(): diff --git a/neutron_vpnaas/db/models/__init__.py b/neutron_vpnaas/db/models/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/neutron_vpnaas/db/models/head.py b/neutron_vpnaas/db/models/head.py new file mode 100644 index 000000000..b052ec38c --- /dev/null +++ b/neutron_vpnaas/db/models/head.py @@ -0,0 +1,31 @@ +# Copyright (c) 2014 OpenStack Foundation. +# All Rights Reserved. +# +# 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. + +""" +The module provides all database models at current HEAD. + +Its purpose is to create comparable metadata with current database schema. +Based on this comparison database can be healed with healing migration. + +""" + +from neutron.db.migration.models import head + +from neutron_vpnaas.db.vpn import vpn_db # noqa +from neutron_vpnaas.services.vpn.service_drivers import cisco_csr_db # noqa + + +def get_metadata(): + return head.model_base.BASEV2.metadata diff --git a/neutron_vpnaas/tests/functional/common/test_migrations_sync.py b/neutron_vpnaas/tests/functional/common/test_migrations_sync.py new file mode 100644 index 000000000..6466881bf --- /dev/null +++ b/neutron_vpnaas/tests/functional/common/test_migrations_sync.py @@ -0,0 +1,59 @@ +# Copyright 2015 Mirantis Inc +# +# 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 oslo_config import cfg + +from neutron.db.migration.alembic_migrations import external +from neutron.db.migration import cli as migration +from neutron.tests.common import base +from neutron.tests.functional.db import test_migrations + +from neutron_vpnaas.db.migration import alembic_migrations +from neutron_vpnaas.db.models import head + +EXTERNAL_TABLES = set(external.TABLES) - set(external.VPNAAS_TABLES) + + +class _TestModelsMigrationsVPNAAS(test_migrations._TestModelsMigrations): + + def db_sync(self, engine): + cfg.CONF.set_override('connection', engine.url, group='database') + for conf in migration.get_alembic_configs(): + self.alembic_config = conf + self.alembic_config.neutron_config = cfg.CONF + migration.do_alembic_command(conf, 'upgrade', 'heads') + + def get_metadata(self): + return head.get_metadata() + + def include_object(self, object_, name, type_, reflected, compare_to): + if type_ == 'table' and ( + name == alembic_migrations.VPNAAS_VERSION_TABLE or + name in EXTERNAL_TABLES): + return False + else: + return True + + def get_engine(self): + return self.engine + + +class TestModelsMigrationsMysql(_TestModelsMigrationsVPNAAS, + base.MySQLTestCase): + pass + + +class TestModelsMigrationsPsql(_TestModelsMigrationsVPNAAS, + base.PostgreSQLTestCase): + pass diff --git a/neutron_vpnaas/tests/functional/requirements.txt b/neutron_vpnaas/tests/functional/requirements.txt new file mode 100644 index 000000000..857e3dffd --- /dev/null +++ b/neutron_vpnaas/tests/functional/requirements.txt @@ -0,0 +1,10 @@ +# Additional requirements for functional tests + +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. + +psutil>=1.1.1,<2.0.0 +psycopg2 +PyMySQL>=0.6.2 # MIT License + diff --git a/tox.ini b/tox.ini index 3b3aecd74..d8d3253e7 100644 --- a/tox.ini +++ b/tox.ini @@ -15,10 +15,10 @@ commands = # there is also secret magic in pretty_tox.sh which lets you run in a fail only # mode. To do this define the TRACE_FAILONLY environmental variable. -# [testenv:functional] -# setenv = OS_TEST_PATH=./neutron-vpnaas/tests/functional -# commands = -# python setup.py testr --slowest --testr-args='{posargs}' +[testenv:functional] +deps = + {[testenv]deps} + -r{toxinidir}/neutron_vpnaas/tests/functional/requirements.txt [testenv:dsvm-functional] setenv = OS_TEST_PATH=./neutron_vpnaas/tests/functional/openswan @@ -26,6 +26,8 @@ setenv = OS_TEST_PATH=./neutron_vpnaas/tests/functional/openswan OS_ROOTWRAP_CMD=sudo {envdir}/bin/neutron-rootwrap {envdir}/etc/neutron/rootwrap.conf OS_ROOTWRAP_DAEMON_CMD=sudo {envdir}/bin/neutron-rootwrap-daemon {envdir}/etc/neutron/rootwrap.conf OS_FAIL_ON_MISSING_DEPS=1 +deps = + {[testenv:functional]deps} sitepackages=True whitelist_externals = sh @@ -41,6 +43,8 @@ setenv = OS_TEST_PATH=./neutron_vpnaas/tests/functional/strongswan OS_ROOTWRAP_CMD=sudo {envdir}/bin/neutron-rootwrap {envdir}/etc/neutron/rootwrap.conf OS_ROOTWRAP_DAEMON_CMD=sudo {envdir}/bin/neutron-rootwrap-daemon {envdir}/etc/neutron/rootwrap.conf OS_FAIL_ON_MISSING_DEPS=1 +deps = + {[testenv:functional]deps} sitepackages=True whitelist_externals = sh