]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
qos: Delete bw limit rule when policy is deleted
authorJakub Libosvar <libosvar@redhat.com>
Tue, 18 Aug 2015 13:42:37 +0000 (13:42 +0000)
committerJakub Libosvar <libosvar@redhat.com>
Thu, 20 Aug 2015 14:01:41 +0000 (14:01 +0000)
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
neutron/tests/api/test_qos.py

index 6185475edfceee0c99aefd4d9e45ba1a4fc22a53..3e1d027c68c567257f45694df85cb5488fc90edb 100755 (executable)
@@ -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)
index d281094b36d66a889b4fe209565f11e687919426..c3dd45dcacb60103cdc7f66f047a63169395e267 100644 (file)
@@ -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