[healthd] Use unix_socket_path instead of loopback ip (#14843)

- Why I did it

interfaces-config service restarts networking service, which in-turn results in loopback interface address is being removed and reassigned back

If the system-health happens to start during that instance expections and logs like this are seen:

Apr 15 18:14:49.357869 r-panther-20 ERR healthd: update system status exception:Unable to connect to redis: Cannot assign requested address
Apr 15 18:14:49.429778 r-panther-20 ERR healthd: subscribe_statedb exited- Unable to connect to redis: Cannot assign requested address
Apr 15 18:14:52.218594 r-panther-20 ERR healthd: system_service_Map_base::at
Apr 15 18:14:52.219714 r-panther-20 ERR healthd: system_service_Map_base::at
Apr 15 18:14:55.218636 r-panther-20 ERR healthd: system_service_Map_base::at
Apr 15 18:14:55.218722 r-panther-20 ERR healthd: system_service_Map_base::at

- How I did it
use unix socket path

Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
This commit is contained in:
Vivek 2023-05-26 05:49:21 -07:00 committed by GitHub
parent f3ce9ebda8
commit bc9c054da2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 12 deletions

View File

@ -15,7 +15,7 @@ class HardwareChecker(HealthChecker):
def __init__(self): def __init__(self):
HealthChecker.__init__(self) HealthChecker.__init__(self)
self._db = SonicV2Connector(host="127.0.0.1") self._db = SonicV2Connector(use_unix_socket_path=True)
self._db.connect(self._db.STATE_DB) self._db.connect(self._db.STATE_DB)
def get_category(self): def get_category(self):

View File

@ -269,7 +269,7 @@ class ServiceChecker(HealthChecker):
config (config.Config): Health checker configuration. config (config.Config): Health checker configuration.
""" """
if not self.config_db: if not self.config_db:
self.config_db = swsscommon.ConfigDBConnector() self.config_db = swsscommon.ConfigDBConnector(use_unix_socket_path=True)
self.config_db.connect() self.config_db.connect()
feature_table = self.config_db.get_table("FEATURE") feature_table = self.config_db.get_table("FEATURE")
expected_running_containers, self.container_feature_dict = self.get_expected_running_containers(feature_table) expected_running_containers, self.container_feature_dict = self.get_expected_running_containers(feature_table)

View File

@ -31,7 +31,7 @@ class MonitorStateDbTask(ProcessTaskBase):
self.task_queue = myQ self.task_queue = myQ
def subscribe_statedb(self): def subscribe_statedb(self):
state_db = swsscommon.DBConnector("STATE_DB", REDIS_TIMEOUT_MS, True) state_db = swsscommon.DBConnector("STATE_DB", REDIS_TIMEOUT_MS, False)
sel = swsscommon.Select() sel = swsscommon.Select()
cst = swsscommon.SubscriberStateTable(state_db, "FEATURE") cst = swsscommon.SubscriberStateTable(state_db, "FEATURE")
sel.addSelectable(cst) sel.addSelectable(cst)
@ -122,7 +122,7 @@ class Sysmonitor(ProcessTaskBase):
def post_system_status(self, state): def post_system_status(self, state):
try: try:
if not self.state_db: if not self.state_db:
self.state_db = swsscommon.SonicV2Connector(host='127.0.0.1') self.state_db = swsscommon.SonicV2Connector(use_unix_socket_path=True)
self.state_db.connect(self.state_db.STATE_DB) self.state_db.connect(self.state_db.STATE_DB)
self.state_db.set(self.state_db.STATE_DB, "SYSTEM_READY|SYSTEM_STATE", "Status", state) self.state_db.set(self.state_db.STATE_DB, "SYSTEM_READY|SYSTEM_STATE", "Status", state)
@ -135,7 +135,7 @@ class Sysmonitor(ProcessTaskBase):
def get_all_service_list(self): def get_all_service_list(self):
if not self.config_db: if not self.config_db:
self.config_db = swsscommon.ConfigDBConnector() self.config_db = swsscommon.ConfigDBConnector(use_unix_socket_path=True)
self.config_db.connect() self.config_db.connect()
dir_list = [] dir_list = []
@ -197,10 +197,10 @@ class Sysmonitor(ProcessTaskBase):
#else, just return Up #else, just return Up
def get_app_ready_status(self, service): def get_app_ready_status(self, service):
if not self.state_db: if not self.state_db:
self.state_db = swsscommon.SonicV2Connector(host='127.0.0.1') self.state_db = swsscommon.SonicV2Connector(use_unix_socket_path=True)
self.state_db.connect(self.state_db.STATE_DB) self.state_db.connect(self.state_db.STATE_DB)
if not self.config_db: if not self.config_db:
self.config_db = swsscommon.ConfigDBConnector() self.config_db = swsscommon.ConfigDBConnector(use_unix_socket_path=True)
self.config_db.connect() self.config_db.connect()
fail_reason = "" fail_reason = ""
@ -248,7 +248,7 @@ class Sysmonitor(ProcessTaskBase):
#Sets the service status to state db #Sets the service status to state db
def post_unit_status(self, srv_name, srv_status, app_status, fail_reason, update_time): def post_unit_status(self, srv_name, srv_status, app_status, fail_reason, update_time):
if not self.state_db: if not self.state_db:
self.state_db = swsscommon.SonicV2Connector(host='127.0.0.1') self.state_db = swsscommon.SonicV2Connector(use_unix_socket_path=True)
self.state_db.connect(self.state_db.STATE_DB) self.state_db.connect(self.state_db.STATE_DB)
key = 'ALL_SERVICE_STATUS|{}'.format(srv_name) key = 'ALL_SERVICE_STATUS|{}'.format(srv_name)
@ -378,7 +378,7 @@ class Sysmonitor(ProcessTaskBase):
def check_unit_status(self, event): def check_unit_status(self, event):
#global dnsrvs_name #global dnsrvs_name
if not self.state_db: if not self.state_db:
self.state_db = swsscommon.SonicV2Connector(host='127.0.0.1') self.state_db = swsscommon.SonicV2Connector(use_unix_socket_path=True)
self.state_db.connect(self.state_db.STATE_DB) self.state_db.connect(self.state_db.STATE_DB)
astate = "DOWN" astate = "DOWN"
@ -419,7 +419,7 @@ class Sysmonitor(ProcessTaskBase):
def system_service(self): def system_service(self):
if not self.state_db: if not self.state_db:
self.state_db = swsscommon.SonicV2Connector(host='127.0.0.1') self.state_db = swsscommon.SonicV2Connector(use_unix_socket_path=True)
self.state_db.connect(self.state_db.STATE_DB) self.state_db.connect(self.state_db.STATE_DB)
mpmgr = multiprocessing.Manager() mpmgr = multiprocessing.Manager()

View File

@ -31,7 +31,7 @@ class HealthDaemon(DaemonBase):
Constructor of HealthDaemon. Constructor of HealthDaemon.
""" """
DaemonBase.__init__(self, SYSLOG_IDENTIFIER) DaemonBase.__init__(self, SYSLOG_IDENTIFIER)
self._db = SonicV2Connector(host="127.0.0.1") self._db = SonicV2Connector(use_unix_socket_path=True)
self._db.connect(self._db.STATE_DB) self._db.connect(self._db.STATE_DB)
self.stop_event = threading.Event() self.stop_event = threading.Event()

View File

@ -2,7 +2,7 @@ class MockConnector(object):
STATE_DB = None STATE_DB = None
data = {} data = {}
def __init__(self, host): def __init__(self, use_unix_socket_path):
pass pass
def connect(self, db_id): def connect(self, db_id):