NSX-V3: Fix QoS delete

In commit I1f863bf91f712d4b12db753b13cc6b842b6918a4 the qos driver stopped
using the message queue.
So the delete callback is now called in the plugin context, after the qos
policy is already deleted.
This means that we cannot access the backend profile id in the DB, since it
was already deleted too.

The fix is to remove the foreign key constraint from the mapping table, and
manually delete the entry.

Change-Id: I28e1c7c5ad0bb487d9c19ce76e2f7820f029678e
This commit is contained in:
Adit Sarfaty 2017-03-15 12:09:10 +02:00
parent 653b9bef83
commit 70fbe736b7
5 changed files with 44 additions and 3 deletions

View File

@ -374,6 +374,11 @@ def get_switch_profile_by_qos_policy(session, qos_policy_id):
raise nsx_exc.NsxQosPolicyMappingNotFound(policy=qos_policy_id)
def delete_qos_policy_profile_mapping(session, qos_policy_id):
return (session.query(nsx_models.QosPolicySwitchProfile).
filter_by(qos_policy_id=qos_policy_id).delete())
# NSXv3 Port Mirror Sessions DB methods.
def add_port_mirror_session_mapping(session, tf_id, pm_session_id):
with session.begin(subtransactions=True):

View File

@ -1 +1 @@
8c0a81a07691
84ceffa27115

View File

@ -0,0 +1,35 @@
# Copyright 2017 VMware, Inc.
#
# 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.
"""remove the foreign key constrain from nsxv3_qos_policy_mapping
Revision ID: 84ceffa27115
Revises: 8c0a81a07691
Create Date: 2017-03-15 11:47:09.450116
"""
# revision identifiers, used by Alembic.
revision = '84ceffa27115'
down_revision = '8c0a81a07691'
from alembic import op
from sqlalchemy.engine import reflection
def upgrade():
table_name = 'neutron_nsx_qos_policy_mappings'
inspector = reflection.Inspector.from_engine(op.get_bind())
fk_constraint = inspector.get_foreign_keys(table_name)[0]
op.drop_constraint(fk_constraint.get('name'), table_name,
type_='foreignkey')

View File

@ -355,8 +355,6 @@ class QosPolicySwitchProfile(model_base.BASEV2, models.TimestampMixin):
# Maps neutron qos policy identifiers to NSX-V3 switch profile identifiers
__tablename__ = 'neutron_nsx_qos_policy_mappings'
qos_policy_id = sa.Column(sa.String(36),
sa.ForeignKey('qos_policies.id',
ondelete='CASCADE'),
primary_key=True)
switch_profile_id = sa.Column(sa.String(36), nullable=False)

View File

@ -118,7 +118,10 @@ class QosNotificationsHandler(object):
def delete_policy(self, context, policy_id):
profile_id = nsx_db.get_switch_profile_by_qos_policy(
context.session, policy_id)
# delete the profile id from the backend and the DB
self._nsxlib_qos.delete(profile_id)
nsx_db.delete_qos_policy_profile_mapping(
context.session, policy_id)
def update_policy(self, context, policy_id, policy):
profile_id = nsx_db.get_switch_profile_by_qos_policy(