@@ -327,6 +327,12 @@ def add_log_marker(self):
327
327
self .ctn .exec_run ("logger {}" .format (marker ))
328
328
return marker
329
329
330
+ def SubscribeAppDbObject (self , objpfx ):
331
+ r = redis .Redis (unix_socket_path = self .redis_sock , db = swsscommon .APP_DB )
332
+ pubsub = r .pubsub ()
333
+ pubsub .psubscribe ("__keyspace@0__:%s*" % objpfx )
334
+ return pubsub
335
+
330
336
def SubscribeAsicDbObject (self , objpfx ):
331
337
r = redis .Redis (unix_socket_path = self .redis_sock , db = swsscommon .ASIC_DB )
332
338
pubsub = r .pubsub ()
@@ -356,6 +362,64 @@ def CountSubscribedObjects(self, pubsub, ignore=None, timeout=10):
356
362
357
363
return (nadd , ndel )
358
364
365
+ def GetSubscribedAppDbObjects (self , pubsub , ignore = None , timeout = 10 ):
366
+ r = redis .Redis (unix_socket_path = self .redis_sock , db = swsscommon .APP_DB )
367
+
368
+ addobjs = []
369
+ delobjs = []
370
+ idle = 0
371
+
372
+ while True and idle < timeout :
373
+ message = pubsub .get_message ()
374
+ if message :
375
+ print message
376
+ key = message ['channel' ].split (':' , 1 )[1 ]
377
+ if ignore :
378
+ fds = message ['channel' ].split (':' )
379
+ if fds [2 ] in ignore :
380
+ continue
381
+ if message ['data' ] == 'hset' :
382
+ value = r .hgetall (key )
383
+ addobjs .append ({'key' :k , 'vals' :value })
384
+ elif message ['data' ] == 'del' :
385
+ delobjs .append (key )
386
+ idle = 0
387
+ else :
388
+ time .sleep (1 )
389
+ idle += 1
390
+
391
+ return (addobjs , delobjs )
392
+
393
+
394
+ def GetSubscribedAsicDbObjects (self , pubsub , ignore = None , timeout = 10 ):
395
+ r = redis .Redis (unix_socket_path = self .redis_sock , db = swsscommon .ASIC_DB )
396
+
397
+ addobjs = []
398
+ delobjs = []
399
+ idle = 0
400
+
401
+ while True and idle < timeout :
402
+ message = pubsub .get_message ()
403
+ if message :
404
+ print message
405
+ key = message ['channel' ].split (':' , 1 )[1 ]
406
+ if ignore :
407
+ fds = message ['channel' ].split (':' )
408
+ if fds [2 ] in ignore :
409
+ continue
410
+ if message ['data' ] == 'hset' :
411
+ value = r .hgetall (key )
412
+ (_ , t , k ) = key .split (':' , 2 )
413
+ addobjs .append ({'type' :t , 'key' :k , 'vals' :value })
414
+ elif message ['data' ] == 'del' :
415
+ delobjs .append (key )
416
+ idle = 0
417
+ else :
418
+ time .sleep (1 )
419
+ idle += 1
420
+
421
+ return (addobjs , delobjs )
422
+
359
423
def get_map_iface_bridge_port_id (self , asic_db ):
360
424
port_id_2_iface = self .asicdb .portoidmap
361
425
tbl = swsscommon .Table (asic_db , "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT" )
0 commit comments