Browse Source

Merge "[QoS] Get only min bw rules when extending port dict" into stable/train

changes/92/773592/1 15.3.2
Zuul 6 months ago
committed by Gerrit Code Review
parent
commit
112d82aad0
  1. 10
      neutron/services/qos/qos_plugin.py
  2. 11
      neutron/tests/unit/services/qos/test_qos_plugin.py

10
neutron/services/qos/qos_plugin.py

@ -43,6 +43,7 @@ from neutron.objects import network as network_object
from neutron.objects import ports as ports_object
from neutron.objects.qos import policy as policy_object
from neutron.objects.qos import qos_policy_validator as checker
from neutron.objects.qos import rule as rule_object
from neutron.objects.qos import rule_type as rule_type_object
from neutron.services.qos.drivers import manager
@ -100,8 +101,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.
@ -111,9 +110,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

@ -128,10 +128,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'])
@ -142,8 +140,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)
@ -184,7 +184,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'))
@ -202,7 +202,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