From 20df8ce45f14d91633d46e08d5b28cd0006124ef Mon Sep 17 00:00:00 2001 From: Jakub Libosvar Date: Tue, 18 Aug 2015 13:42:37 +0000 Subject: [PATCH] qos: Delete bw limit rule when policy is deleted We need to add ON DELETE CASCADE to qos_policy_id on bw limit rule table in order to delete policy successfully. There is a migration script that creates db scheme with correct foreign key constraint but we miss this in models. Currently, we have a functional test that guarantees parity between migration scripts and models but we don't have guaranteed foreign keys parity due to alembic bug [1]. https://bitbucket.org/zzzeek/alembic/issues/317 Change-Id: I06fa32dd11a5a52a80ae5a7952f8b32511c3f39d Closes-Bug: 1485926 --- neutron/db/qos/models.py | 18 ++++++------------ neutron/tests/api/test_qos.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/neutron/db/qos/models.py b/neutron/db/qos/models.py index 6185475ed..3e1d027c6 100755 --- a/neutron/db/qos/models.py +++ b/neutron/db/qos/models.py @@ -69,18 +69,12 @@ class QosPortPolicyBinding(model_base.BASEV2): cascade='delete', lazy='joined')) -class QosRuleColumns(models_v2.HasId): - # NOTE(ihrachyshka): we may need to rework it later when we introduce types - # that should not enforce uniqueness - qos_policy_id = sa.Column(sa.String(36), nullable=False, unique=True) - - __table_args__ = ( - sa.ForeignKeyConstraint(['qos_policy_id'], ['qos_policies.id']), - model_base.BASEV2.__table_args__ - ) - - -class QosBandwidthLimitRule(QosRuleColumns, model_base.BASEV2): +class QosBandwidthLimitRule(models_v2.HasId, model_base.BASEV2): __tablename__ = 'qos_bandwidth_limit_rules' + qos_policy_id = sa.Column(sa.String(36), + sa.ForeignKey('qos_policies.id', + ondelete='CASCADE'), + nullable=False, + unique=True) max_kbps = sa.Column(sa.Integer) max_burst_kbps = sa.Column(sa.Integer) diff --git a/neutron/tests/api/test_qos.py b/neutron/tests/api/test_qos.py index d281094b3..c3dd45dca 100644 --- a/neutron/tests/api/test_qos.py +++ b/neutron/tests/api/test_qos.py @@ -13,6 +13,7 @@ # under the License. from tempest_lib import exceptions +import testtools from neutron.services.qos import qos_consts from neutron.tests.api import base @@ -285,6 +286,20 @@ class QosTestJSON(base.BaseAdminNetworkTest): self._disassociate_port(port['id']) self.admin_client.delete_qos_policy(policy['id']) + @test.attr(type='smoke') + @test.idempotent_id('a2a5849b-dd06-4b18-9664-0b6828a1fc27') + def test_qos_policy_delete_with_rules(self): + policy = self.create_qos_policy(name='test-policy', + description='test policy', + shared=False) + self.admin_client.create_bandwidth_limit_rule( + policy['id'], 200, 1337)['bandwidth_limit_rule'] + + self.admin_client.delete_qos_policy(policy['id']) + + with testtools.ExpectedException(exceptions.NotFound): + self.admin_client.show_qos_policy(policy['id']) + class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest): @classmethod -- 2.45.2