Browse Source

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

Only min bw rules are required hence no need to fetch
all rules of QoS policy.
Also no need to get qos policy from DB

Partial-Bug: #1905726
Change-Id: Iad29cb34825adaa8c766d01b192a6bbe9992148b
(cherry picked from commit a7e02cdb17)
changes/04/772404/2
Oleg Bondarev 8 months ago
committed by Oleg Bondarev
parent
commit
2d3c578444
  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