2021-05-20 17:47:46 -05:00
|
|
|
#!/usr/bin/python3
|
2022-07-10 21:01:10 -05:00
|
|
|
from swsscommon import swsscommon
|
2020-12-10 13:06:19 -06:00
|
|
|
import redis
|
|
|
|
import subprocess
|
|
|
|
import time
|
2022-05-24 18:54:12 -05:00
|
|
|
import syslog
|
2020-12-10 13:06:19 -06:00
|
|
|
|
|
|
|
while(True):
|
2021-05-31 07:36:24 -05:00
|
|
|
output = subprocess.Popen(['sonic-db-cli', 'PING'], stdout=subprocess.PIPE, text=True).communicate()[0]
|
2020-12-10 13:06:19 -06:00
|
|
|
if 'PONG' in output:
|
|
|
|
break
|
|
|
|
time.sleep(1)
|
|
|
|
|
2022-07-10 21:01:10 -05:00
|
|
|
instlists = swsscommon.SonicDBConfig.get_instancelist()
|
2020-12-10 13:06:19 -06:00
|
|
|
for instname, v in instlists.items():
|
|
|
|
insthost = v['hostname']
|
|
|
|
instsocket = v['unix_socket_path']
|
|
|
|
|
2022-07-10 21:01:10 -05:00
|
|
|
dblists = swsscommon.SonicDBConfig.get_dblist()
|
2020-12-10 13:06:19 -06:00
|
|
|
for dbname in dblists:
|
2022-07-10 21:01:10 -05:00
|
|
|
dbid = swsscommon.SonicDBConfig.get_dbid(dbname)
|
|
|
|
dbinst = swsscommon.SonicDBConfig.get_instancename(dbname)
|
2020-12-10 13:06:19 -06:00
|
|
|
|
|
|
|
# this DB is on current instance, skip flush
|
|
|
|
if dbinst == instname:
|
|
|
|
continue
|
|
|
|
|
2022-05-24 18:54:12 -05:00
|
|
|
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))
|