Browse Source

Merge "[QoS] Get only min bw rules when extending port dict"

changes/54/764454/14
Zuul 8 months ago
committed by Gerrit Code Review
parent
commit
fd5047ecf2
  1. 9
      neutron/services/qos/qos_plugin.py
  2. 11
      neutron/tests/unit/services/qos/test_qos_plugin.py

9
neutron/services/qos/qos_plugin.py

@ -118,8 +118,6 @@ class QoSPlugin(qos.QoSPluginBase):
port_res['resource_request'] = None
if not qos_id:
return port_res
qos_policy = policy_object.QosPolicy.get_object(
context.get_admin_context(), id=qos_id)
resources = {}
# NOTE(ralonsoh): we should move this translation dict to n-lib.
@ -129,9 +127,10 @@ class QoSPlugin(qos.QoSPluginBase):
nl_constants.EGRESS_DIRECTION:
pl_constants.CLASS_NET_BW_EGRESS_KBPS
}
for rule in qos_policy.rules:
if rule.rule_type == qos_consts.RULE_TYPE_MINIMUM_BANDWIDTH:
resources[rule_direction_class[rule.direction]] = rule.min_kbps
min_bw_rules = rule_object.QosMinimumBandwidthRule.get_objects(
context.get_admin_context(), qos_policy_id=qos_id)
for rule in min_bw_rules:
resources[rule_direction_class[rule.direction]] = rule.min_kbps
if not resources:
return port_res

11
neutron/tests/unit/services/qos/test_qos_plugin.py

@ -130,10 +130,8 @@ class TestQosPlugin(base.BaseQosTestCase):
if has_qos_policy:
self.port_data['port']['qos_policy_id'] = self.policy.id
self.policy.rules = bw_rules
elif has_net_qos_policy:
self.port_data['port']['qos_network_policy_id'] = self.policy.id
self.policy.rules = bw_rules
self.port = ports_object.Port(
self.ctxt, **self.port_data['port'])
@ -144,8 +142,10 @@ class TestQosPlugin(base.BaseQosTestCase):
with mock.patch('neutron.objects.network.NetworkSegment.get_objects',
return_value=[segment_mock]), \
mock.patch('neutron.objects.qos.policy.QosPolicy.get_object',
return_value=self.policy):
mock.patch(
'neutron.objects.qos.rule.QosMinimumBandwidthRule.'
'get_objects',
return_value=bw_rules):
return qos_plugin.QoSPlugin._extend_port_resource_request(
port_res, self.port)
@ -186,7 +186,7 @@ class TestQosPlugin(base.BaseQosTestCase):
)
def test__extend_port_resource_request_non_min_bw_rule(self):
port = self._create_and_extend_port([self.rule])
port = self._create_and_extend_port([])
self.assertIsNone(port.get('resource_request'))
@ -204,7 +204,6 @@ class TestQosPlugin(base.BaseQosTestCase):
def test__extend_port_resource_request_inherited_policy(self):
self.min_rule.direction = lib_constants.EGRESS_DIRECTION
self.policy.rules = [self.min_rule]
self.min_rule.qos_policy_id = self.policy.id
port = self._create_and_extend_port([self.min_rule],

Loading…
Cancel
Save