@@ -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