]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
OVS agent factor our port stats processing
authorrossella <rsblendido@suse.com>
Sun, 5 Jul 2015 21:58:25 +0000 (23:58 +0200)
committerrossella <rsblendido@suse.com>
Fri, 17 Jul 2015 10:31:00 +0000 (10:31 +0000)
Move the port stats processing from the rpc loop to a new method
get_port_stats

Change-Id: I4a927f5c11328d854fbb5f76d560bbd9425651ea

neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py

index b9d6ae3a9ee7699ab0d0a7e4f48081a618f9aae6..d39959da5f625138df0d526179f381833b13a168 100644 (file)
@@ -1469,6 +1469,18 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
                        'elapsed': elapsed})
         self.iter_num = self.iter_num + 1
 
+    def get_port_stats(self, port_info, ancillary_port_info):
+        port_stats = {
+            'regular': {
+                'added': len(port_info.get('added', [])),
+                'updated': len(port_info.get('updated', [])),
+                'removed': len(port_info.get('removed', []))}}
+        if self.ancillary_brs:
+            port_stats['ancillary'] = {
+                'added': len(ancillary_port_info.get('added', [])),
+                'removed': len(ancillary_port_info.get('removed', []))}
+        return port_stats
+
     def rpc_loop(self, polling_manager=None):
         if not polling_manager:
             polling_manager = polling.get_polling_manager(
@@ -1482,11 +1494,6 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
         ovs_restarted = False
         while self._check_and_handle_signal():
             start = time.time()
-            port_stats = {'regular': {'added': 0,
-                                      'updated': 0,
-                                      'removed': 0},
-                          'ancillary': {'added': 0,
-                                        'removed': 0}}
             LOG.debug("Agent rpc_loop - iteration:%d started",
                       self.iter_num)
             if sync:
@@ -1514,6 +1521,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
                 # Agent doesn't apply any operations when ovs is dead, to
                 # prevent unexpected failure or crash. Sleep and continue
                 # loop in which ovs status will be checked periodically.
+                port_stats = self.get_port_stats({}, {})
                 self.loop_count_and_wait(start, port_stats)
                 continue
             # Notify the plugin of tunnel IP
@@ -1570,12 +1578,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
                                   "ports processed. Elapsed:%(elapsed).3f",
                                   {'iter_num': self.iter_num,
                                    'elapsed': time.time() - start})
-                        port_stats['regular']['added'] = (
-                            len(port_info.get('added', [])))
-                        port_stats['regular']['updated'] = (
-                            len(port_info.get('updated', [])))
-                        port_stats['regular']['removed'] = (
-                            len(port_info.get('removed', [])))
+
                     ports = port_info['current']
 
                     if self.ancillary_brs:
@@ -1587,10 +1590,6 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
                                   {'iter_num': self.iter_num,
                                    'elapsed': time.time() - start})
                         ancillary_ports = ancillary_port_info['current']
-                        port_stats['ancillary']['added'] = (
-                            len(ancillary_port_info.get('added', [])))
-                        port_stats['ancillary']['removed'] = (
-                            len(ancillary_port_info.get('removed', [])))
 
                     polling_manager.polling_completed()
                     # Keep this flag in the last line of "try" block,
@@ -1602,7 +1601,9 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
                     # Put the ports back in self.updated_port
                     self.updated_ports |= updated_ports_copy
                     sync = True
-
+            ancillary_port_info = (ancillary_port_info if self.ancillary_brs
+                else {})
+            port_stats = self.get_port_stats(port_info, ancillary_port_info)
             self.loop_count_and_wait(start, port_stats)
 
     def daemon_loop(self):