Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[202311][lldp-syncd] Fix unexpected exception in snmp-subagent (#64) #67

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions src/lldp_syncd/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,26 @@ def cache_diff(self, cache, update):

return new_keys, changed_keys, deleted_keys

def is_only_time_mark_modified(self, cached_interface, updated_interface):
"""
Check if only lldp_rem_time_mark is modified in the update
:param cached_interface: Local cached interface dict
:param updated_interface: Updated interface dict
:return: True if only lldp_rem_time_mark is modified, False otherwise
"""
if len(cached_interface) != len(updated_interface):
return False

changed_keys = 0

for key in cached_interface.keys():
if 'lldp_rem_time_mark' == key and cached_interface[key] != updated_interface[key]:
changed_keys += 1
elif key not in updated_interface or cached_interface[key] != updated_interface[key]:
return False

return True if changed_keys == 1 else False

def sync(self, parsed_update):
"""
Sync LLDP information to redis DB.
Expand All @@ -367,18 +387,32 @@ def sync(self, parsed_update):
logger.debug("sync'd: {}".format(json.dumps(chassis_update, indent=3)))

new, changed, deleted = self.cache_diff(self.interfaces_cache, parsed_update)

# For changed elements, if only lldp_rem_time_mark changed, update its value, otherwise delete and repopulate
for interface in changed:
if re.match(SONIC_ETHERNET_RE_PATTERN, interface) is None:
logger.warning("Ignoring interface '{}'".format(interface))
continue
table_key = ':'.join([LldpSyncDaemon.LLDP_ENTRY_TABLE, interface])
if self.is_only_time_mark_modified(self.interfaces_cache[interface], parsed_update[interface]):
self.db_connector.set(self.db_connector.APPL_DB, table_key, 'lldp_rem_time_mark', parsed_update[interface]['lldp_rem_time_mark'], blocking=True)
logger.debug("Only sync'd interface {} lldp_rem_time_mark: {}".format(interface, parsed_update[interface]['lldp_rem_time_mark']))
else:
self.db_connector.delete(self.db_connector.APPL_DB, table_key)
self.db_connector.hmset(self.db_connector.APPL_DB, table_key, parsed_update[interface])
logger.debug("Sync'd changed interface {} : {}".format(interface, parsed_update[interface]))
self.interfaces_cache = parsed_update
# Delete LLDP_ENTRIES which were modified or are missing
for interface in changed + deleted:
# Delete LLDP_ENTRIES which are missing
for interface in deleted:
table_key = ':'.join([LldpSyncDaemon.LLDP_ENTRY_TABLE, interface])
self.db_connector.delete(self.db_connector.APPL_DB, table_key)
# Repopulate LLDP_ENTRY_TABLE by adding all changed elements
for interface in changed + new:
logger.debug("Delete table_key: {}".format(table_key))
# Repopulate LLDP_ENTRY_TABLE by adding new elements
for interface in new:
if re.match(SONIC_ETHERNET_RE_PATTERN, interface) is None:
logger.warning("Ignoring interface '{}'".format(interface))
continue
# port_table_key = LLDP_ENTRY_TABLE:INTERFACE_NAME;
table_key = ':'.join([LldpSyncDaemon.LLDP_ENTRY_TABLE, interface])
for k, v in parsed_update[interface].items():
self.db_connector.set(self.db_connector.APPL_DB, table_key, k, v, blocking=True)
logger.debug("sync'd: \n{}".format(json.dumps(parsed_update[interface], indent=3)))
self.db_connector.hmset(self.db_connector.APPL_DB, table_key, parsed_update[interface])
logger.debug("Add new interface {} : {}".format(interface, parsed_update[interface]))
Loading
Loading