]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Minimize ovs l2 agent calls to get_vif_port_set()
authorMaru Newby <marun@redhat.com>
Thu, 22 Aug 2013 07:57:00 +0000 (07:57 +0000)
committerMaru Newby <marun@redhat.com>
Fri, 23 Aug 2013 21:30:15 +0000 (21:30 +0000)
The ovs l2 agent was previously calling get_vif_port_set() on the
integration bridge once per rpc_loop() iteration and then again in
the periodic _report_state() call that returns the current device
count to the neutron service.  Since get_vif_port_set() is an
expensive call (relying on shell commands) and since there
is minimal risk associated with reporting stats that are a few
seconds old, this patch caches the device count for reuse by
_report_state().

Partial-Bug: 1177973

Change-Id: Ice73384ed1ba1e97120028cd0a9bff94a62a41a4

neutron/plugins/openvswitch/agent/ovs_neutron_agent.py
neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py

index 842dda911829d0f4dbb777a5c5e20b9fa0ddaf16..4316cc6096d39df01bf5c3535931d490692e132e 100644 (file)
@@ -198,6 +198,9 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin):
             'start_flag': True}
         self.setup_rpc()
 
+        # Keep track of int_br's device count for use by _report_state()
+        self.int_br_device_count = 0
+
         # Security group agent supprot
         self.sg_agent = OVSSecurityGroupAgent(self.context,
                                               self.plugin_rpc,
@@ -211,9 +214,8 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin):
     def _report_state(self):
         try:
             # How many devices are likely used by a VM
-            ports = self.int_br.get_vif_port_set()
-            num_devices = len(ports)
-            self.agent_state.get('configurations')['devices'] = num_devices
+            self.agent_state.get('configurations')['devices'] = (
+                self.int_br_device_count)
             self.state_rpc.report_state(self.context,
                                         self.agent_state)
             self.agent_state.pop('start_flag', None)
@@ -655,6 +657,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin):
         ports = self.int_br.get_vif_port_set()
         if ports == registered_ports:
             return
+        self.int_br_device_count = len(ports)
         added = ports - registered_ports
         removed = registered_ports - ports
         return {'current': ports,
index d7c0deb988012fffeed5786296bb06f93890b974..447efad6cec805740ac40618a698043992801476 100644 (file)
@@ -222,18 +222,16 @@ class TestOvsNeutronAgent(base.BaseTestCase):
                 self.assertTrue(device_removed.called)
 
     def test_report_state(self):
-        with contextlib.nested(
-            mock.patch.object(self.agent.int_br, "get_vif_port_set"),
-            mock.patch.object(self.agent.state_rpc, "report_state")
-        ) as (get_vif_fn, report_st):
-            get_vif_fn.return_value = ["vif123", "vif234"]
+        with mock.patch.object(self.agent.state_rpc,
+                               "report_state") as report_st:
+            self.agent.int_br_device_count = 5
             self.agent._report_state()
-            self.assertTrue(get_vif_fn.called)
             report_st.assert_called_with(self.agent.context,
                                          self.agent.agent_state)
             self.assertNotIn("start_flag", self.agent.agent_state)
             self.assertEqual(
-                self.agent.agent_state["configurations"]["devices"], 2
+                self.agent.agent_state["configurations"]["devices"],
+                self.agent.int_br_device_count
             )
 
     def test_network_delete(self):