Skip to content

Commit

Permalink
Feature table cli command update (sonic-net#1271)
Browse files Browse the repository at this point in the history
added new value "always_enabled" for the state and auto-restart field of Feature Table

Once the field value is "always_enabled" it can be changes from config feature .. command

Updated Command Reference Manual
  • Loading branch information
abdosi committed Nov 26, 2020
1 parent 167d67a commit 49cd91d
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 91 deletions.
22 changes: 13 additions & 9 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3294,12 +3294,16 @@ def feature():
@click.argument('state', metavar='<state>', required=True, type=click.Choice(["enabled", "disabled"]))
def feature_state(name, state):
"""Enable/disable a feature"""
state_data = config_db.get_entry('FEATURE', name)
entry_data = config_db.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

config_db.mod_entry('FEATURE', name, {'state': state})

#
Expand All @@ -3310,15 +3314,15 @@ def feature_state(name, state):
@click.argument('autorestart', metavar='<autorestart>', required=True, type=click.Choice(["enabled", "disabled"]))
def feature_autorestart(name, autorestart):
"""Enable/disable autorestart of a feature"""
feature_table = config_db.get_table('FEATURE')
if not feature_table:
click.echo("Unable to retrieve feature table from Config DB.")
sys.exit(1)

if not feature_table.has_key(name):
click.echo("Unable to retrieve feature '{}'".format(name))
entry_data = config_db.get_entry('FEATURE', 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

config_db.mod_entry('FEATURE', name, {'auto_restart': autorestart})

if __name__ == '__main__':
Expand Down
170 changes: 108 additions & 62 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
* [BGP](#bgp)
* [BGP show commands](#bgp-show-commands)
* [BGP config commands](#bgp-config-commands)
* [Container Auto-restart](#container-autorestart-commands)
* [Container Auto-restart show commands](#container-autorestart-show-commands)
* [Container Auto-restart config command](#container-autorestart-config-command)
* [DHCP Relay](#dhcp-relay)
* [DHCP Relay config commands](#dhcp-relay-config-commands)
* [Drop Counters](#drop-counters)
Expand All @@ -43,6 +40,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)
* [Interfaces](#interfaces)
* [Interface Show Commands](#interface-show-commands)
* [Interface Config Commands](#interface-config-commands)
Expand Down Expand Up @@ -256,6 +256,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...
Expand All @@ -273,7 +274,6 @@ This command lists all the possible configuration commands at the top level.
vlan VLAN-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)

Expand Down Expand Up @@ -304,6 +304,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
Expand Down Expand Up @@ -335,7 +336,6 @@ This command displays the full list of show commands available in the software;
vlan Show VLAN information
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.
Expand Down Expand Up @@ -1888,63 +1888,6 @@ This command is used to remove particular IPv4 or IPv6 BGP neighbor configuratio
Go Back To [Beginning of the document](#) or [Beginning of this section](#bgp)
## 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 configureation 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 [<container_name>]
```
- 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 <container_name> <autorestart_status>**
This command will configure the status of auto-restart feature for a specific container.
- Usage:
```
sudo config container feature autorestart <container_name> (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-autorestart-commands)
## DHCP Relay
### DHCP Relay config commands
Expand Down Expand Up @@ -2246,6 +2189,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 [<feature_name>]
```
- 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 [<feature_name>]
```
- 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 <feature_name> <state>**
This command will configure the state for a specific feature.
- Usage:
```
config feature state <feature_name> (enabled | disabled)
```
- Example:
```
admin@sonic:~$ sudo config feature state bgp disabled
```
**config feature autorestart <feature_name> <autorestart_status>**
This command will configure the status of auto-restart for a specific feature container.
- Usage:
```
config feature autorestart <feature_name> (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)
## Update Device Hostname Configuration Commands
This sub-section of commands is used to change device hostname without traffic being impacted.
Expand Down
84 changes: 66 additions & 18 deletions sonic-utilities-tests/feature_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@
config.config_db = config_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="""\
Expand All @@ -54,9 +54,9 @@

show_feature_autorestart_output="""\
Feature AutoRestart
---------- -------------
---------- --------------
bgp enabled
database disabled
database always_enabled
dhcp_relay enabled
lldp enabled
nat enabled
Expand Down Expand Up @@ -84,6 +84,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):
Expand Down Expand Up @@ -155,6 +167,42 @@ def test_config_bgp_autorestart(self):
assert result.exit_code == 0
assert result.output == show_feature_bgp_disabled_autorestart_output

def test_config_database_feature_state(self):
runner = CliRunner()
result = runner.invoke(config.config.commands["feature"].commands["state"], ["database", "disabled"])
print(result.exit_code)
print(result.output)
result = runner.invoke(show.cli.commands["feature"].commands["status"], ["database"])
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"])
print(result.exit_code)
print(result.output)
result = runner.invoke(show.cli.commands["feature"].commands["status"], ["database"])
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):
runner = CliRunner()
result = runner.invoke(config.config.commands["feature"].commands["autorestart"], ["database", "disabled"])
print(result.exit_code)
print(result.output)
result = runner.invoke(show.cli.commands["feature"].commands["autorestart"], ["database"])
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"])
print(result.exit_code)
print(result.output)
result = runner.invoke(show.cli.commands["feature"].commands["autorestart"], ["database"])
print(result.output)
assert result.exit_code == 0
assert result.output == show_feature_database_always_enabled_autorestart_output



def test_config_unknown_feature(self):
runner = CliRunner()
result = runner.invoke(config.config.commands["feature"].commands['state'], ["foo", "enabled"])
Expand Down
4 changes: 2 additions & 2 deletions sonic-utilities-tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,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": {
Expand Down

0 comments on commit 49cd91d

Please sign in to comment.