Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hostcfgd]: Add Ability To Configure Feature During Run-time #6700

Conversation

tahmed-dev
Copy link
Contributor

@tahmed-dev tahmed-dev commented Feb 5, 2021

Features may be enabled/disabled for the same topology based on run-time
configuration. This PR adds the ability to enable/disable feature based
on config db data.

singed-off-by: Tamer Ahmed tamer.ahmed@microsoft.com

- Why I did it
Dual ToR topology have mux docker while non single ToR topology does not and hence the need to disable feature during run-time.

- How I did it
Added the ability to pass Jinja2 template to hostcfgd. The template could be as follows:
"{% if 'subtype' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['subtype'] == 'DualToR' %}enabled{% else %}always_disabled{% endif %}"

- How to verify it
On Target:

Single ToR

admin@str-s6000-acs-14:~$ show feature statu
Feature     State            AutoRestart     SystemState    UpdateTime           ContainerId    Version                            SetOwner    CurrentOwner    RemoteState
----------  ---------------  --------------  -------------  -------------------  -------------  ---------------------------------  ----------  --------------  -------------
acms        enabled          enabled         up             2021-02-05 21:21:33  acms                                              local       local           none
bgp         enabled          enabled         up             2021-02-05 21:21:36  bgp                                               local       local           none
database    always_enabled   always_enabled                                                                                        local
dhcp_relay  enabled          enabled         up             2021-02-05 21:22:37  dhcp_relay     mux-debug.0-dirty-20210204.123047  kube        local
lldp        enabled          enabled         up             2021-02-05 21:22:37  lldp           mux-debug.0-dirty-20210204.123047  kube        local
mux         always_disabled  enabled         down           2021-02-05 21:26:52                                                    local       none            none
pmon        enabled          enabled         up             2021-02-05 23:08:07  pmon           mux-debug.0-dirty-20210204.123047  kube        local
radv        enabled          enabled         up             2021-02-05 21:22:32  radv           mux-debug.0-dirty-20210204.123047  kube        local
snmp        enabled          enabled         up             2021-02-05 23:06:45  snmp           mux-debug.0-dirty-20210204.123047  kube        local
swss        enabled          enabled         up             2021-02-05 21:21:50  swss                                              local       local           none
syncd       enabled          enabled         up             2021-02-05 21:22:02  syncd                                             local       local           none
teamd       enabled          enabled         up             2021-02-05 21:22:01  teamd                                             local       local           none
telemetry   enabled          enabled         up             2021-02-05 21:24:12  telemetry      mux-debug.0-dirty-20210204.123047  kube        local

Dual ToR

admin@STR43-0101-0101-01LT0:~$ show feature status 
Feature     State           AutoRestart     SystemState    UpdateTime           ContainerId    Version                            SetOwner    CurrentOwner    RemoteState
----------  --------------  --------------  -------------  -------------------  -------------  ---------------------------------  ----------  --------------  -------------
acms        enabled         enabled         up             2021-02-05 19:22:21  acms                                              local       local           none
bgp         enabled         enabled         up             2021-02-05 20:03:28  bgp                                               local       local           none
database    always_enabled  always_enabled                                                                                        local
dhcp_relay  enabled         enabled         up             2021-02-05 20:03:44  dhcp_relay     mux-debug.0-dirty-20210204.123047  kube        local
lldp        enabled         enabled         up             2021-02-05 20:03:40  lldp           mux-debug.0-dirty-20210204.123047  kube        local
mux         enabled         enabled         up             2021-02-05 20:05:03  mux                                               local       local           none
pmon        enabled         enabled         up             2021-02-05 20:03:30  pmon           mux-debug.0-dirty-20210204.123047  kube        local
radv        enabled         enabled         up             2021-02-05 20:03:36  radv           mux-debug.0-dirty-20210204.123047  kube        local
snmp        enabled         enabled         up             2021-02-05 20:05:09  snmp           mux-debug.0-dirty-20210204.123047  kube        local
swss        enabled         enabled         up             2021-02-05 20:03:26  swss                                              local       local           none
syncd       enabled         enabled         up             2021-02-05 20:03:28  syncd                                             local       local           none
teamd       enabled         enabled         up             2021-02-05 20:03:35  teamd                                             local       local           none
telemetry   enabled         enabled         up             2021-02-05 20:04:24  telemetry      mux-debug.0-dirty-20210204.123047  kube        local

- Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@jleveque
Copy link
Contributor

jleveque commented Feb 6, 2021

Can you provide an example/description of how this template is to be passed to hostcfgd?

@tahmed-dev
Copy link
Contributor Author

Can you provide an example/description of how this template is to be passed to hostcfgd?

in the "How I did it" section above, there is an example template.

@jleveque
Copy link
Contributor

jleveque commented Feb 6, 2021

Can you provide an example/description of how this template is to be passed to hostcfgd?

in the "How I did it" section above, there is an example template.

I see the template. Just want to understand how it is to be passed to the daemon.

@tahmed-dev
Copy link
Contributor Author

Can you provide an example/description of how this template is to be passed to hostcfgd?

in the "How I did it" section above, there is an example template.

I see the template. Just want to understand how it is to be passed to the daemon.

The template gets written to the config_db past of the bootstrapping when init_cfg.json is loaded to the config_db. hostcfgd will consume it from there.

@jleveque
Copy link
Contributor

jleveque commented Feb 6, 2021

The template gets written to the config_db past of the bootstrapping when init_cfg.json is loaded to the config_db. hostcfgd will consume it from there.

The template gets written as a bogus feature state?

@tahmed-dev
Copy link
Contributor Author

tahmed-dev commented Feb 6, 2021

The template gets written to the config_db past of the bootstrapping when init_cfg.json is loaded to the config_db. hostcfgd will consume it from there.

The template gets written as a bogus feature state?

Initially, this line should write the rendered value. Here is an example of before/after hostcgd is invoked:

Before:

        "mux": {
            "auto_restart": "enabled",
            "has_global_scope": "True",
            "has_per_asic_scope": "False",
            "has_timer": "False",
            "high_mem_alert": "disabled",
            "set_owner": "local",
            "state": "{% if 'subtype' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['subtype'] == 'DualToR' %}enabled{% else %}always_disabled{% endif %}"
        },

After

        "mux": {
            "auto_restart": "enabled",
            "has_global_scope": "True",
            "has_per_asic_scope": "False",
            "has_timer": "False",
            "high_mem_alert": "disabled",
            "set_owner": "local",
            "state": "always_disabled"
        },

@jleveque
Copy link
Contributor

jleveque commented Feb 6, 2021

Thanks for the details. While this is a clever solution, I feel it is a bit hacky and complex. Can we not do something simpler, like when hostcfgd first starts, if it detects the subtype is DualToR, It simply changes the state to enabled?

@tahmed-dev
Copy link
Contributor Author

Thanks for the details. While this is a clever solution, I feel it is a bit hacky and complex. Can we not do something simpler, like when hostcfgd first starts, if it detects the subtype is DualToR, It simply changes the state to enabled?

Welcome! I was kind of thinking of more generic approach as if there are more features as such, we would ended filling up hostcfgd with special cases instead of caring about the feature attributes. I open to other solutions.

@tahmed-dev tahmed-dev force-pushed the taahme/hostcfg-add-ability-of-runntime-config branch from ea7408d to d0d14bb Compare February 25, 2021 17:36
Features may be enabled/disabled for the same topology based on run-time
configuration. This PR adds the ability to enable/disable feature based
on config db data.

singed-off-by: Tamer Ahmed <tamer.ahmed@microsoft.com>
@tahmed-dev tahmed-dev force-pushed the taahme/hostcfg-add-ability-of-runntime-config branch from d0d14bb to a5e4fb5 Compare March 12, 2021 00:24
src/sonic-host-services/tests/hostcfgd/hostcfgd_test.py Outdated Show resolved Hide resolved
src/sonic-host-services/tests/hostcfgd/hostcfgd_test.py Outdated Show resolved Hide resolved
src/sonic-host-services/tests/hostcfgd/hostcfgd_test.py Outdated Show resolved Hide resolved
src/sonic-host-services/tests/hostcfgd/test_vectors.py Outdated Show resolved Hide resolved
src/sonic-host-services/.gitignore Outdated Show resolved Hide resolved
src/sonic-host-services/.gitignore Outdated Show resolved Hide resolved
@tahmed-dev tahmed-dev changed the title [hostcfgd]: Add Ability To Configure Feature At Run-time [hostcfgd]: Add Ability To Configure Feature During Run-time Mar 12, 2021
@tahmed-dev tahmed-dev merged commit 51ab39f into sonic-net:master Mar 13, 2021
@tahmed-dev tahmed-dev deleted the taahme/hostcfg-add-ability-of-runntime-config branch March 13, 2021 13:56
daall pushed a commit that referenced this pull request Mar 16, 2021
Features may be enabled/disabled for the same topology based on run-time
configuration. This PR adds the ability to enable/disable feature based
on config db data.

signed-off-by: Tamer Ahmed <tamer.ahmed@microsoft.com>
raphaelt-nvidia pushed a commit to raphaelt-nvidia/sonic-buildimage that referenced this pull request May 23, 2021
…et#6700)

Features may be enabled/disabled for the same topology based on run-time
configuration. This PR adds the ability to enable/disable feature based
on config db data.

signed-off-by: Tamer Ahmed <tamer.ahmed@microsoft.com>
carl-nokia pushed a commit to carl-nokia/sonic-buildimage that referenced this pull request Aug 7, 2021
…et#6700)

Features may be enabled/disabled for the same topology based on run-time
configuration. This PR adds the ability to enable/disable feature based
on config db data.

signed-off-by: Tamer Ahmed <tamer.ahmed@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants