Skip to content

Commit

Permalink
[hostcfgd] check cached state instead of the next state (#6067)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
yxieca authored Dec 2, 2020
1 parent be145b6 commit 443f81f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/sonic-host-services/scripts/hostcfgd
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 443f81f

Please sign in to comment.