From be5c941a7d726fe98e427ff3557c5dd90f676d8d Mon Sep 17 00:00:00 2001 From: Yuvaraja Mariappan Date: Wed, 18 May 2016 11:10:16 -0700 Subject: [PATCH] vrouter-nodemgr change for LBAAS config generation on controller 1. loadbalancer directory is set based on the loadbalancer type 2. If vip is present, the loadbalancer stats will be sent to analystics 3. while removing the sandesh objects from uve-cache, each field is set to empty value Change-Id: Id0fe012c9f343982311f9388880a7bc4b3d0d83f Partial-Bug: #1557222 --- src/nodemgr/vrouter_nodemgr/haproxy_stats.py | 3 ++- .../vrouter_nodemgr/loadbalancer_stats.py | 27 ++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/nodemgr/vrouter_nodemgr/haproxy_stats.py b/src/nodemgr/vrouter_nodemgr/haproxy_stats.py index 893586ca50f..8c8e2575018 100644 --- a/src/nodemgr/vrouter_nodemgr/haproxy_stats.py +++ b/src/nodemgr/vrouter_nodemgr/haproxy_stats.py @@ -30,10 +30,11 @@ class HaproxyStats(object): def __init__(self): + self.lbaas_dir = HAPROXY_DIR pass def get_stats(self, pool_id): - sock_path = os.path.join(LB_BASE_DIR, pool_id, 'haproxy.sock') + sock_path = os.path.join(self.lbaas_dir, pool_id, 'haproxy.sock') if not os.path.exists(sock_path): sys.stderr.write('\nStats socket not found for pool ' + pool_id) return {} diff --git a/src/nodemgr/vrouter_nodemgr/loadbalancer_stats.py b/src/nodemgr/vrouter_nodemgr/loadbalancer_stats.py index f4f470c9dc2..98dd83b5dc3 100644 --- a/src/nodemgr/vrouter_nodemgr/loadbalancer_stats.py +++ b/src/nodemgr/vrouter_nodemgr/loadbalancer_stats.py @@ -3,15 +3,17 @@ from haproxy_stats import HaproxyStats from vrouter.loadbalancer.ttypes import \ - UveLoadbalancerTrace, UveLoadbalancer, UveLoadbalancerStats + UveLoadbalancerTrace, UveLoadbalancer, UveLoadbalancerStats LB_BASE_DIR = '/var/lib/contrail/loadbalancer/' class LoadbalancerStats(object): def __init__(self): self.driver = HaproxyStats() + if not self.driver.lbaas_dir: + self.driver.lbaas_dir = LB_BASE_DIR try: - self.old_pool_uuids = os.listdir(LB_BASE_DIR) + self.old_pool_uuids = os.listdir(self.driver.lbaas_dir) except OSError: self.old_pool_uuids = [] @@ -44,7 +46,7 @@ def _uve_get_member_stats(self, stats): def _send_loadbalancer_uve(self): try: - pool_uuids = os.listdir(LB_BASE_DIR) + pool_uuids = os.listdir(self.driver.lbaas_dir) except OSError: return @@ -52,6 +54,9 @@ def _send_loadbalancer_uve(self): for pool_uuid in self.old_pool_uuids: if pool_uuid not in pool_uuids: uve_lb = UveLoadbalancer(name=pool_uuid, deleted=True) + uve_lb.virtual_ip_stats = {} + uve_lb.pool_stats = {} + uve_lb.member_stats = [] uve_trace = UveLoadbalancerTrace(data=uve_lb) uve_trace.send() self.old_pool_uuids = pool_uuids @@ -59,14 +64,24 @@ def _send_loadbalancer_uve(self): # send stats for pool_uuid in pool_uuids: stats = self.driver.get_stats(pool_uuid) - if not len(stats) or not stats.get('vip') or not stats.get('pool'): + if not len(stats) or not 'vip' in stats: + uve_lb = UveLoadbalancer(name=pool_uuid, deleted=True) + uve_lb.virtual_ip_stats = {} + uve_lb.pool_stats = {} + uve_lb.member_stats = [] + uve_trace = UveLoadbalancerTrace(data=uve_lb) + uve_trace.send() continue uve_lb = UveLoadbalancer() uve_lb.name = pool_uuid + uve_lb.pool_stats = {} + uve_lb.member_stats = [] uve_lb.virtual_ip_stats = self._uve_get_stats(stats['vip']) - uve_lb.pool_stats = self._uve_get_stats(stats['pool']) - uve_lb.member_stats = self._uve_get_member_stats(stats['members']) + if 'pool' in stats: + uve_lb.pool_stats = self._uve_get_stats(stats['pool']) + if 'members' in stats: + uve_lb.member_stats = self._uve_get_member_stats(stats['members']) uve_trace = UveLoadbalancerTrace(data=uve_lb) uve_trace.send()