Debian Codegraph @

networking_l2gw/tests/unit/db/test_migrations.py

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