Debian Codegraph @

neutron_vpnaas/tests/functional/common/test_migrations_sync.py

raw
1 # Copyright 2015 Mirantis 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_vpnaas.db.models import head
23
24 EXTERNAL_TABLES = set(external.TABLES) - set(external.VPNAAS_TABLES)
25 VERSION_TABLE = 'alembic_version_vpnaas'
26
27
28 class TestModelsMigrationsVPNAAS(test_migrations.TestModelsMigrations,
29 testlib_api.MySQLTestCaseMixin,
30 testlib_api.SqlTestCaseLight):
31
32 def db_sync(self, engine):
33 cfg.CONF.set_override(
34 'connection',
35 engine.url.render_as_string(hide_password=False),
36 group='database')
37 for conf in migration.get_alembic_configs():
38 self.alembic_config = conf
39 self.alembic_config.neutron_config = cfg.CONF
40 migration.do_alembic_command(conf, 'upgrade', 'heads')
41
42 def get_metadata(self):
43 return head.get_metadata()
44
45 def include_object(self, object_, name, type_, reflected, compare_to):
46 if type_ == 'table' and (name.startswith('alembic') or
47 name == VERSION_TABLE or
48 name in EXTERNAL_TABLES):
49 return False
50 if type_ == 'index' and reflected and name.startswith("idx_autoinc_"):
51 return False
52 return True