Skip to content

Commit

Permalink
Connect to DBs in namespace once in _init_ of FeatureHandler.
Browse files Browse the repository at this point in the history
  • Loading branch information
judyjoseph committed Sep 27, 2022
1 parent 95206e2 commit fd34803
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions scripts/hostcfgd
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,25 @@ class FeatureHandler(object):
self._config_db = config_db
self._feature_state_table = feature_state_table
self._device_config = device_config
self._device_macsec_support = device_info.get_macsec_support_metadata()
self._cached_config = {}
self.is_multi_npu = device_info.is_multi_npu()
self._device_running_config = device_info.get_device_runtime_metadata()
self._device_macsec_support = device_info.get_macsec_support_metadata()
self.ns_cfg_db = {}
self.ns_feature_state_tbl = {}

# Initlaize Global config that loads all database*.json
if self.is_multi_npu:
SonicDBConfig.initializeGlobalConfig()
namespaces = device_info.get_namespaces()
for ns in namespaces:
#Connect to ConfigDB in each namespace
self.ns_cfg_db[ns] = ConfigDBConnector(namespace=ns)
self.ns_cfg_db[ns].connect(wait_for_init=True, retry_on=True)

#Connect to stateDB in each namespace
db_conn = DBConnector(STATE_DB, 0, False, ns);
self.ns_feature_state_tbl[ns] = Table(db_conn, 'FEATURE')

def handler(self, feature_name, op, feature_cfg):
if not feature_cfg:
Expand Down Expand Up @@ -463,21 +478,15 @@ class FeatureHandler(object):
self._config_db.mod_entry('FEATURE', feature.name, {'state': feature.state})

# resync the feature state in CONFIG_DB in namespaces in multi-asic platform
namespaces = device_info.get_namespaces()
for namespace in namespaces:
db = ConfigDBConnector(namespace=namespace)
db.connect()
for ns, db in self.ns_cfg_db.items():
db.mod_entry('FEATURE', feature.name, {'state': feature.state})

def set_feature_state(self, feature, state):
self._feature_state_table.set(feature.name, [('state', state)])

# Update the feature state in STATE_DB in namespaces in multi-asic platform
namespaces = device_info.get_namespaces()
for namespace in namespaces:
db_conn = DBConnector(STATE_DB, 0, False, namespace);
feature_state_tbl = Table(db_conn, 'FEATURE')
feature_state_tbl.set(feature.name, [('state', state)])
for ns, tbl in self.ns_feature_state_tbl.items():
tbl.set(feature.name, [('state', state)])

class Iptables(object):
def __init__(self):
Expand Down Expand Up @@ -1485,10 +1494,6 @@ class HostConfigDaemon:

self.is_multi_npu = device_info.is_multi_npu()

# Initlaize Global config that loads all database*.json
if self.is_multi_npu:
SonicDBConfig.initializeGlobalConfig()

# Initialize AAACfg
self.aaacfg = AaaCfg()

Expand Down

0 comments on commit fd34803

Please sign in to comment.