From 88759cf5ba41c5b26312ecd133676840d0b25217 Mon Sep 17 00:00:00 2001 From: Zhaohui Sun <94606222+ZhaohuiS@users.noreply.github.com> Date: Wed, 29 Nov 2023 16:22:24 +0800 Subject: [PATCH] [lldp-syncd] Fix unexpected exception in snmp-subagent (#64) Separate deleted and changed scearios deleted interfaces, delete their table key changed interfaces if lldp_rem_time_mark is only changed key, just use hset its new value. Don't delete interface table key. If other keys are changed as well, delete interface key and use hmset to set the whole dict into DB, instead of using hset each item one by one. This will avoid interface exists but some of its keys are not added. Signed-off-by: Zhaohui Sun --- src/lldp_syncd/daemon.py | 48 +- tests/mock_tables/LLDP_ENTRY_TABLE.json | 716 ++++++++++++------------ tests/mock_tables/dbconnector.py | 67 ++- tests/test_lldpSyncDaemon.py | 44 +- 4 files changed, 499 insertions(+), 376 deletions(-) diff --git a/src/lldp_syncd/daemon.py b/src/lldp_syncd/daemon.py index a80edef..fde3002 100644 --- a/src/lldp_syncd/daemon.py +++ b/src/lldp_syncd/daemon.py @@ -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. @@ -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])) diff --git a/tests/mock_tables/LLDP_ENTRY_TABLE.json b/tests/mock_tables/LLDP_ENTRY_TABLE.json index 065ea41..73550f8 100644 --- a/tests/mock_tables/LLDP_ENTRY_TABLE.json +++ b/tests/mock_tables/LLDP_ENTRY_TABLE.json @@ -1,465 +1,465 @@ { - "LLDP_ENTRY_TABLE:Ethernet100": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "LLDP_ENTRY_TABLE:eth0": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "ge-0/0/17", + "lldp_rem_port_desc": "TPS report vending machine", + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18544, - "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, - "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet26", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet4": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", + "lldp_rem_sys_name": "switch218ad08", + "lldp_rem_sys_desc": "I'm going to need you to come in on saturday", + "lldp_rem_man_addr": "", + "lldp_rem_time_mark": "18542", + "lldp_rem_index": "2", "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet0": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet1", + "lldp_rem_port_desc": "this is a port description", + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", + "lldp_rem_sys_name": "switch13", "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18543, + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18545", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet100": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet26", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet2", - "lldp_rem_man_addr": "10.3.147.196" + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18544", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" }, "LLDP_ENTRY_TABLE:Ethernet104": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18544, - "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, - "lldp_rem_sys_name": "switch13", + "lldp_rem_port_id_subtype": "5", "lldp_rem_port_id": "Ethernet27", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet0": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "lldp_rem_port_desc": "", + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18545, - "lldp_rem_port_desc": "this is a port description", - "lldp_rem_chassis_id_subtype": 4, "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet1", - "lldp_rem_man_addr": "10.3.147.196" + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18544", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" }, "LLDP_ENTRY_TABLE:Ethernet108": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18544, - "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, - "lldp_rem_sys_name": "switch13", + "lldp_rem_port_id_subtype": "5", "lldp_rem_port_id": "Ethernet28", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet8": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18543, "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet3", - "lldp_rem_man_addr": "10.3.147.196" + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18544", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" }, - "LLDP_ENTRY_TABLE:Ethernet96": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "", - "lldp_rem_sys_cap_supported": "", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "", - "lldp_rem_time_mark": 18543, + "LLDP_ENTRY_TABLE:Ethernet112": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet29", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, - "lldp_rem_sys_name": "", - "lldp_rem_port_id": "Ethernet25", - "lldp_rem_man_addr": "" - }, - "LLDP_ENTRY_TABLE:Ethernet92": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 32, - "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet24", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet124": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "2103", + "lldp_rem_index": "1", "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet116": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet30", + "lldp_rem_port_desc": "", + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", + "lldp_rem_sys_name": "switch13", "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 4834, + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "1113", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet12": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet4", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet32", - "lldp_rem_man_addr": "10.3.147.196" + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18545", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" }, "LLDP_ENTRY_TABLE:Ethernet120": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet31", + "lldp_rem_port_desc": "", + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", + "lldp_rem_sys_name": "switch13", "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 3844, + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "3844", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet124": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet32", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet31", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet40": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "4834", + "lldp_rem_index": "1", "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet16": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet5", + "lldp_rem_port_desc": "", + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", + "lldp_rem_sys_name": "switch13", "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 572, + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18545", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet20": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet6", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet11", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet44": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18545", + "lldp_rem_index": "1", "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet24": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet7", + "lldp_rem_port_desc": "", + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", + "lldp_rem_sys_name": "switch13", "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 1202, + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "1775", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet28": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet8", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet12", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet48": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18513", + "lldp_rem_index": "1", "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet32": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet9", + "lldp_rem_port_desc": "", + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", + "lldp_rem_sys_name": "switch13", "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 1202, + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "1142", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet36": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet10", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet13", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet24": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "152", + "lldp_rem_index": "1", "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet4": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet2", + "lldp_rem_port_desc": "", + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", + "lldp_rem_sys_name": "switch13", "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 1775, + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18543", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet40": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet11", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet7", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet68": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "572", + "lldp_rem_index": "1", "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet44": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet12", + "lldp_rem_port_desc": "", + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", + "lldp_rem_sys_name": "switch13", "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18543, + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "1202", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet48": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet13", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet18", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:eth0": { - "lldp_rem_index": 2, - "lldp_rem_sys_cap_enabled": "28 00", + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "1202", + "lldp_rem_index": "1", "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm going to need you to come in on saturday", - "lldp_rem_time_mark": 18542, - "lldp_rem_port_desc": "TPS report vending machine", - "lldp_rem_chassis_id_subtype": 4, - "lldp_rem_sys_name": "switch218ad08", - "lldp_rem_port_id": "ge-0/0/17", - "lldp_rem_man_addr": "" + "lldp_rem_sys_cap_enabled": "28 00" }, - "LLDP_ENTRY_TABLE:Ethernet20": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "LLDP_ENTRY_TABLE:Ethernet52": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet14", + "lldp_rem_port_desc": "", + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", + "lldp_rem_sys_name": "switch13", "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18545, + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18543", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet56": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet15", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet6", - "lldp_rem_man_addr": "10.3.147.196" + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18543", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" }, "LLDP_ENTRY_TABLE:Ethernet60": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18543, + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet16", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet16", - "lldp_rem_man_addr": "10.3.147.196" + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18543", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" }, "LLDP_ENTRY_TABLE:Ethernet64": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18543, - "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, - "lldp_rem_sys_name": "switch13", + "lldp_rem_port_id_subtype": "5", "lldp_rem_port_id": "Ethernet17", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet112": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 2103, "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet29", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet116": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18543", + "lldp_rem_index": "1", "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet68": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet18", + "lldp_rem_port_desc": "", + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", + "lldp_rem_sys_name": "switch13", "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 1113, + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18543", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet72": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet19", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet30", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet84": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18543", + "lldp_rem_index": "1", "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet76": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet20", + "lldp_rem_port_desc": "", + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", + "lldp_rem_sys_name": "switch13", "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 362, + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18543", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet8": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet3", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet22", - "lldp_rem_man_addr": "10.3.147.196" + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "18543", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" }, "LLDP_ENTRY_TABLE:Ethernet80": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet21", + "lldp_rem_port_desc": "", + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", + "lldp_rem_sys_name": "switch13", "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 362, + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "362", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" + }, + "LLDP_ENTRY_TABLE:Ethernet84": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet22", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet21", - "lldp_rem_man_addr": "10.3.147.196" + "lldp_rem_sys_desc": "I'm a little teapot.", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "362", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "28 00", + "lldp_rem_sys_cap_enabled": "28 00" }, "LLDP_ENTRY_TABLE:Ethernet88": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 92, - "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, - "lldp_rem_sys_name": "switch13", + "lldp_rem_port_id_subtype": "5", "lldp_rem_port_id": "Ethernet23", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet52": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18543, "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, - "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet14", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet76": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18543, - "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet20", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet56": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18543, - "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, - "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet15", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet72": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "92", + "lldp_rem_index": "1", "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18543, - "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, - "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet19", - "lldp_rem_man_addr": "10.3.147.196" + "lldp_rem_sys_cap_enabled": "28 00" }, - "LLDP_ENTRY_TABLE:Ethernet32": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 1142, + "LLDP_ENTRY_TABLE:Ethernet92": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet24", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, - "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet9", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet28": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, + "lldp_rem_chassis_id_subtype": "4", "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18513, - "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet8", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet36": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 152, - "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, - "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet10", - "lldp_rem_man_addr": "10.3.147.196" - }, - "LLDP_ENTRY_TABLE:Ethernet16": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", + "lldp_rem_man_addr": "10.3.147.196", + "lldp_rem_time_mark": "32", + "lldp_rem_index": "1", "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18545, - "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, - "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet5", - "lldp_rem_man_addr": "10.3.147.196" + "lldp_rem_sys_cap_enabled": "28 00" }, - "LLDP_ENTRY_TABLE:Ethernet12": { - "lldp_rem_index": 1, - "lldp_rem_sys_cap_enabled": "28 00", - "lldp_rem_sys_cap_supported": "28 00", - "lldp_rem_port_id_subtype": 5, - "lldp_rem_chassis_id": "00:11:22:33:44:55", - "lldp_rem_sys_desc": "I'm a little teapot.", - "lldp_rem_time_mark": 18545, + "LLDP_ENTRY_TABLE:Ethernet96": { + "lldp_rem_port_id_subtype": "5", + "lldp_rem_port_id": "Ethernet25", "lldp_rem_port_desc": "", - "lldp_rem_chassis_id_subtype": 4, - "lldp_rem_sys_name": "switch13", - "lldp_rem_port_id": "Ethernet4", - "lldp_rem_man_addr": "10.3.147.196" + "lldp_rem_chassis_id_subtype": "4", + "lldp_rem_chassis_id": "00:11:22:33:44:55", + "lldp_rem_sys_name": "", + "lldp_rem_sys_desc": "", + "lldp_rem_man_addr": "", + "lldp_rem_time_mark": "18543", + "lldp_rem_index": "1", + "lldp_rem_sys_cap_supported": "", + "lldp_rem_sys_cap_enabled": "" }, "LLDP_LOC_CHASSIS": { "lldp_loc_chassis_id_subtype": "4", diff --git a/tests/mock_tables/dbconnector.py b/tests/mock_tables/dbconnector.py index ec44617..ca21263 100644 --- a/tests/mock_tables/dbconnector.py +++ b/tests/mock_tables/dbconnector.py @@ -5,7 +5,7 @@ import mockredis import redis -from swsssdk import SonicV2Connector +from swsscommon.swsscommon import SonicV2Connector from swsssdk import SonicDBConfig from swsssdk.interface import DBInterface from swsscommon import swsscommon @@ -16,13 +16,6 @@ xrange = range basestring = str -_old_connect_SonicV2Connector = SonicV2Connector.connect - -def connect_SonicV2Connector(self, db_name, retry_on=True): - self.dbintf.redis_kwargs['db_name'] = db_name - self.dbintf.redis_kwargs['decode_responses'] = True - _old_connect_SonicV2Connector(self, db_name, retry_on) - def _subscribe_keyspace_notification(self, db_name, client): pass @@ -107,9 +100,63 @@ def keys(self, pattern='*'): # Find every key that matches the pattern return [key for key in self.redis.keys() if regex.match(key)] +class MockConnector(object): + APPL_DB = 0 + CONFIG_DB = 4 + data = {} + + def __init__(self): + pass + + def connect(self, db_id): + if db_id == 0: + with open(INPUT_DIR + '/LLDP_ENTRY_TABLE.json') as f: + db = json.load(f) + for h, table in db.items(): + self.data[h] = {} + for k, v in table.items(): + self.data[h][k] = v + + elif db_id == 4: + with open(INPUT_DIR + '/CONFIG_DB.json') as f: + db = json.load(f) + for h, table in db.items(): + self.data[h] = {} + for k, v in table.items(): + self.data[h][k] = v + + + def get(self, db_id, key, field): + return MockConnector.data[key][field] + + def keys(self, db_id): + ret = [] + for key in MockConnector.data.keys(): + ret.append(key) + + return ret + + def get_all(self, db_id, key): + return MockConnector.data[key] + + def exists(self, db_id, key): + return key in MockConnector.data + + def set(self, db_id, key, field, value, blocking=False): + self.data[key] = {} + self.data[key][field] = value + + def hmset(self, db_id, key, fieldsvalues): + self.data[key] = {} + for field,value in fieldsvalues.items(): + self.data[key][field] = value + + def delete(self, db_id, key): + del self.data[key] + DBInterface._subscribe_keyspace_notification = _subscribe_keyspace_notification mockredis.MockRedis.config_set = config_set redis.StrictRedis = SwssSyncClient -SonicV2Connector.connect = connect_SonicV2Connector -swsscommon.SonicV2Connector = SonicV2Connector +SonicV2Connector.connect = MockConnector.connect +swsscommon.SonicV2Connector = MockConnector diff --git a/tests/test_lldpSyncDaemon.py b/tests/test_lldpSyncDaemon.py index bc50baf..28897bf 100644 --- a/tests/test_lldpSyncDaemon.py +++ b/tests/test_lldpSyncDaemon.py @@ -2,6 +2,7 @@ import sys # noinspection PyUnresolvedReferences import tests.mock_tables.dbconnector +import time modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -14,7 +15,7 @@ import lldp_syncd import lldp_syncd.conventions import lldp_syncd.daemon -from swsssdk import SonicV2Connector +from swsscommon.swsscommon import SonicV2Connector INPUT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'subproc_outputs') @@ -137,3 +138,44 @@ def test_remote_sys_capability_list(self): (if_name, if_attributes), = interface.items() capability_list = self.daemon.get_sys_capability_list(if_attributes, if_name, "fake_chassis_id") self.assertNotEqual(capability_list, []) + + def test_changed_deleted_interface(self): + parsed_update = self.daemon.parse_update(self._json) + self.daemon.sync(parsed_update) + db = create_dbconnector() + keys = db.keys(db.APPL_DB) + # Check if each lldp_rem_time_mark is changed + dump = {} + for k in keys: + if k != 'LLDP_LOC_CHASSIS': + if 'eth0' in k or 'Ethernet0' in k: + dump[k] = db.get(db.APPL_DB, k, 'lldp_rem_time_mark') + elif 'Ethernet100' in k: + dump[k] = db.get(db.APPL_DB, k, 'lldp_rem_port_desc') + + time.sleep(1) + # simulate lldp_rem_time_mark was changed or port description was changed or interface was removed + changed_json = self._json.copy() + changed_json['lldp']['interface'][0]['eth0']['age'] = '0 day, 05:09:12' + changed_json['lldp']['interface'][1]['Ethernet0']['age'] = '0 day, 05:09:15' + changed_json['lldp']['interface'][2]['Ethernet100']['port']['descr'] = "I'm a little teapot, too." + changed_json['lldp']['interface'].pop(3) # Remove interface Ethernet104 + + parsed_update = self.daemon.parse_update(changed_json) + self.daemon.sync(parsed_update) + keys = db.keys(db.APPL_DB) + + jo = {} + for k in keys: + if k != 'LLDP_LOC_CHASSIS': + if 'eth0' in k or 'Ethernet0' in k: + jo[k] = db.get(db.APPL_DB, k, 'lldp_rem_time_mark') + self.assertEqual(int(jo[k]), int(dump[k])+10) + elif 'Ethernet100' in k: + jo[k] = db.get(db.APPL_DB, k, 'lldp_rem_port_desc') + self.assertEqual(dump[k], "") + self.assertEqual(jo[k], "I'm a little teapot, too.") + else: + jo[k] = db.get_all(db.APPL_DB, k) + if 'LLDP_ENTRY_TABLE:Ethernet104' in jo: + self.fail("After removing Ethernet104, it is still found in APPL_DB!") \ No newline at end of file