OVS agent factor our port stats processing

Move the port stats processing from the rpc loop to a new method
get_port_stats

Change-Id: I4a927f5c11328d854fbb5f76d560bbd9425651ea
This commit is contained in:
rossella 2015-07-05 23:58:25 +02:00
parent eb9226214f
commit d82a2f75ac
1 changed files with 17 additions and 16 deletions

View 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):