From 5b121ea6c9a5dd54bca08091210fd753a089d9d6 Mon Sep 17 00:00:00 2001 From: Vasant Patil <36455926+vasant17@users.noreply.github.com> Date: Mon, 13 Apr 2020 22:19:07 -0700 Subject: [PATCH] Handle port deletion while updating lldp (#66) Co-authored-by: Vasant --- dockers/docker-lldp-sv2/lldpmgrd | 51 ++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/dockers/docker-lldp-sv2/lldpmgrd b/dockers/docker-lldp-sv2/lldpmgrd index 7e9ef1642a06..71b2c8eb48c5 100755 --- a/dockers/docker-lldp-sv2/lldpmgrd +++ b/dockers/docker-lldp-sv2/lldpmgrd @@ -98,10 +98,12 @@ class LldpManager(object): True) self.pending_cmds = {} + self.config_port_names = set() + self.app_port_names = set() def is_port_up(self, port_name): """ - Determine if a port is up or down by looking into the oper-status for the port in + Determine if a port is up or down by looking into the oper-status for the port in PORT TABLE in the Application DB """ # Retrieve all entires for this port from the Port table @@ -141,8 +143,8 @@ class LldpManager(object): if not port_alias: log_info("Unable to retrieve port alias for port '{}'. Using port name instead.".format(port_name)) port_alias = port_name - - # Get the port description. If None or empty string, we'll skip this configuration + + # Get the port description. If None or empty string, we'll skip this configuration port_desc = port_table_dict.get("description") else: @@ -208,32 +210,43 @@ class LldpManager(object): sel.addSelectable(sst_appdb) # Listen for changes to the PORT table in the CONFIG_DB and APP_DB + # Only when port is present in both DBs and the operation status is UP + # we are going to configure it in lldp while True: (state, c) = sel.select(SELECT_TIMEOUT_MS) if state == swsscommon.Select.OBJECT: + + # handle alias or description changes, by listening to + # changes in config DB (key, op, fvp) = sst_confdb.pop() - if fvp: - fvp_dict = dict(fvp) + if op == "DEL": + self.config_port_names.discard(key) + self.pending_cmds.pop(key, None) + elif op == "SET": + self.config_port_names.add(key) + if fvp and key in self.app_port_names: + fvp_dict = dict(fvp) - # handle config change - if (fvp_dict.has_key("alias") or fvp_dict.has_key("description")) and (op in ["SET", "DEL"]): - if self.is_port_up(key): + if (fvp_dict.has_key("alias") or fvp_dict.has_key("description")) and (self.is_port_up(key)): self.generate_pending_lldp_config_cmd_for_port(key) - else: - self.pending_cmds.pop(key, None) + # handle port status change, by listening to + # changes in APP DB (key, op, fvp) = sst_appdb.pop() if (key != "PortInitDone") and (key != "PortConfigDone"): - if fvp: - fvp_dict = dict(fvp) - - # handle port status change - if fvp_dict.has_key("oper_status"): - if "up" in fvp_dict.get("oper_status"): - self.generate_pending_lldp_config_cmd_for_port(key) - else: - self.pending_cmds.pop(key, None) + if op == "DEL": + self.app_port_names.discard(key) + self.pending_cmds.pop(key, None) + elif op == "SET": + self.app_port_names.add(key) + if fvp and key in self.config_port_names: + fvp_dict = dict(fvp) + + # handle port status change + if fvp_dict.has_key("oper_status"): + if "up" in fvp_dict.get("oper_status"): + self.generate_pending_lldp_config_cmd_for_port(key) # Process all pending commands self.process_pending_cmds()