Reduce qos rpc times on the ovs-agent side

When multiple ports are bound to qos-policy with the same id,
ovs-agent should check whether the cache has policy information
instead of directly reading rpc when processing the port.

Change-Id: I88f9f5af95439f1536799169390764c89109f467
Closes-Bug: #1783559
(cherry picked from commit 7a27e24447)
This commit is contained in:
Chengqian Liu 2018-07-25 21:29:02 +08:00 committed by Vlad Gusev
parent b87eb4814a
commit c49cc2cde2
2 changed files with 24 additions and 1 deletions

View File

@ -257,7 +257,8 @@ class QosAgentExtension(l2_agent_extension.L2AgentExtension):
if not self.policy_map.has_policy_changed(port, qos_policy_id):
return
qos_policy = self.resource_rpc.pull(
qos_policy = self.policy_map.get_policy(
qos_policy_id) or self.resource_rpc.pull(
context, resources.QOS_POLICY, qos_policy_id)
if qos_policy is None:
LOG.info("QoS policy %(qos_policy_id)s applied to port "

View File

@ -289,6 +289,28 @@ class QosExtensionRpcTestCase(QosExtensionBaseTestCase):
self.context, resources.QOS_POLICY,
port['qos_policy_id'])
def test_handle_diff_ports_same_policy_id(self):
port_obj1 = self._create_test_port_dict()
port_obj2 = self._create_test_port_dict()
self.qos_ext.handle_port(self.context, port_obj1)
self.pull_mock.assert_called_once_with(
self.context, resources.QOS_POLICY,
port_obj1['qos_policy_id'])
self.assertIsNotNone(
self.qos_ext.policy_map.get_port_policy(port_obj1))
self.assertIsNone(
self.qos_ext.policy_map.get_port_policy(port_obj2))
self.qos_ext.resource_rpc.pull.reset_mock()
self.qos_ext.handle_port(self.context, port_obj2)
self.assertFalse(self.pull_mock.called)
self.assertIsNotNone(
self.qos_ext.policy_map.get_port_policy(port_obj2))
self.assertEqual(
self.qos_ext.policy_map.get_port_policy(port_obj1),
self.qos_ext.policy_map.get_port_policy(port_obj2))
def test_delete_known_port(self):
port = self._create_test_port_dict()
self.qos_ext.handle_port(self.context, port)