Skip to content

Commit 3454111

Browse files
yxiecasanthosh-kt
authored andcommitted
[hostcfgd] check cached state instead of the next state (sonic-net#6067)
- Why I did it 'always_enabled' feature can still be disabled/enabled. - How I did it When checking if a feature is 'always_enabled', check the cached state to prevent new change to be accepted. Fix an issue where cache value is updated before all the check is done. Restore 'always_enabled' value in config db if someone wants to change. Signed-off-by: Ying Xie [email protected] - How to verify it Without the fix, 'always_enabled' feature can be enabled or disabled without cli protection. With the protection, the change will be rejected properly.
1 parent 1956de3 commit 3454111

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/sonic-host-services/scripts/hostcfgd

+10-4
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,17 @@ class HostConfigDaemon:
252252

253253

254254
def update_feature_state(self, feature_name, state, feature_table):
255-
if state == "always_enabled":
256-
syslog.syslog(syslog.LOG_INFO, "Feature '{}' service is always enabled"
257-
.format(feature_name))
255+
if self.cached_feature_states[feature_name] == "always_enabled":
256+
if state != "always_enabled":
257+
syslog.syslog(syslog.LOG_INFO, "Feature '{}' service is always enabled"
258+
.format(feature_name))
259+
entry = self.config_db.get_entry('FEATURE', feature_name)
260+
entry['state'] = 'always_enabled'
261+
self.config_db.set_entry('FEATURE', feature_name, entry)
258262
return
263+
264+
self.cached_feature_states[feature_name] = state
265+
259266
has_timer = ast.literal_eval(feature_table[feature_name].get('has_timer', 'False'))
260267
has_global_scope = ast.literal_eval(feature_table[feature_name].get('has_global_scope', 'True'))
261268
has_per_asic_scope = ast.literal_eval(feature_table[feature_name].get('has_per_asic_scope', 'False'))
@@ -375,7 +382,6 @@ class HostConfigDaemon:
375382

376383
# Enable/disable the container service if the feature state was changed from its previous state.
377384
if self.cached_feature_states[feature_name] != state:
378-
self.cached_feature_states[feature_name] = state
379385
self.update_feature_state(feature_name, state, feature_table)
380386

381387
def start(self):

0 commit comments

Comments
 (0)