Add model sync test

As neutron-lbaas doesn't have functional tests right now,
add this to unit tests following the convention.
(networking-cisco and networking-midonet)

Note: the Cisco copyright notice in test_migrations is intended.
It came from networking-cisco via networking-midonet.

Closes-Bug: #1549699
Change-Id: I30998407eae04d28a3a653430f8c90711b6c0235
This commit is contained in:
YAMAMOTO Takashi 2016-03-02 14:28:25 +09:00
parent a7d195ad70
commit cb4ec40a62
4 changed files with 86 additions and 0 deletions

View File

View File

@ -0,0 +1,22 @@
# Copyright 2016 Midokura SARL
#
# 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.migration.models import head
import neutron_lbaas.db.loadbalancer.loadbalancer_db # noqa
import neutron_lbaas.db.loadbalancer.models # noqa
def get_metadata():
return head.model_base.BASEV2.metadata

View File

@ -0,0 +1,61 @@
# Copyright (c) 2015 Cisco Systems, 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_lbaas.db.models import head
# EXTERNAL_TABLES should contain all names of tables that are not related to
# current repo.
EXTERNAL_TABLES = set(external.TABLES) - set(external.LBAAS_TABLES)
VERSION_TABLE = 'alembic_version_lbaas'
class _TestModelsMigrationsLBAAS(test_migrations._TestModelsMigrations):
# TODO(yamamoto): Move this test to functional, once neutron-lbaas
# gets a functional job.
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.startswith('alembic') or
name == VERSION_TABLE or
name in EXTERNAL_TABLES):
return False
if type_ == 'index' and reflected and name.startswith("idx_autoinc_"):
return False
return True
class TestModelsMigrationsMysql(_TestModelsMigrationsLBAAS,
base.MySQLTestCase):
pass
class TestModelsMigrationsPostgresql(_TestModelsMigrationsLBAAS,
base.PostgreSQLTestCase):
pass

View File

@ -14,8 +14,11 @@ oslo.concurrency>=3.5.0 # Apache-2.0
oslotest>=1.10.0 # Apache-2.0
tempest-lib>=0.14.0 # Apache-2.0
testrepository>=0.0.18 # Apache-2.0/BSD
testresources>=0.2.4 # Apache-2.0/BSD
testtools>=1.4.0 # MIT
testscenarios>=0.4 # Apache-2.0/BSD
WebOb>=1.2.3 # MIT
WebTest>=2.0 # MIT
reno>=0.1.1 # Apache2
# Needed to run DB commands in virtualenvs
PyMySQL>=0.6.2 # MIT License