Merge "Bring models in sync with migrations, add test"
This commit is contained in:
13 changed files with 149 additions and 11 deletions
@@ -34,16 +34,21 @@ from networking_bgpvpn.neutron.services.common import utils
LOG = log.getLogger(__name__)
class HasTenantNotNullable(object):
"""Non-nullable Tenant mixin."""
tenant_id = sa.Column(sa.String(255), index=True, nullable=False)
class BGPVPNNetAssociation(model_base.BASEV2, models_v2.HasId,
models_v2.HasTenant):
HasTenantNotNullable):
"""Represents the association between a bgpvpn and a network."""
__tablename__ = 'bgpvpn_network_associations'
bgpvpn_id = sa.Column(sa.String(36),
sa.ForeignKey('bgpvpns.id'),
sa.ForeignKey('bgpvpns.id', ondelete='CASCADE'),
nullable=False)
network_id = sa.Column(sa.String(36),
sa.ForeignKey('networks.id'),
sa.ForeignKey('networks.id', ondelete='CASCADE'),
nullable=False)
sa.UniqueConstraint(bgpvpn_id, network_id)
network = orm.relationship("Network",
@@ -53,15 +58,15 @@ class BGPVPNNetAssociation(model_base.BASEV2, models_v2.HasId,
class BGPVPNRouterAssociation(model_base.BASEV2, models_v2.HasId,
models_v2.HasTenant):
HasTenantNotNullable):
"""Represents the association between a bgpvpn and a router."""
__tablename__ = 'bgpvpn_router_associations'
bgpvpn_id = sa.Column(sa.String(36),
sa.ForeignKey('bgpvpns.id'),
sa.ForeignKey('bgpvpns.id', ondelete='CASCADE'),
nullable=False)
router_id = sa.Column(sa.String(36),
sa.ForeignKey('routers.id'),
sa.ForeignKey('routers.id', ondelete='CASCADE'),
nullable=False)
sa.UniqueConstraint(bgpvpn_id, router_id)
router = orm.relationship("Router",
@@ -77,9 +82,9 @@ class BGPVPN(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant):
name="bgpvpn_type"),
nullable=False)
route_targets = sa.Column(sa.String(255), nullable=False)
import_targets = sa.Column(sa.String(255), nullable=False)
export_targets = sa.Column(sa.String(255), nullable=False)
route_distinguishers = sa.Column(sa.String(255), nullable=False)
import_targets = sa.Column(sa.String(255), nullable=True)
export_targets = sa.Column(sa.String(255), nullable=True)
route_distinguishers = sa.Column(sa.String(255), nullable=True)
network_associations = orm.relationship("BGPVPNNetAssociation",
backref="bgpvpn",
lazy='joined',
20
networking_bgpvpn/neutron/db/head.py
Normal file
20
networking_bgpvpn/neutron/db/head.py
Normal file
@@ -0,0 +1,20 @@
# 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
# pylint: disable=unused-import
import networking_bgpvpn.neutron.db.bgpvpn_db # noqa
def get_metadata():
return head.model_base.BASEV2.metadata
@@ -1,2 +1 @@
180baa4183e0
3600132c6147
@@ -0,0 +1 @@
0ab4049986b8
@@ -32,7 +32,7 @@ branch_labels = (cli.EXPAND_BRANCH,)
vpn_types = sa.Enum("l2", "l3", name="vpn_types")
def upgrade(active_plugins=None, options=None):
def upgrade():
op.create_table(
'bgpvpns',
sa.Column('name', sa.String(255), nullable=True),
@@ -0,0 +1,35 @@
# 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.
#
"""add indexes to tenant_id
Revision ID: 0ab4049986b8
Create Date: 2016年07月22日 14:19:04.888614
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = '0ab4049986b8'
down_revision = '3600132c6147'
def upgrade():
for table in [
'bgpvpns',
'bgpvpn_network_associations',
'bgpvpn_router_associations',
]:
op.create_index(op.f('ix_%s_tenant_id' % table),
table, ['tenant_id'], unique=False)
73
networking_bgpvpn/tests/unit/db/test_migrations.py
Normal file
73
networking_bgpvpn/tests/unit/db/test_migrations.py
Normal file
@@ -0,0 +1,73 @@
# 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.functional.db import test_migrations
from neutron.tests.unit import testlib_api
from networking_bgpvpn.neutron.db import head
# Tables from other repos that we depend on but do not manage.
BAGPIPE_TABLES = {
'ml2_route_target_allocations',
}
ODL_TABLES = {
'odl_alembic_version',
'opendaylightjournal',
'opendaylight_maintenance',
}
# EXTERNAL_TABLES should contain all names of tables that are not related to
# current repo.
EXTERNAL_TABLES = set(external.TABLES) | BAGPIPE_TABLES | ODL_TABLES
VERSION_TABLE = 'alembic_version_bgpvpn'
class _TestModelsMigrationsBGPVPN(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.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(testlib_api.MySQLTestCaseMixin,
_TestModelsMigrationsBGPVPN,
testlib_api.SqlTestCaseLight):
pass
class TestModelsMigrationsPostgresql(testlib_api.PostgreSQLTestCaseMixin,
_TestModelsMigrationsBGPVPN,
testlib_api.SqlTestCaseLight):
pass
@@ -10,6 +10,8 @@ discover
python-subunit>=0.0.18
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0
psycopg2>=2.5 # LGPL/ZPL
PyMySQL>=0.6.2 # MIT License
WebOb>=1.2.3
WebTest>=2.0
oslotest>=1.10.0 # Apache-2.0
3
tox.ini
3
tox.ini
@@ -29,6 +29,9 @@ commands =
pylint --rcfile=.pylintrc --output-format=colorized doc/source/samples
neutron-db-manage --subproject networking-bgpvpn --database-connection sqlite:// check_migration
[testenv:py27]
setenv = OS_FAIL_ON_MISSING_DEPS=1
[testenv:venv]
# TODO(tmorin): remove once infra supports constraints for this target
install_command = {toxinidir}/tools/tox_install.sh unconstrained {opts} {packages}
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.