Skip to content

Commit

Permalink
Handle feature flow when state is always_enabled (#8811)
Browse files Browse the repository at this point in the history
Why I did it
When feature state is set to always_enabled hostcfgd throws error message
Sep 21 22:30:55.135377 r-leopard-32 ERR /hostcfgd: Unexpected state value 'always_enabled' for feature bgp
Sep 21 22:30:55.420268 r-leopard-32 ERR /hostcfgd: Unexpected state value 'always_enabled' for feature database
Sep 21 22:30:58.672714 r-leopard-32 ERR /hostcfgd: Unexpected state value 'always_enabled' for feature swss
This is due to feature == always_enabled not handled properly.

How I did it
Handled the scenario when feature is always enabled

How to verify it
Restart hostcfgd with feature state configured as always_enabled and check if there are no errors.
Added UT to cover the scenario.
  • Loading branch information
dgsudharsan authored Sep 28, 2021
1 parent ada8043 commit b2659dc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/sonic-host-services/scripts/hostcfgd
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class FeatureHandler(object):
disable = feature.state in ("always_disabled", "disabled")
elif cached_feature.state in ("always_enabled", "always_disabled"):
disable = feature.state == "always_disabled"
enable = feature.state == "always_enabled"
elif cached_feature.state in ("enabled", "disabled"):
enable = feature.state == "enabled"
disable = feature.state == "disabled"
Expand Down
21 changes: 21 additions & 0 deletions src/sonic-host-services/tests/hostcfgd/test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@
"state": "enabled",
"status": "enabled"
},
"sflow": {
"auto_restart": "enabled",
"has_global_scope": "True",
"has_per_asic_scope": "False",
"has_timer": "False",
"high_mem_alert": "disabled",
"set_owner": "local",
"state": "always_enabled"
},
},
},
"expected_config_db": {
Expand Down Expand Up @@ -178,6 +187,15 @@
"state": "enabled",
"status": "enabled"
},
"sflow": {
"auto_restart": "enabled",
"has_global_scope": "True",
"has_per_asic_scope": "False",
"has_timer": "False",
"high_mem_alert": "disabled",
"set_owner": "local",
"state": "always_enabled"
},
},
},
"expected_subprocess_calls": [
Expand All @@ -188,6 +206,9 @@
call("sudo systemctl unmask telemetry.timer", shell=True),
call("sudo systemctl enable telemetry.timer", shell=True),
call("sudo systemctl start telemetry.timer", shell=True),
call("sudo systemctl unmask sflow.service", shell=True),
call("sudo systemctl enable sflow.service", shell=True),
call("sudo systemctl start sflow.service", shell=True),
],
"popen_attributes": {
'communicate.return_value': ('output', 'error')
Expand Down

0 comments on commit b2659dc

Please sign in to comment.