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 authored Nov 26, 2020
1 parent 5b8da56 commit cfb7a22
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 91 deletions.
21 changes: 13 additions & 8 deletions config/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})

#
Expand All @@ -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})
171 changes: 108 additions & 63 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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...
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 [<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:
```
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-auto-restart)
## DHCP Relay
Expand Down Expand Up @@ -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 [<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)
## Gearbox
This section explains all the Gearbox PHY show commands that are supported in SONiC.
Expand Down
86 changes: 68 additions & 18 deletions tests/feature_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="""\
Expand All @@ -35,9 +35,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 @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit cfb7a22

Please sign in to comment.