[hostcfgd] check cached state instead of the next state (#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 ying.xie@microsoft.com - 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.
This commit is contained in:
parent
be145b613c
commit
443f81f9b7
@ -252,10 +252,17 @@ 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))
|
||||
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'))
|
||||
@ -375,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):
|
||||
|
Reference in New Issue
Block a user