diff --git a/config/feature.py b/config/feature.py index 3e19c45c455a..8a90ae798d97 100644 --- a/config/feature.py +++ b/config/feature.py @@ -20,12 +20,16 @@ def feature(): @pass_db def feature_state(db, name, state): """Enable/disable a feature""" - state_data = db.cfgdb.get_entry('FEATURE', name) + entry_data = db.cfgdb.get_entry('FEATURE', name) - if not state_data: + if not entry_data: click.echo("Feature '{}' doesn't exist".format(name)) sys.exit(1) + if entry_data['state'] == "always_enabled": + click.echo("Feature '{}' state is always enabled and can not be modified".format(name)) + return + db.cfgdb.mod_entry('FEATURE', name, {'state': state}) # @@ -37,13 +41,14 @@ def feature_state(db, name, state): @pass_db def feature_autorestart(db, name, autorestart): """Enable/disable autorestart of a feature""" - feature_table = db.cfgdb.get_table('FEATURE') - if not feature_table: - click.echo("Unable to retrieve feature table from Config DB.") - sys.exit(1) + entry_data = db.cfgdb.get_entry('FEATURE', name) - if name not in feature_table: - click.echo("Unable to retrieve feature '{}'".format(name)) + if not entry_data: + click.echo("Feature '{}' doesn't exist".format(name)) sys.exit(1) + if entry_data['auto_restart'] == "always_enabled": + click.echo("Feature '{}' auto-restart is always enabled and can not be modified".format(name)) + return + db.cfgdb.mod_entry('FEATURE', name, {'auto_restart': autorestart}) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 5c947700cc0e..a2ab1cab16b4 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -36,9 +36,6 @@ * [Console config commands](#console-config-commands) * [Console connect commands](#console-connect-commands) * [Console clear commands](#console-clear-commands) -* [Container Auto-restart](#container-auto-restart) - * [Container Auto-restart show commands](#container-auto-restart-show-commands) - * [Container Auto-restart config command](#container-auto-restart-config-command) * [DHCP Relay](#dhcp-relay) * [DHCP Relay config commands](#dhcp-relay-config-commands) * [Drop Counters](#drop-counters) @@ -48,6 +45,9 @@ * [ECN](#ecn) * [ECN show commands](#ecn-show-commands) * [ECN config commands](#ecn-config-commands) +* [Feature](#feature) + * [Feature show commands](#feature-show-commands) + * [Feature config commands](#feature-config-commands) * [Gearbox](#gearbox) * [Gearbox show commands](#gearbox-show-commands) * [Interfaces](#interfaces) @@ -282,6 +282,7 @@ This command lists all the possible configuration commands at the top level. acl ACL-related configuration tasks bgp BGP-related configuration tasks ecn ECN-related configuration tasks + feature Modify configuration of features hostname Change device hostname without impacting traffic interface Interface-related configuration tasks interface_naming_mode Modify interface naming mode for interacting... @@ -302,7 +303,6 @@ This command lists all the possible configuration commands at the top level. vrf VRF-related configuration tasks warm_restart warm_restart-related configuration tasks watermark Configure watermark - container Modify configuration of containers ``` Go Back To [Beginning of the document](#) or [Beginning of this section](#getting-help) @@ -333,6 +333,7 @@ This command displays the full list of show commands available in the software; clock Show date and time ecn Show ECN configuration environment Show environmentals (voltages, fans, temps) + feature Show feature status interfaces Show details of the network interfaces ip Show IP (IPv4) commands ipv6 Show IPv6 commands @@ -365,7 +366,6 @@ This command displays the full list of show commands available in the software; vrf Show vrf config warm_restart Show warm restart configuration and state watermark Show details of watermark - container Show details of container ``` The same syntax applies to all subgroups of `show` which themselves contain subcommands, and subcommands which accept options/arguments. @@ -2079,64 +2079,6 @@ Optionally, you can clear with a remote device name by specifying the `-d` or `- Go Back To [Beginning of the document](#) or [Beginning of this section](#console) -## Container Auto-restart - -SONiC includes a feature in which Docker containers can be automatically shut -down and restarted if one of critical processes running in the container exits -unexpectedly. Restarting the entire container ensures that configuration is -reloaded and all processes in the container get restarted, thus increasing the -likelihood of entering a healthy state. - -### Container Auto-restart show commands - -**show container feature autorestart** - -This command will display the status of auto-restart feature for containers. - -- Usage: - ``` - show container feature autorestart [] - ``` - -- Example: - ``` - admin@sonic:~$ show container feature autorestart - Container Name Status - -------------- -------- - database enabled - syncd enabled - teamd disabled - dhcp_relay enabled - lldp enabled - pmon enabled - bgp enabled - swss disabled - telemetry enabled - sflow enabled - snmp enabled - radv disabled - ``` - -Optionally, you can specify a container name in order to display the auto-restart -feature status for that container only. - -### Container Auto-restart config command - -**config container feature autorestart ** - -This command will configure the status of auto-restart feature for a specific container. - -- Usage: - ``` - config container feature autorestart (enabled | disabled) - ``` - -- Example: - ``` - admin@sonic:~$ sudo config container feature autorestart database disabled - ``` - -Go Back To [Beginning of the document](#) or [Beginning of this section](#container-auto-restart) ## DHCP Relay @@ -2437,6 +2379,109 @@ The list of the WRED profile fields that are configurable is listed in the below Go Back To [Beginning of the document](#) or [Beginning of this section](#ecn) +## Feature + +SONiC includes a capability in which Feature state can be enabled/disabled +which will make corresponding feature docker container to start/stop. + +Also SONiC provide capability in which Feature docker container can be automatically shut +down and restarted if one of critical processes running in the container exits +unexpectedly. Restarting the entire feature container ensures that configuration is +reloaded and all processes in the feature container get restarted, thus increasing the +likelihood of entering a healthy state. + +### Feature show commands + +**show feature status** + +This command will display the status of feature state. + +- Usage: + ``` + show feature status [] + ``` + +- Example: + ``` + admin@sonic:~$ show feature status + Feature State AutoRestart + ---------- -------------- -------------- + bgp enabled enabled + database always_enabled always_enabled + dhcp_relay enabled enabled + lldp enabled enabled + pmon enabled enabled + radv enabled enabled + snmp enabled enabled + swss always_enabled enabled + syncd always_enabled enabled + teamd always_enabled enabled + telemetry enabled enabled + ``` +**show feature autorestart** + +This command will display the status of auto-restart for feature container. + +- Usage: + ``` + show feature autorestart [] + ``` + +- Example: + ``` + admin@sonic:~$ show feature autorestart + Feature AutoRestart + ---------- -------------- + bgp enabled + database always_enabled + dhcp_relay enabled + lldp enabled + pmon enabled + radv enabled + snmp enabled + swss enabled + syncd enabled + teamd enabled + telemetry enabled + ``` + +Optionally, you can specify a feature name in order to display +status for that feature + +### Feature config commands + +**config feature state ** + +This command will configure the state for a specific feature. + +- Usage: + ``` + config feature state (enabled | disabled) + ``` + +- Example: + ``` + admin@sonic:~$ sudo config feature state bgp disabled + ``` + +**config feature autorestart ** + +This command will configure the status of auto-restart for a specific feature container. + +- Usage: + ``` + config feature autorestart (enabled | disabled) + ``` + +- Example: + ``` + admin@sonic:~$ sudo config feature autorestart bgp disabled + ``` +NOTE: If the existing state or auto-restart value for a feature is "always_enabled" then config +commands are don't care and will not update state/auto-restart value. + +Go Back To [Beginning of the document](#) or [Beginning of this section](#feature) + ## Gearbox This section explains all the Gearbox PHY show commands that are supported in SONiC. diff --git a/tests/feature_test.py b/tests/feature_test.py index cf54b89d7b46..c260a4b5f626 100644 --- a/tests/feature_test.py +++ b/tests/feature_test.py @@ -3,22 +3,22 @@ from utilities_common.db import Db show_feature_status_output="""\ -Feature State AutoRestart ----------- -------- ------------- -bgp enabled enabled -database enabled disabled -dhcp_relay enabled enabled -lldp enabled enabled -nat enabled enabled -pmon enabled enabled -radv enabled enabled -restapi disabled enabled -sflow disabled enabled -snmp enabled enabled -swss enabled enabled -syncd enabled enabled -teamd enabled enabled -telemetry enabled enabled +Feature State AutoRestart +---------- -------------- -------------- +bgp enabled enabled +database always_enabled always_enabled +dhcp_relay enabled enabled +lldp enabled enabled +nat enabled enabled +pmon enabled enabled +radv enabled enabled +restapi disabled enabled +sflow disabled enabled +snmp enabled enabled +swss enabled enabled +syncd enabled enabled +teamd enabled enabled +telemetry enabled enabled """ show_feature_bgp_status_output="""\ @@ -35,9 +35,9 @@ show_feature_autorestart_output="""\ Feature AutoRestart ----------- ------------- +---------- -------------- bgp enabled -database disabled +database always_enabled dhcp_relay enabled lldp enabled nat enabled @@ -65,6 +65,18 @@ bgp disabled """ +show_feature_database_always_enabled_state_output="""\ +Feature State AutoRestart +--------- -------------- -------------- +database always_enabled always_enabled +""" + +show_feature_database_always_enabled_autorestart_output="""\ +Feature AutoRestart +--------- -------------- +database always_enabled +""" + class TestFeature(object): @classmethod def setup_class(cls): @@ -157,6 +169,44 @@ def test_config_bgp_autorestart(self, get_cmd_module): assert result.exit_code == 0 assert result.output == show_feature_bgp_disabled_autorestart_output + def test_config_database_feature_state(self, get_cmd_module): + (config, show) = get_cmd_module + db = Db() + runner = CliRunner() + result = runner.invoke(config.config.commands["feature"].commands["state"], ["database", "disabled"], obj=db) + print(result.exit_code) + print(result.output) + result = runner.invoke(show.cli.commands["feature"].commands["status"], ["database"], obj=db) + print(result.output) + assert result.exit_code == 0 + assert result.output == show_feature_database_always_enabled_state_output + result = runner.invoke(config.config.commands["feature"].commands["state"], ["database", "enabled"], obj=db) + print(result.exit_code) + print(result.output) + result = runner.invoke(show.cli.commands["feature"].commands["status"], ["database"], obj=db) + print(result.output) + assert result.exit_code == 0 + assert result.output == show_feature_database_always_enabled_state_output + + def test_config_database_feature_autorestart(self, get_cmd_module): + (config, show) = get_cmd_module + db = Db() + runner = CliRunner() + result = runner.invoke(config.config.commands["feature"].commands["autorestart"], ["database", "disabled"], obj=db) + print(result.exit_code) + print(result.output) + result = runner.invoke(show.cli.commands["feature"].commands["autorestart"], ["database"], obj=db) + print(result.output) + assert result.exit_code == 0 + assert result.output == show_feature_database_always_enabled_autorestart_output + result = runner.invoke(config.config.commands["feature"].commands["autorestart"], ["database", "enabled"], obj=db) + print(result.exit_code) + print(result.output) + result = runner.invoke(show.cli.commands["feature"].commands["autorestart"], ["database"], obj=db) + print(result.output) + assert result.exit_code == 0 + assert result.output == show_feature_database_always_enabled_autorestart_output + def test_config_unknown_feature(self, get_cmd_module): (config, show) = get_cmd_module runner = CliRunner() diff --git a/tests/mock_tables/config_db.json b/tests/mock_tables/config_db.json index 557890a30cdf..81eda85c532e 100644 --- a/tests/mock_tables/config_db.json +++ b/tests/mock_tables/config_db.json @@ -573,8 +573,8 @@ "high_mem_alert": "disabled" }, "FEATURE|database": { - "state": "enabled", - "auto_restart": "disabled", + "state": "always_enabled", + "auto_restart": "always_enabled", "high_mem_alert": "disabled" }, "FEATURE|dhcp_relay": {