From ad762d26549c538afd5020136d72032921ba3412 Mon Sep 17 00:00:00 2001 From: Abhishek Dosi Date: Mon, 19 Oct 2020 21:13:01 +0000 Subject: [PATCH 1/5] Updated the the fix for pfc/queue counters also. Signed-off-by: Abhishek Dosi --- scripts/pfcstat | 12 +----------- scripts/portstat | 3 +-- scripts/queuestat | 13 +------------ 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/scripts/pfcstat b/scripts/pfcstat index 4f63ac8f50..2979ba74b6 100755 --- a/scripts/pfcstat +++ b/scripts/pfcstat @@ -18,6 +18,7 @@ from natsort import natsorted from tabulate import tabulate from sonic_py_common.multi_asic import get_external_ports +from utilities_common.netstat import ns_diff, STATUS_NA from utilities_common import multi_asic as multi_asic_util from utilities_common import constants @@ -63,7 +64,6 @@ counter_bucket_tx_dict = { 'SAI_PORT_STAT_PFC_7_TX_PKTS': 7 } -STATUS_NA = 'N/A' COUNTER_TABLE_PREFIX = "COUNTERS:" COUNTERS_PORT_NAME_MAP = "COUNTERS_PORT_NAME_MAP" @@ -155,16 +155,6 @@ class Pfcstat(object): """ Print the difference between two cnstat results. """ - def ns_diff(newstr, oldstr): - """ - Calculate the diff. - """ - if newstr == STATUS_NA or oldstr == STATUS_NA: - return STATUS_NA - else: - new, old = int(newstr), int(oldstr) - return '{:,}'.format(new - old) - table = [] for key, cntr in cnstat_new_dict.iteritems(): diff --git a/scripts/portstat b/scripts/portstat index 1fe00af2cc..f39c12d63b 100755 --- a/scripts/portstat +++ b/scripts/portstat @@ -140,13 +140,12 @@ class Portstat(object): """ # Get speed from APPL_DB full_table_id = PORT_STATUS_TABLE_PREFIX + port_name - speed = PORT_RATE for ns in self.multi_asic.get_ns_list_based_on_options(): self.db = multi_asic.connect_to_all_dbs_for_ns(ns) speed = self.db.get(self.db.APPL_DB, full_table_id, PORT_SPEED_FIELD) if speed is not None: return int(speed)//1000 - return speed + return PORT_RATE def get_port_state(self, port_name): """ diff --git a/scripts/queuestat b/scripts/queuestat index 9ce450a85d..ca8a5ad47b 100755 --- a/scripts/queuestat +++ b/scripts/queuestat @@ -28,8 +28,7 @@ counter_bucket_dict = { 'SAI_QUEUE_STAT_DROPPED_BYTES': 5, } -STATUS_NA = 'N/A' -STATUS_INVALID = 'INVALID' +from utilities_common.netstat import ns_diff, STATUS_NA QUEUE_TYPE_MC = 'MC' QUEUE_TYPE_UC = 'UC' @@ -158,16 +157,6 @@ class Queuestat(object): """ Print the difference between two cnstat results. """ - def ns_diff(newstr, oldstr): - """ - Calculate the diff. - """ - if newstr == STATUS_NA or oldstr == STATUS_NA: - return STATUS_NA - else: - new, old = int(newstr), int(oldstr) - return '{:,}'.format(new - old) - table = [] for key, cntr in cnstat_new_dict.iteritems(): From ed3262471378b02abd64708a9665620ff96dd577 Mon Sep 17 00:00:00 2001 From: Abhishek Dosi Date: Wed, 25 Nov 2020 01:31:33 +0000 Subject: [PATCH 2/5] Updated with always_enabled value for feature table state and auto-restart fields Signed-off-by: Abhishek Dosi --- config/feature.py | 21 +++++--- tests/feature_test.py | 86 +++++++++++++++++++++++++------- tests/mock_tables/config_db.json | 4 +- 3 files changed, 83 insertions(+), 28 deletions(-) diff --git a/config/feature.py b/config/feature.py index 3e19c45c45..8a90ae798d 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/tests/feature_test.py b/tests/feature_test.py index cf54b89d7b..c260a4b5f6 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 557890a30c..81eda85c53 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": { From e5dbf8f4c4e9a5bd8099ca0a23ea8b09804017e2 Mon Sep 17 00:00:00 2001 From: Abhishek Dosi Date: Wed, 25 Nov 2020 03:23:22 +0000 Subject: [PATCH 3/5] Updated Command Reference Manual Signed-off-by: Abhishek Dosi --- doc/Command-Reference.md | 190 ++++++++++++++++++++++++++------------- 1 file changed, 127 insertions(+), 63 deletions(-) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 5c947700cc..f7b4c2fc81 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,12 @@ * [ECN](#ecn) * [ECN show commands](#ecn-show-commands) * [ECN config commands](#ecn-config-commands) +* [Feature State](#feature-state) + * [Feature State show commands](#feature-state-show-commands) + * [Feature State config command](#feature-state-config-command) +* [Feature Auto-restart](#feature-auto-restart) + * [Feature Auto-restart show commands](#feature-auto-restart-show-commands) + * [Feature Auto-restart config command](#feature-auto-restart-config-command) * [Gearbox](#gearbox) * [Gearbox show commands](#gearbox-show-commands) * [Interfaces](#interfaces) @@ -282,6 +285,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 +306,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 +336,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 +369,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 +2082,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 +2382,125 @@ 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 State + +SONiC includes a capability in which Feature state can be enabled/disabled +which will make corresponding feature docker container to start/stop. + +### Feature State 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 + ``` + +Optionally, you can specify a feature name in order to display +status for that feature + +### Feature State config command + +**config feature state ** + +This command will configure the state for a specific feature. +Please note if the state for a feature is "always_enabled" then this +commands is don't care and will not update state. + + +- Usage: + ``` + config feature state (enabled | disabled) + ``` + +- Example: + ``` + admin@sonic:~$ sudo config feature state bgp disabled + ``` + +Go Back To [Beginning of the document](#) or [Beginning of this section](#feature-state) + +## Feature Auto-restart + +SONiC includes a 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 Auto-restart show commands + +**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 the auto-restart +status for that feature container + +### Feature Auto-restart config command + +**config feature autorestart ** + +This command will configure the status of auto-restart for a specific feature container. +Please note if the state of auto-restart for a feature is "always_enabled" then this +commands is don't care and will not update auto-restart state. + + +- Usage: + ``` + config feature autorestart (enabled | disabled) + ``` + +- Example: + ``` + admin@sonic:~$ sudo config feature autorestart bgp disabled + ``` + +Go Back To [Beginning of the document](#) or [Beginning of this section](#feature-auto-restart) + ## Gearbox This section explains all the Gearbox PHY show commands that are supported in SONiC. From 933456e367e4fc144d7c34e02d12f23d8096d0bc Mon Sep 17 00:00:00 2001 From: Abhishek Dosi Date: Wed, 25 Nov 2020 07:21:32 +0000 Subject: [PATCH 4/5] Addresss Review Comments Signed-off-by: Abhishek Dosi --- doc/Command-Reference.md | 81 +++++++++++++++------------------------- 1 file changed, 31 insertions(+), 50 deletions(-) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index f7b4c2fc81..ec4fa6057e 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -45,12 +45,9 @@ * [ECN](#ecn) * [ECN show commands](#ecn-show-commands) * [ECN config commands](#ecn-config-commands) -* [Feature State](#feature-state) - * [Feature State show commands](#feature-state-show-commands) - * [Feature State config command](#feature-state-config-command) -* [Feature Auto-restart](#feature-auto-restart) - * [Feature Auto-restart show commands](#feature-auto-restart-show-commands) - * [Feature Auto-restart config command](#feature-auto-restart-config-command) +* [Feature](#feature) + * [Feature State show commands](#feature-show-commands) + * [Feature State config command](#feature-config-commands) * [Gearbox](#gearbox) * [Gearbox show commands](#gearbox-show-commands) * [Interfaces](#interfaces) @@ -2382,12 +2379,18 @@ 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 State +## Feature SONiC includes a capability in which Feature state can be enabled/disabled which will make corresponding feature docker container to start/stop. -### Feature State show commands +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** @@ -2415,41 +2418,6 @@ This command will display the status of feature state. teamd always_enabled enabled telemetry enabled enabled ``` - -Optionally, you can specify a feature name in order to display -status for that feature - -### Feature State config command - -**config feature state ** - -This command will configure the state for a specific feature. -Please note if the state for a feature is "always_enabled" then this -commands is don't care and will not update state. - - -- Usage: - ``` - config feature state (enabled | disabled) - ``` - -- Example: - ``` - admin@sonic:~$ sudo config feature state bgp disabled - ``` - -Go Back To [Beginning of the document](#) or [Beginning of this section](#feature-state) - -## Feature Auto-restart - -SONiC includes a 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 Auto-restart show commands - **show feature autorestart** This command will display the status of auto-restart for feature container. @@ -2477,17 +2445,28 @@ This command will display the status of auto-restart for feature container. telemetry enabled ``` -Optionally, you can specify a feature name in order to display the auto-restart -status for that feature container +Optionally, you can specify a feature name in order to display +status for that feature + +### Feature config commands -### Feature Auto-restart config command +**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. -Please note if the state of auto-restart for a feature is "always_enabled" then this -commands is don't care and will not update auto-restart state. - - Usage: ``` @@ -2498,8 +2477,10 @@ commands is don't care and will not update auto-restart state. ``` admin@sonic:~$ sudo config feature autorestart bgp disabled ``` +Note: If the 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-auto-restart) +Go Back To [Beginning of the document](#) or [Beginning of this section](#feature) ## Gearbox From d31700d2aab2420a865950d86cac1ca0bbd7f1cf Mon Sep 17 00:00:00 2001 From: Abhishek Dosi Date: Wed, 25 Nov 2020 07:25:41 +0000 Subject: [PATCH 5/5] Fixes Signed-off-by: Abhishek Dosi --- doc/Command-Reference.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index ec4fa6057e..a2ab1cab16 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -46,8 +46,8 @@ * [ECN show commands](#ecn-show-commands) * [ECN config commands](#ecn-config-commands) * [Feature](#feature) - * [Feature State show commands](#feature-show-commands) - * [Feature State config command](#feature-config-commands) + * [Feature show commands](#feature-show-commands) + * [Feature config commands](#feature-config-commands) * [Gearbox](#gearbox) * [Gearbox show commands](#gearbox-show-commands) * [Interfaces](#interfaces) @@ -2477,7 +2477,7 @@ This command will configure the status of auto-restart for a specific feature co ``` admin@sonic:~$ sudo config feature autorestart bgp disabled ``` -Note: If the state or auto-restart value for a feature is "always_enabled" then config +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)