From 4d1fb7556a35c41cf4a7c1a8d26764f8a11de8c5 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan <47282725+renukamanavalan@users.noreply.github.com> Date: Sat, 31 Oct 2020 16:38:32 -0700 Subject: [PATCH] Load config after subscribe (#5740) - Why I did it The update_all_feature_states can run in the range of 20+ seconds to one minute. With load of AAA & Tacacs preceding it, any DB updates in AAA/TACACS during the long running feature updates would get missed. To avoid, switch the order. - How I did it Do a load after after updating all feature states. - How to verify it Not a easy one Have a script that restart hostcfgd sleep 2s run redis-cli/config command to update AAA/TACACS table Run the script above and watch the file /etc/pam.d/common-auth-sonic for a minute. - When it repro: The updates will not reflect in /etc/pam.d/common-auth-sonic --- files/image_config/hostcfgd/hostcfgd | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/files/image_config/hostcfgd/hostcfgd b/files/image_config/hostcfgd/hostcfgd index b76655ceef2c..9c86cedc7db6 100755 --- a/files/image_config/hostcfgd/hostcfgd +++ b/files/image_config/hostcfgd/hostcfgd @@ -233,17 +233,24 @@ class HostConfigDaemon: self.config_db = ConfigDBConnector() self.config_db.connect(wait_for_init=True, retry_on=True) syslog.syslog(syslog.LOG_INFO, 'ConfigDB connect success') + + self.aaacfg = AaaCfg() + self.iptables = Iptables() + # Cache the values of 'state' field in 'FEATURE' table of each container + self.cached_feature_states = {} + + self.is_multi_npu = device_info.is_multi_npu() + + + def load(self): aaa = self.config_db.get_table('AAA') tacacs_global = self.config_db.get_table('TACPLUS') tacacs_server = self.config_db.get_table('TACPLUS_SERVER') - self.aaacfg = AaaCfg() self.aaacfg.load(aaa, tacacs_global, tacacs_server) + lpbk_table = self.config_db.get_table('LOOPBACK_INTERFACE') - self.iptables = Iptables() self.iptables.load(lpbk_table) - self.is_multi_npu = device_info.is_multi_npu() - # Cache the values of 'state' field in 'FEATURE' table of each container - self.cached_feature_states = {} + def update_feature_state(self, feature_name, state, feature_table): has_timer = ast.literal_eval(feature_table[feature_name].get('has_timer', 'False')) @@ -367,14 +374,19 @@ class HostConfigDaemon: self.update_feature_state(feature_name, state, feature_table) def start(self): - # Update all feature states once upon starting - self.update_all_feature_states() self.config_db.subscribe('AAA', lambda table, key, data: self.aaa_handler(key, data)) self.config_db.subscribe('TACPLUS_SERVER', lambda table, key, data: self.tacacs_server_handler(key, data)) self.config_db.subscribe('TACPLUS', lambda table, key, data: self.tacacs_global_handler(key, data)) self.config_db.subscribe('LOOPBACK_INTERFACE', lambda table, key, data: self.lpbk_handler(key, data)) self.config_db.subscribe('FEATURE', lambda table, key, data: self.feature_state_handler(key, data)) + + # Update all feature states once upon starting + self.update_all_feature_states() + + # Defer load until subscribe + self.load() + self.config_db.listen()