Browse Source

qos: require min_kbps parameter for minimum bandwidth rule

It does not have much physical sense to have a rule without the limit set, just
direction. Require the parameter to avoid creating rules without the limit.

Change-Id: I13c54be22f35ac7eb5835d8424a919d0b61a8e95
Partial-Bug: #1560963
tags/9.0.0.0b3
Ihar Hrachyshka 3 years ago
parent
commit
85bbeedbe0
3 changed files with 39 additions and 23 deletions
  1. +1
    -1
      neutron/extensions/qos.py
  2. +30
    -15
      neutron/tests/tempest/api/test_qos.py
  3. +8
    -7
      neutron/tests/tempest/services/network/json/network_client.py

+ 1
- 1
neutron/extensions/qos.py View File

@@ -102,7 +102,7 @@ SUB_RESOURCE_ATTRIBUTE_MAP = {
'parameters': dict(QOS_RULE_COMMON_FIELDS,
**{'min_kbps': {
'allow_post': True, 'allow_put': True,
'is_visible': True, 'default': None,
'is_visible': True,
'validate': {'type:range': [0,
common_constants.DB_INTEGER_MAX_VALUE]}},
'direction': {

+ 30
- 15
neutron/tests/tempest/api/test_qos.py View File

@@ -900,8 +900,9 @@ class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
description='test policy',
shared=False)
rule = self.admin_client.create_minimum_bandwidth_rule(
policy_id=policy['id'], min_kbps=1138,
direction=self.DIRECTION_EGRESS)[self.RULE_NAME]
policy_id=policy['id'],
direction=self.DIRECTION_EGRESS,
min_kbps=1138)[self.RULE_NAME]

# Test 'show rule'
retrieved_rule = self.admin_client.show_minimum_bandwidth_rule(
@@ -925,19 +926,29 @@ class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
self.assertEqual(qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH,
policy_rules[0]['type'])

@test.idempotent_id('266d9b87-e51c-48bd-9aa7-8269573621be')
def test_rule_create_fail_for_missing_min_kbps(self):
policy = self.create_qos_policy(name='test-policy',
description='test policy',
shared=False)
self.assertRaises(exceptions.BadRequest,
self.admin_client.create_minimum_bandwidth_rule,
policy_id=policy['id'],
direction=self.DIRECTION_EGRESS)

@test.idempotent_id('aa59b00b-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.admin_client.create_minimum_bandwidth_rule(
policy_id=policy['id'], min_kbps=200,
direction=self.DIRECTION_EGRESS)
policy_id=policy['id'],
direction=self.DIRECTION_EGRESS, min_kbps=200)

self.assertRaises(exceptions.Conflict,
self.admin_client.create_minimum_bandwidth_rule,
policy_id=policy['id'],
min_kbps=201, direction=self.DIRECTION_EGRESS)
direction=self.DIRECTION_EGRESS, min_kbps=201)

@test.idempotent_id('d6fce764-e511-4fa6-9f86-f4b41cf142cf')
def test_rule_create_fail_for_direction_ingress(self):
@@ -947,7 +958,8 @@ class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
self.assertRaises(exceptions.BadRequest,
self.admin_client.create_minimum_bandwidth_rule,
policy_id=policy['id'],
min_kbps=201, direction=self.DIRECTION_INGRESS)
direction=self.DIRECTION_INGRESS,
min_kbps=201)

@test.idempotent_id('a49a6988-2568-47d2-931e-2dbc858943b3')
def test_rule_update(self):
@@ -955,8 +967,9 @@ class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
description='test policy',
shared=False)
rule = self.admin_client.create_minimum_bandwidth_rule(
policy_id=policy['id'], min_kbps=300,
direction=self.DIRECTION_EGRESS)[self.RULE_NAME]
policy_id=policy['id'],
direction=self.DIRECTION_EGRESS,
min_kbps=300)[self.RULE_NAME]

self.admin_client.update_minimum_bandwidth_rule(policy['id'],
rule['id'], min_kbps=350, direction=self.DIRECTION_EGRESS)
@@ -973,7 +986,7 @@ class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
description='test policy',
shared=False)
rule = self.admin_client.create_minimum_bandwidth_rule(
policy['id'], 200, self.DIRECTION_EGRESS)[self.RULE_NAME]
policy['id'], self.DIRECTION_EGRESS, min_kbps=200)[self.RULE_NAME]

retrieved_policy = self.admin_client.show_minimum_bandwidth_rule(
policy['id'], rule['id'])
@@ -991,14 +1004,14 @@ class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
self.assertRaises(
exceptions.NotFound,
self.admin_client.create_minimum_bandwidth_rule,
'policy', 200, self.DIRECTION_EGRESS)
'policy', self.DIRECTION_EGRESS, min_kbps=200)

@test.idempotent_id('b4a2e7ad-786f-4927-a85a-e545a93bd274')
def test_rule_create_forbidden_for_regular_tenants(self):
self.assertRaises(
exceptions.Forbidden,
self.client.create_minimum_bandwidth_rule,
'policy', 300, self.DIRECTION_EGRESS)
'policy', self.DIRECTION_EGRESS, min_kbps=300)

@test.idempotent_id('de0bd0c2-54d9-4e29-85f1-cfb36ac3ebe2')
def test_get_rules_by_policy(self):
@@ -1006,15 +1019,17 @@ class QosMinimumBandwidthRuleTestJSON(base.BaseAdminNetworkTest):
description='test policy1',
shared=False)
rule1 = self.admin_client.create_minimum_bandwidth_rule(
policy_id=policy1['id'], min_kbps=200,
direction=self.DIRECTION_EGRESS)[self.RULE_NAME]
policy_id=policy1['id'],
direction=self.DIRECTION_EGRESS,
min_kbps=200)[self.RULE_NAME]

policy2 = self.create_qos_policy(name='test-policy2',
description='test policy2',
shared=False)
rule2 = self.admin_client.create_minimum_bandwidth_rule(
policy_id=policy2['id'], min_kbps=5000,
direction=self.DIRECTION_EGRESS)[self.RULE_NAME]
policy_id=policy2['id'],
direction=self.DIRECTION_EGRESS,
min_kbps=5000)[self.RULE_NAME]

# Test 'list rules'
rules = self.admin_client.list_minimum_bandwidth_rules(policy1['id'])

+ 8
- 7
neutron/tests/tempest/services/network/json/network_client.py View File

@@ -653,15 +653,16 @@ class NetworkClientJSON(service_client.RestClient):
self.expected_success(204, resp.status)
return service_client.ResponseBody(resp, body)

def create_minimum_bandwidth_rule(self, policy_id, min_kbps, direction):
def create_minimum_bandwidth_rule(self, policy_id, direction,
min_kbps=None):
uri = '%s/qos/policies/%s/minimum_bandwidth_rules' % (
self.uri_prefix, policy_id)
post_data = self.serialize({
'minimum_bandwidth_rule': {
'min_kbps': min_kbps,
'direction': direction
}
})
data = {
'direction': direction,
}
if min_kbps is not None:
data['min_kbps'] = min_kbps
post_data = self.serialize({'minimum_bandwidth_rule': data})
resp, body = self.post(uri, post_data)
self.expected_success(201, resp.status)
body = jsonutils.loads(body)

Loading…
Cancel
Save