| 1 |
# Copyright 2016 VMware, Inc |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 |
# not use this file except in compliance with the License. You may obtain |
| 5 |
# a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 |
# License for the specific language governing permissions and limitations |
| 13 |
# under the License. |
| 14 |
|
| 15 |
from oslo_config import cfg |
| 16 |
|
| 17 |
from neutron.db.migration.alembic_migrations import external |
| 18 |
from neutron.db.migration import cli as migration |
| 19 |
from neutron.tests.functional.db import test_migrations |
| 20 |
from neutron.tests.unit import testlib_api |
| 21 |
|
| 22 |
from neutron_taas.db import head |
| 23 |
|
| 24 |
# EXTERNAL_TABLES should contain all names of tables that are not related to |
| 25 |
# current repo. |
| 26 |
EXTERNAL_TABLES = set(external.TABLES) |
| 27 |
VERSION_TABLE = 'taas_alembic_version' |
| 28 |
|
| 29 |
|
| 30 |
class TestModelsMigrationsTAAS(test_migrations.TestModelsMigrations, |
| 31 |
testlib_api.MySQLTestCaseMixin, |
| 32 |
testlib_api.SqlTestCaseLight): |
| 33 |
|
| 34 |
def db_sync(self, engine): |
| 35 |
cfg.CONF.set_override( |
| 36 |
'connection', |
| 37 |
engine.url.render_as_string(hide_password=False), |
| 38 |
group='database') |
| 39 |
for conf in migration.get_alembic_configs(): |
| 40 |
self.alembic_config = conf |
| 41 |
self.alembic_config.neutron_config = cfg.CONF |
| 42 |
migration.do_alembic_command(conf, 'upgrade', 'heads') |
| 43 |
|
| 44 |
def get_metadata(self): |
| 45 |
return head.get_metadata() |
| 46 |
|
| 47 |
def include_object(self, object_, name, type_, reflected, compare_to): |
| 48 |
if type_ == 'table' and (name.startswith('alembic') or |
| 49 |
name == VERSION_TABLE or |
| 50 |
name in EXTERNAL_TABLES): |
| 51 |
return False |
| 52 |
if type_ == 'index' and reflected and name.startswith("idx_autoinc_"): |
| 53 |
return False |
| 54 |
return True |