Skip to content

Commit 4d25c4e

Browse files
committed
Add chassis cache update
1 parent b0ea01f commit 4d25c4e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/lldp_syncd/daemon.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ def sync(self, parsed_update):
386386
for k, v in chassis_update.items():
387387
self.db_connector.set(self.db_connector.APPL_DB,
388388
LldpSyncDaemon.LLDP_LOC_CHASSIS_TABLE, k, v, blocking=True)
389+
self.chassis_cache = chassis_update
389390
logger.debug("sync'd: {}".format(json.dumps(chassis_update, indent=3)))
390391

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

tests/test_lldpSyncDaemon.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,30 @@ def test_changed_interface(self):
271271
self.assertEqual(jo[k], 'Ethernet1')
272272
else:
273273
jo[k] = db.get_all(db.APPL_DB, k)
274+
275+
def test_chassis_cache_no_db_calls_when_unchanged(self):
276+
"""
277+
Test that database operations are not called when chassis data hasn't changed.
278+
"""
279+
# First sync to populate chassis_cache
280+
parsed_update = self.daemon.parse_update(self._json)
281+
self.daemon.sync(parsed_update)
282+
initial_cache = self.daemon.chassis_cache.copy()
283+
284+
# Sync again with same data - DB operations should NOT be called
285+
parsed_update_same = self.daemon.parse_update(self._json)
286+
287+
with mock.patch.object(self.daemon.db_connector, 'delete') as mock_delete, \
288+
mock.patch.object(self.daemon.db_connector, 'set') as mock_set:
289+
290+
self.daemon.sync(parsed_update_same)
291+
292+
# Verify chassis DB operations were NOT called
293+
chassis_deletes = [c for c in mock_delete.call_args_list
294+
if len(c[0]) > 1 and c[0][1] == 'LLDP_LOC_CHASSIS']
295+
chassis_sets = [c for c in mock_set.call_args_list
296+
if len(c[0]) > 1 and c[0][1] == 'LLDP_LOC_CHASSIS']
297+
298+
self.assertEqual(len(chassis_deletes), 0)
299+
self.assertEqual(len(chassis_sets), 0)
300+
self.assertEqual(self.daemon.chassis_cache, initial_cache)

0 commit comments

Comments
 (0)