From b189f2719c690f2f8a8c47ca8aef490f2dba92db Mon Sep 17 00:00:00 2001 From: linb Date: Fri, 25 Sep 2015 14:45:19 +0800 Subject: [PATCH] Fix dhcp_router_id DB integration error dhcp_router_id column is useless in nsxv_vdr_dhcp_bindings and would lead to DB integration error. So the patch removes this column. Change-Id: I882c46e07f588d0106503075bc2de3116256cd73 --- .../alembic_migrations/versions/HEADS | 2 +- .../3c88bdea3054_nsxv_vdr_dhcp_binding.py | 34 +++++++++++++++++++ vmware_nsx/db/nsxv_db.py | 3 +- vmware_nsx/db/nsxv_models.py | 7 ++-- .../plugins/nsx_v/vshield/edge_utils.py | 2 +- 5 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 vmware_nsx/db/migration/alembic_migrations/versions/liberty/contract/3c88bdea3054_nsxv_vdr_dhcp_binding.py diff --git a/vmware_nsx/db/migration/alembic_migrations/versions/HEADS b/vmware_nsx/db/migration/alembic_migrations/versions/HEADS index 3ce48c43cd..65bc3df995 100644 --- a/vmware_nsx/db/migration/alembic_migrations/versions/HEADS +++ b/vmware_nsx/db/migration/alembic_migrations/versions/HEADS @@ -1,2 +1,2 @@ 279b70ac3ae8 -393bf843b96 +3c88bdea3054 diff --git a/vmware_nsx/db/migration/alembic_migrations/versions/liberty/contract/3c88bdea3054_nsxv_vdr_dhcp_binding.py b/vmware_nsx/db/migration/alembic_migrations/versions/liberty/contract/3c88bdea3054_nsxv_vdr_dhcp_binding.py new file mode 100644 index 0000000000..9e4e02a07b --- /dev/null +++ b/vmware_nsx/db/migration/alembic_migrations/versions/liberty/contract/3c88bdea3054_nsxv_vdr_dhcp_binding.py @@ -0,0 +1,34 @@ +# Copyright 2015 VMware, Inc. +# All Rights Reserved +# +# 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. + +"""nsxv_vdr_dhcp_binding.py + +Revision ID: 3c88bdea3054 +Revises: 393bf843b96 +Create Date: 2015-09-23 14:59:15.102609 + +""" + +# revision identifiers, used by Alembic. +revision = '3c88bdea3054' +down_revision = '393bf843b96' + +from alembic import op + + +def upgrade(): + op.drop_constraint('unique_nsxv_vdr_dhcp_bindings0dhcp_router_id', + 'nsxv_vdr_dhcp_bindings', 'unique') + op.drop_column('nsxv_vdr_dhcp_bindings', 'dhcp_router_id') diff --git a/vmware_nsx/db/nsxv_db.py b/vmware_nsx/db/nsxv_db.py index 554c0c45cf..65938effa0 100644 --- a/vmware_nsx/db/nsxv_db.py +++ b/vmware_nsx/db/nsxv_db.py @@ -507,10 +507,9 @@ def get_spoofguard_policy_id(session, network_id): network_id) -def add_vdr_dhcp_binding(session, vdr_router_id, dhcp_router_id, dhcp_edge_id): +def add_vdr_dhcp_binding(session, vdr_router_id, dhcp_edge_id): with session.begin(subtransactions=True): binding = nsxv_models.NsxvVdrDhcpBinding(vdr_router_id=vdr_router_id, - dhcp_router_id=dhcp_router_id, dhcp_edge_id=dhcp_edge_id) session.add(binding) return binding diff --git a/vmware_nsx/db/nsxv_models.py b/vmware_nsx/db/nsxv_models.py index 226dec8560..4278c2741b 100644 --- a/vmware_nsx/db/nsxv_models.py +++ b/vmware_nsx/db/nsxv_models.py @@ -247,13 +247,10 @@ class NsxvVdrDhcpBinding(model_base.BASEV2): __tablename__ = 'nsxv_vdr_dhcp_bindings' vdr_router_id = sa.Column(sa.String(36), primary_key=True) - dhcp_router_id = sa.Column(sa.String(36), nullable=False) dhcp_edge_id = sa.Column(sa.String(36), nullable=False) __table_args__ = ( - sa.UniqueConstraint( - dhcp_router_id, - name='unique_nsxv_vdr_dhcp_bindings0dhcp_router_id'), sa.UniqueConstraint( dhcp_edge_id, - name='unique_nsxv_vdr_dhcp_bindings0dhcp_edge_id')) + name='unique_nsxv_vdr_dhcp_bindings0dhcp_edge_id'), + model_base.BASEV2.__table_args__) diff --git a/vmware_nsx/plugins/nsx_v/vshield/edge_utils.py b/vmware_nsx/plugins/nsx_v/vshield/edge_utils.py index 3ffb27d213..175d46b755 100644 --- a/vmware_nsx/plugins/nsx_v/vshield/edge_utils.py +++ b/vmware_nsx/plugins/nsx_v/vshield/edge_utils.py @@ -987,7 +987,7 @@ class EdgeManager(object): [RP_FILTER_PROPERTY_OFF_TEMPLATE % ('all', '0')]) nsxv_db.add_vdr_dhcp_binding(context.session, vdr_router_id, - str(resource_id), dhcp_edge_id) + dhcp_edge_id) address_groups = self.plugin._create_network_dhcp_address_group( context, network_id)