Skip to content

Commit cfb7a22

Browse files
authored
Feature table cli command update (sonic-net#1271)
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
1 parent 5b8da56 commit cfb7a22

File tree

4 files changed

+191
-91
lines changed

4 files changed

+191
-91
lines changed

config/feature.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ def feature():
2020
@pass_db
2121
def feature_state(db, name, state):
2222
"""Enable/disable a feature"""
23-
state_data = db.cfgdb.get_entry('FEATURE', name)
23+
entry_data = db.cfgdb.get_entry('FEATURE', name)
2424

25-
if not state_data:
25+
if not entry_data:
2626
click.echo("Feature '{}' doesn't exist".format(name))
2727
sys.exit(1)
2828

29+
if entry_data['state'] == "always_enabled":
30+
click.echo("Feature '{}' state is always enabled and can not be modified".format(name))
31+
return
32+
2933
db.cfgdb.mod_entry('FEATURE', name, {'state': state})
3034

3135
#
@@ -37,13 +41,14 @@ def feature_state(db, name, state):
3741
@pass_db
3842
def feature_autorestart(db, name, autorestart):
3943
"""Enable/disable autorestart of a feature"""
40-
feature_table = db.cfgdb.get_table('FEATURE')
41-
if not feature_table:
42-
click.echo("Unable to retrieve feature table from Config DB.")
43-
sys.exit(1)
44+
entry_data = db.cfgdb.get_entry('FEATURE', name)
4445

45-
if name not in feature_table:
46-
click.echo("Unable to retrieve feature '{}'".format(name))
46+
if not entry_data:
47+
click.echo("Feature '{}' doesn't exist".format(name))
4748
sys.exit(1)
4849

50+
if entry_data['auto_restart'] == "always_enabled":
51+
click.echo("Feature '{}' auto-restart is always enabled and can not be modified".format(name))
52+
return
53+
4954
db.cfgdb.mod_entry('FEATURE', name, {'auto_restart': autorestart})

doc/Command-Reference.md

+108-63
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
* [Console config commands](#console-config-commands)
3737
* [Console connect commands](#console-connect-commands)
3838
* [Console clear commands](#console-clear-commands)
39-
* [Container Auto-restart](#container-auto-restart)
40-
* [Container Auto-restart show commands](#container-auto-restart-show-commands)
41-
* [Container Auto-restart config command](#container-auto-restart-config-command)
4239
* [DHCP Relay](#dhcp-relay)
4340
* [DHCP Relay config commands](#dhcp-relay-config-commands)
4441
* [Drop Counters](#drop-counters)
@@ -48,6 +45,9 @@
4845
* [ECN](#ecn)
4946
* [ECN show commands](#ecn-show-commands)
5047
* [ECN config commands](#ecn-config-commands)
48+
* [Feature](#feature)
49+
* [Feature show commands](#feature-show-commands)
50+
* [Feature config commands](#feature-config-commands)
5151
* [Gearbox](#gearbox)
5252
* [Gearbox show commands](#gearbox-show-commands)
5353
* [Interfaces](#interfaces)
@@ -282,6 +282,7 @@ This command lists all the possible configuration commands at the top level.
282282
acl ACL-related configuration tasks
283283
bgp BGP-related configuration tasks
284284
ecn ECN-related configuration tasks
285+
feature Modify configuration of features
285286
hostname Change device hostname without impacting traffic
286287
interface Interface-related configuration tasks
287288
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.
302303
vrf VRF-related configuration tasks
303304
warm_restart warm_restart-related configuration tasks
304305
watermark Configure watermark
305-
container Modify configuration of containers
306306
```
307307
Go Back To [Beginning of the document](#) or [Beginning of this section](#getting-help)
308308

@@ -333,6 +333,7 @@ This command displays the full list of show commands available in the software;
333333
clock Show date and time
334334
ecn Show ECN configuration
335335
environment Show environmentals (voltages, fans, temps)
336+
feature Show feature status
336337
interfaces Show details of the network interfaces
337338
ip Show IP (IPv4) commands
338339
ipv6 Show IPv6 commands
@@ -365,7 +366,6 @@ This command displays the full list of show commands available in the software;
365366
vrf Show vrf config
366367
warm_restart Show warm restart configuration and state
367368
watermark Show details of watermark
368-
container Show details of container
369369
```
370370

371371
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 `-
20792079
20802080
Go Back To [Beginning of the document](#) or [Beginning of this section](#console)
20812081
2082-
## Container Auto-restart
2083-
2084-
SONiC includes a feature in which Docker containers can be automatically shut
2085-
down and restarted if one of critical processes running in the container exits
2086-
unexpectedly. Restarting the entire container ensures that configuration is
2087-
reloaded and all processes in the container get restarted, thus increasing the
2088-
likelihood of entering a healthy state.
2089-
2090-
### Container Auto-restart show commands
2091-
2092-
**show container feature autorestart**
2093-
2094-
This command will display the status of auto-restart feature for containers.
2095-
2096-
- Usage:
2097-
```
2098-
show container feature autorestart [<container_name>]
2099-
```
2100-
2101-
- Example:
2102-
```
2103-
admin@sonic:~$ show container feature autorestart
2104-
Container Name Status
2105-
-------------- --------
2106-
database enabled
2107-
syncd enabled
2108-
teamd disabled
2109-
dhcp_relay enabled
2110-
lldp enabled
2111-
pmon enabled
2112-
bgp enabled
2113-
swss disabled
2114-
telemetry enabled
2115-
sflow enabled
2116-
snmp enabled
2117-
radv disabled
2118-
```
2119-
2120-
Optionally, you can specify a container name in order to display the auto-restart
2121-
feature status for that container only.
2122-
2123-
### Container Auto-restart config command
2124-
2125-
**config container feature autorestart <container_name> <autorestart_status>**
2126-
2127-
This command will configure the status of auto-restart feature for a specific container.
2128-
2129-
- Usage:
2130-
```
2131-
config container feature autorestart <container_name> (enabled | disabled)
2132-
```
2133-
2134-
- Example:
2135-
```
2136-
admin@sonic:~$ sudo config container feature autorestart database disabled
2137-
```
2138-
2139-
Go Back To [Beginning of the document](#) or [Beginning of this section](#container-auto-restart)
21402082
21412083
## DHCP Relay
21422084
@@ -2437,6 +2379,109 @@ The list of the WRED profile fields that are configurable is listed in the below
24372379
24382380
Go Back To [Beginning of the document](#) or [Beginning of this section](#ecn)
24392381
2382+
## Feature
2383+
2384+
SONiC includes a capability in which Feature state can be enabled/disabled
2385+
which will make corresponding feature docker container to start/stop.
2386+
2387+
Also SONiC provide capability in which Feature docker container can be automatically shut
2388+
down and restarted if one of critical processes running in the container exits
2389+
unexpectedly. Restarting the entire feature container ensures that configuration is
2390+
reloaded and all processes in the feature container get restarted, thus increasing the
2391+
likelihood of entering a healthy state.
2392+
2393+
### Feature show commands
2394+
2395+
**show feature status**
2396+
2397+
This command will display the status of feature state.
2398+
2399+
- Usage:
2400+
```
2401+
show feature status [<feature_name>]
2402+
```
2403+
2404+
- Example:
2405+
```
2406+
admin@sonic:~$ show feature status
2407+
Feature State AutoRestart
2408+
---------- -------------- --------------
2409+
bgp enabled enabled
2410+
database always_enabled always_enabled
2411+
dhcp_relay enabled enabled
2412+
lldp enabled enabled
2413+
pmon enabled enabled
2414+
radv enabled enabled
2415+
snmp enabled enabled
2416+
swss always_enabled enabled
2417+
syncd always_enabled enabled
2418+
teamd always_enabled enabled
2419+
telemetry enabled enabled
2420+
```
2421+
**show feature autorestart**
2422+
2423+
This command will display the status of auto-restart for feature container.
2424+
2425+
- Usage:
2426+
```
2427+
show feature autorestart [<feature_name>]
2428+
```
2429+
2430+
- Example:
2431+
```
2432+
admin@sonic:~$ show feature autorestart
2433+
Feature AutoRestart
2434+
---------- --------------
2435+
bgp enabled
2436+
database always_enabled
2437+
dhcp_relay enabled
2438+
lldp enabled
2439+
pmon enabled
2440+
radv enabled
2441+
snmp enabled
2442+
swss enabled
2443+
syncd enabled
2444+
teamd enabled
2445+
telemetry enabled
2446+
```
2447+
2448+
Optionally, you can specify a feature name in order to display
2449+
status for that feature
2450+
2451+
### Feature config commands
2452+
2453+
**config feature state <feature_name> <state>**
2454+
2455+
This command will configure the state for a specific feature.
2456+
2457+
- Usage:
2458+
```
2459+
config feature state <feature_name> (enabled | disabled)
2460+
```
2461+
2462+
- Example:
2463+
```
2464+
admin@sonic:~$ sudo config feature state bgp disabled
2465+
```
2466+
2467+
**config feature autorestart <feature_name> <autorestart_status>**
2468+
2469+
This command will configure the status of auto-restart for a specific feature container.
2470+
2471+
- Usage:
2472+
```
2473+
config feature autorestart <feature_name> (enabled | disabled)
2474+
```
2475+
2476+
- Example:
2477+
```
2478+
admin@sonic:~$ sudo config feature autorestart bgp disabled
2479+
```
2480+
NOTE: If the existing state or auto-restart value for a feature is "always_enabled" then config
2481+
commands are don't care and will not update state/auto-restart value.
2482+
2483+
Go Back To [Beginning of the document](#) or [Beginning of this section](#feature)
2484+
24402485
## Gearbox
24412486
24422487
This section explains all the Gearbox PHY show commands that are supported in SONiC.

tests/feature_test.py

+68-18
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
from utilities_common.db import Db
44

55
show_feature_status_output="""\
6-
Feature State AutoRestart
7-
---------- -------- -------------
8-
bgp enabled enabled
9-
database enabled disabled
10-
dhcp_relay enabled enabled
11-
lldp enabled enabled
12-
nat enabled enabled
13-
pmon enabled enabled
14-
radv enabled enabled
15-
restapi disabled enabled
16-
sflow disabled enabled
17-
snmp enabled enabled
18-
swss enabled enabled
19-
syncd enabled enabled
20-
teamd enabled enabled
21-
telemetry enabled enabled
6+
Feature State AutoRestart
7+
---------- -------------- --------------
8+
bgp enabled enabled
9+
database always_enabled always_enabled
10+
dhcp_relay enabled enabled
11+
lldp enabled enabled
12+
nat enabled enabled
13+
pmon enabled enabled
14+
radv enabled enabled
15+
restapi disabled enabled
16+
sflow disabled enabled
17+
snmp enabled enabled
18+
swss enabled enabled
19+
syncd enabled enabled
20+
teamd enabled enabled
21+
telemetry enabled enabled
2222
"""
2323

2424
show_feature_bgp_status_output="""\
@@ -35,9 +35,9 @@
3535

3636
show_feature_autorestart_output="""\
3737
Feature AutoRestart
38-
---------- -------------
38+
---------- --------------
3939
bgp enabled
40-
database disabled
40+
database always_enabled
4141
dhcp_relay enabled
4242
lldp enabled
4343
nat enabled
@@ -65,6 +65,18 @@
6565
bgp disabled
6666
"""
6767

68+
show_feature_database_always_enabled_state_output="""\
69+
Feature State AutoRestart
70+
--------- -------------- --------------
71+
database always_enabled always_enabled
72+
"""
73+
74+
show_feature_database_always_enabled_autorestart_output="""\
75+
Feature AutoRestart
76+
--------- --------------
77+
database always_enabled
78+
"""
79+
6880
class TestFeature(object):
6981
@classmethod
7082
def setup_class(cls):
@@ -157,6 +169,44 @@ def test_config_bgp_autorestart(self, get_cmd_module):
157169
assert result.exit_code == 0
158170
assert result.output == show_feature_bgp_disabled_autorestart_output
159171

172+
def test_config_database_feature_state(self, get_cmd_module):
173+
(config, show) = get_cmd_module
174+
db = Db()
175+
runner = CliRunner()
176+
result = runner.invoke(config.config.commands["feature"].commands["state"], ["database", "disabled"], obj=db)
177+
print(result.exit_code)
178+
print(result.output)
179+
result = runner.invoke(show.cli.commands["feature"].commands["status"], ["database"], obj=db)
180+
print(result.output)
181+
assert result.exit_code == 0
182+
assert result.output == show_feature_database_always_enabled_state_output
183+
result = runner.invoke(config.config.commands["feature"].commands["state"], ["database", "enabled"], obj=db)
184+
print(result.exit_code)
185+
print(result.output)
186+
result = runner.invoke(show.cli.commands["feature"].commands["status"], ["database"], obj=db)
187+
print(result.output)
188+
assert result.exit_code == 0
189+
assert result.output == show_feature_database_always_enabled_state_output
190+
191+
def test_config_database_feature_autorestart(self, get_cmd_module):
192+
(config, show) = get_cmd_module
193+
db = Db()
194+
runner = CliRunner()
195+
result = runner.invoke(config.config.commands["feature"].commands["autorestart"], ["database", "disabled"], obj=db)
196+
print(result.exit_code)
197+
print(result.output)
198+
result = runner.invoke(show.cli.commands["feature"].commands["autorestart"], ["database"], obj=db)
199+
print(result.output)
200+
assert result.exit_code == 0
201+
assert result.output == show_feature_database_always_enabled_autorestart_output
202+
result = runner.invoke(config.config.commands["feature"].commands["autorestart"], ["database", "enabled"], obj=db)
203+
print(result.exit_code)
204+
print(result.output)
205+
result = runner.invoke(show.cli.commands["feature"].commands["autorestart"], ["database"], obj=db)
206+
print(result.output)
207+
assert result.exit_code == 0
208+
assert result.output == show_feature_database_always_enabled_autorestart_output
209+
160210
def test_config_unknown_feature(self, get_cmd_module):
161211
(config, show) = get_cmd_module
162212
runner = CliRunner()

tests/mock_tables/config_db.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,8 @@
573573
"high_mem_alert": "disabled"
574574
},
575575
"FEATURE|database": {
576-
"state": "enabled",
577-
"auto_restart": "disabled",
576+
"state": "always_enabled",
577+
"auto_restart": "always_enabled",
578578
"high_mem_alert": "disabled"
579579
},
580580
"FEATURE|dhcp_relay": {

0 commit comments

Comments
 (0)