#!/usr/bin/python3 from swsscommon import swsscommon import redis import subprocess import time import syslog while(True): output = subprocess.Popen(['sonic-db-cli', 'PING'], stdout=subprocess.PIPE, text=True).communicate()[0] if 'PONG' in output: break time.sleep(1) instlists = swsscommon.SonicDBConfig.getInstanceList() for instname, v in instlists.items(): insthost = v.hostname instsocket = v.unixSocketPath dblists = swsscommon.SonicDBConfig.getDbList() for dbname in dblists: dbid = swsscommon.SonicDBConfig.getDbId(dbname) dbinst = swsscommon.SonicDBConfig.getDbInst(dbname) # this DB is on current instance, skip flush if dbinst == instname: continue try: r = redis.Redis(host=insthost, unix_socket_path=instsocket, db=dbid) r.flushdb() except (redis.exceptions.ConnectionError): syslog.syslog(syslog.LOG_INFO,"flushdb:Redis Unix Socket connection error for path {} and dbaname {}".format(instsocket, dbname))