From 9bf19b91e2c6689ab15bb0a78b85d0ef610eddda Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Mon, 30 Nov 2020 23:07:49 +0000 Subject: [PATCH 1/2] [hostcfgd] check cached state instead of the next state When checking if a feature is 'always_enabled', check the cached state to prevent new change to be accepted. Signed-off-by: Ying Xie --- src/sonic-host-services/scripts/hostcfgd | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sonic-host-services/scripts/hostcfgd b/src/sonic-host-services/scripts/hostcfgd index 159d73c3fdd4..127c081e97e0 100755 --- a/src/sonic-host-services/scripts/hostcfgd +++ b/src/sonic-host-services/scripts/hostcfgd @@ -252,9 +252,10 @@ class HostConfigDaemon: def update_feature_state(self, feature_name, state, feature_table): - if state == "always_enabled": - syslog.syslog(syslog.LOG_INFO, "Feature '{}' service is always enabled" - .format(feature_name)) + if self.cached_feature_states[feature_name] == "always_enabled": + if state != "always_enabled": + syslog.syslog(syslog.LOG_INFO, "Feature '{}' service is always enabled" + .format(feature_name)) return has_timer = ast.literal_eval(feature_table[feature_name].get('has_timer', 'False')) has_global_scope = ast.literal_eval(feature_table[feature_name].get('has_global_scope', 'True')) From ac32476fe5d012071b0f9fc1a551ba8a4f74aa46 Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Tue, 1 Dec 2020 02:00:55 +0000 Subject: [PATCH 2/2] update cache before change, and restore value if needed --- src/sonic-host-services/scripts/hostcfgd | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sonic-host-services/scripts/hostcfgd b/src/sonic-host-services/scripts/hostcfgd index 127c081e97e0..0f583b4dcd9f 100755 --- a/src/sonic-host-services/scripts/hostcfgd +++ b/src/sonic-host-services/scripts/hostcfgd @@ -256,7 +256,13 @@ class HostConfigDaemon: if state != "always_enabled": syslog.syslog(syslog.LOG_INFO, "Feature '{}' service is always enabled" .format(feature_name)) + entry = self.config_db.get_entry('FEATURE', feature_name) + entry['state'] = 'always_enabled' + self.config_db.set_entry('FEATURE', feature_name, entry) return + + self.cached_feature_states[feature_name] = state + has_timer = ast.literal_eval(feature_table[feature_name].get('has_timer', 'False')) has_global_scope = ast.literal_eval(feature_table[feature_name].get('has_global_scope', 'True')) has_per_asic_scope = ast.literal_eval(feature_table[feature_name].get('has_per_asic_scope', 'False')) @@ -376,7 +382,6 @@ class HostConfigDaemon: # Enable/disable the container service if the feature state was changed from its previous state. if self.cached_feature_states[feature_name] != state: - self.cached_feature_states[feature_name] = state self.update_feature_state(feature_name, state, feature_table) def start(self):