]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Guarantee there is only one bandwidth limit rule per policy
authorIhar Hrachyshka <ihrachys@redhat.com>
Wed, 29 Jul 2015 18:44:54 +0000 (20:44 +0200)
committerIhar Hrachyshka <ihrachys@redhat.com>
Sun, 2 Aug 2015 22:47:47 +0000 (00:47 +0200)
Added corresponding db model constraint.

Change-Id: I5592d49909408df66e4d01cebbc45204c2be66c1
Partially-Implements: blueprint quantum-qos-api

neutron/db/migration/alembic_migrations/versions/liberty/expand/48153cb5f051_qos_db_changes.py
neutron/db/qos/models.py
neutron/services/qos/qos_plugin.py
neutron/tests/api/test_qos.py

index d20048b0e394a705a6ed7dd856a15cdfe11b40aa..940b4def58c956956fbd394d3078babc0de178ef 100755 (executable)
@@ -64,6 +64,6 @@ def upgrade():
         sa.Column('id', sa.String(length=36), primary_key=True),
         sa.Column('qos_policy_id', sa.String(length=36),
                   sa.ForeignKey('qos_policies.id', ondelete='CASCADE'),
-                  nullable=False),
+                  nullable=False, unique=True),
         sa.Column('max_kbps', sa.Integer()),
         sa.Column('max_burst_kbps', sa.Integer()))
index 89594618ff1949c025f6ebcb6d9dbf0fa8fcc94d..6185475edfceee0c99aefd4d9e45ba1a4fc22a53 100755 (executable)
@@ -70,7 +70,9 @@ class QosPortPolicyBinding(model_base.BASEV2):
 
 
 class QosRuleColumns(models_v2.HasId):
-    qos_policy_id = sa.Column(sa.String(36), nullable=False)
+    # 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']),
index 23135bf82be7a942c580d4137c5ecd6d9a1fbfd7..082fdae2b8ec7b2a893101e257894fdc77b34200 100644 (file)
@@ -85,10 +85,6 @@ class QoSPlugin(qos.QoSPluginBase):
     #           future code duplication when we have more rules.
     def create_policy_bandwidth_limit_rule(self, context, policy_id,
                                            bandwidth_limit_rule):
-        #TODO(QoS): avoid creation of severan bandwidth limit rules
-        #           in the future we need an inter-rule validation
-        #           mechanism to verify all created rules will
-        #           play well together.
         # validate that we have access to the policy
         policy = self._get_policy_obj(context, policy_id)
         rule = rule_object.QosBandwidthLimitRule(
index 845ef61cc8ffa761f8fce5c9a769b03ef180f47a..43ab12b8ca9434a1048e69fff1f4a658de64c6f9 100644 (file)
@@ -256,6 +256,21 @@ class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
         self.assertEqual(1, len(policy_rules))
         self.assertEqual(rule['id'], policy_rules[0]['id'])
 
+    @test.attr(type='smoke')
+    @test.idempotent_id('8a59b00b-ab01-4787-92f8-93a5cdf5e378')
+    def test_rule_create_fail_for_the_same_type(self):
+        policy = self.create_qos_policy(name='test-policy',
+                                        description='test policy',
+                                        shared=False)
+        self.create_qos_bandwidth_limit_rule(policy_id=policy['id'],
+                                             max_kbps=200,
+                                             max_burst_kbps=1337)
+
+        self.assertRaises(exceptions.ServerFault,
+                          self.create_qos_bandwidth_limit_rule,
+                          policy_id=policy['id'],
+                          max_kbps=201, max_burst_kbps=1338)
+
     @test.attr(type='smoke')
     @test.idempotent_id('149a6988-2568-47d2-931e-2dbc858943b3')
     def test_rule_update(self):
@@ -295,6 +310,3 @@ class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):
         self.assertRaises(exceptions.ServerFault,
                           self.admin_client.show_bandwidth_limit_rule,
                           policy['id'], rule['id'])
-
-    #TODO(QoS): create several bandwidth-limit rules (not sure it makes sense,
-    #           but to test more than one rule)