Skip to content

Commit 49cd91d

Browse files
committed
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 167d67a commit 49cd91d

File tree

4 files changed

+189
-91
lines changed

4 files changed

+189
-91
lines changed

config/main.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -3294,12 +3294,16 @@ def feature():
32943294
@click.argument('state', metavar='<state>', required=True, type=click.Choice(["enabled", "disabled"]))
32953295
def feature_state(name, state):
32963296
"""Enable/disable a feature"""
3297-
state_data = config_db.get_entry('FEATURE', name)
3297+
entry_data = config_db.get_entry('FEATURE', name)
32983298

3299-
if not state_data:
3299+
if not entry_data:
33003300
click.echo("Feature '{}' doesn't exist".format(name))
33013301
sys.exit(1)
33023302

3303+
if entry_data['state'] == "always_enabled":
3304+
click.echo("Feature '{}' state is always enabled and can not be modified".format(name))
3305+
return
3306+
33033307
config_db.mod_entry('FEATURE', name, {'state': state})
33043308

33053309
#
@@ -3310,15 +3314,15 @@ def feature_state(name, state):
33103314
@click.argument('autorestart', metavar='<autorestart>', required=True, type=click.Choice(["enabled", "disabled"]))
33113315
def feature_autorestart(name, autorestart):
33123316
"""Enable/disable autorestart of a feature"""
3313-
feature_table = config_db.get_table('FEATURE')
3314-
if not feature_table:
3315-
click.echo("Unable to retrieve feature table from Config DB.")
3316-
sys.exit(1)
3317-
3318-
if not feature_table.has_key(name):
3319-
click.echo("Unable to retrieve feature '{}'".format(name))
3317+
entry_data = config_db.get_entry('FEATURE', name)
3318+
if not entry_data:
3319+
click.echo("Feature '{}' doesn't exist".format(name))
33203320
sys.exit(1)
33213321

3322+
if entry_data['auto_restart'] == "always_enabled":
3323+
click.echo("Feature '{}' auto-restart is always enabled and can not be modified".format(name))
3324+
return
3325+
33223326
config_db.mod_entry('FEATURE', name, {'auto_restart': autorestart})
33233327

33243328
if __name__ == '__main__':

doc/Command-Reference.md

+108-62
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
* [BGP](#bgp)
3232
* [BGP show commands](#bgp-show-commands)
3333
* [BGP config commands](#bgp-config-commands)
34-
* [Container Auto-restart](#container-autorestart-commands)
35-
* [Container Auto-restart show commands](#container-autorestart-show-commands)
36-
* [Container Auto-restart config command](#container-autorestart-config-command)
3734
* [DHCP Relay](#dhcp-relay)
3835
* [DHCP Relay config commands](#dhcp-relay-config-commands)
3936
* [Drop Counters](#drop-counters)
@@ -43,6 +40,9 @@
4340
* [ECN](#ecn)
4441
* [ECN show commands](#ecn-show-commands)
4542
* [ECN config commands](#ecn-config-commands)
43+
* [Feature](#feature)
44+
* [Feature show commands](#feature-show-commands)
45+
* [Feature config commands](#feature-config-commands)
4646
* [Interfaces](#interfaces)
4747
* [Interface Show Commands](#interface-show-commands)
4848
* [Interface Config Commands](#interface-config-commands)
@@ -256,6 +256,7 @@ This command lists all the possible configuration commands at the top level.
256256
acl ACL-related configuration tasks
257257
bgp BGP-related configuration tasks
258258
ecn ECN-related configuration tasks
259+
feature Modify configuration of features
259260
hostname Change device hostname without impacting traffic
260261
interface Interface-related configuration tasks
261262
interface_naming_mode Modify interface naming mode for interacting...
@@ -273,7 +274,6 @@ This command lists all the possible configuration commands at the top level.
273274
vlan VLAN-related configuration tasks
274275
warm_restart warm_restart-related configuration tasks
275276
watermark Configure watermark
276-
container Modify configuration of containers
277277
```
278278
Go Back To [Beginning of the document](#) or [Beginning of this section](#getting-help)
279279

@@ -304,6 +304,7 @@ This command displays the full list of show commands available in the software;
304304
clock Show date and time
305305
ecn Show ECN configuration
306306
environment Show environmentals (voltages, fans, temps)
307+
feature Show feature status
307308
interfaces Show details of the network interfaces
308309
ip Show IP (IPv4) commands
309310
ipv6 Show IPv6 commands
@@ -335,7 +336,6 @@ This command displays the full list of show commands available in the software;
335336
vlan Show VLAN information
336337
warm_restart Show warm restart configuration and state
337338
watermark Show details of watermark
338-
container Show details of container
339339
```
340340

341341
The same syntax applies to all subgroups of `show` which themselves contain subcommands, and subcommands which accept options/arguments.
@@ -1888,63 +1888,6 @@ This command is used to remove particular IPv4 or IPv6 BGP neighbor configuratio
18881888
18891889
Go Back To [Beginning of the document](#) or [Beginning of this section](#bgp)
18901890
1891-
## Container Auto-restart
1892-
SONiC includes a feature in which Docker containers can be automatically shut
1893-
down and restarted if one of critical processes running in the container exits
1894-
unexpectedly. Restarting the entire container ensures that configureation is
1895-
reloaded and all processes in the container get restarted, thus increasing the
1896-
likelihood of entering a healthy state.
1897-
1898-
### Container Auto-restart show commands
1899-
1900-
**show container feature autorestart**
1901-
1902-
This command will display the status of auto-restart feature for containers.
1903-
1904-
- Usage:
1905-
```
1906-
show container feature autorestart [<container_name>]
1907-
```
1908-
1909-
- Example:
1910-
```
1911-
admin@sonic:~$ show container feature autorestart
1912-
Container Name Status
1913-
-------------- --------
1914-
database enabled
1915-
syncd enabled
1916-
teamd disabled
1917-
dhcp_relay enabled
1918-
lldp enabled
1919-
pmon enabled
1920-
bgp enabled
1921-
swss disabled
1922-
telemetry enabled
1923-
sflow enabled
1924-
snmp enabled
1925-
radv disabled
1926-
```
1927-
1928-
Optionally, you can specify a container name in order to display the auto-restart
1929-
feature status for that container only.
1930-
1931-
### Container Auto-restart config command
1932-
1933-
**config container feature autorestart <container_name> <autorestart_status>**
1934-
1935-
This command will configure the status of auto-restart feature for a specific container.
1936-
1937-
- Usage:
1938-
```
1939-
sudo config container feature autorestart <container_name> (enabled | disabled)
1940-
```
1941-
1942-
- Example:
1943-
```
1944-
admin@sonic:~$ sudo config container feature autorestart database disabled
1945-
```
1946-
Go Back To [Beginning of the document](#) or [Beginning of this section](#container-autorestart-commands)
1947-
19481891
## DHCP Relay
19491892
19501893
### DHCP Relay config commands
@@ -2246,6 +2189,109 @@ The list of the WRED profile fields that are configurable is listed in the below
22462189
22472190
Go Back To [Beginning of the document](#) or [Beginning of this section](#ecn)
22482191
2192+
## Feature
2193+
2194+
SONiC includes a capability in which Feature state can be enabled/disabled
2195+
which will make corresponding feature docker container to start/stop.
2196+
2197+
Also SONiC provide capability in which Feature docker container can be automatically shut
2198+
down and restarted if one of critical processes running in the container exits
2199+
unexpectedly. Restarting the entire feature container ensures that configuration is
2200+
reloaded and all processes in the feature container get restarted, thus increasing the
2201+
likelihood of entering a healthy state.
2202+
2203+
### Feature show commands
2204+
2205+
**show feature status**
2206+
2207+
This command will display the status of feature state.
2208+
2209+
- Usage:
2210+
```
2211+
show feature status [<feature_name>]
2212+
```
2213+
2214+
- Example:
2215+
```
2216+
admin@sonic:~$ show feature status
2217+
Feature State AutoRestart
2218+
---------- -------------- --------------
2219+
bgp enabled enabled
2220+
database always_enabled always_enabled
2221+
dhcp_relay enabled enabled
2222+
lldp enabled enabled
2223+
pmon enabled enabled
2224+
radv enabled enabled
2225+
snmp enabled enabled
2226+
swss always_enabled enabled
2227+
syncd always_enabled enabled
2228+
teamd always_enabled enabled
2229+
telemetry enabled enabled
2230+
```
2231+
**show feature autorestart**
2232+
2233+
This command will display the status of auto-restart for feature container.
2234+
2235+
- Usage:
2236+
```
2237+
show feature autorestart [<feature_name>]
2238+
```
2239+
2240+
- Example:
2241+
```
2242+
admin@sonic:~$ show feature autorestart
2243+
Feature AutoRestart
2244+
---------- --------------
2245+
bgp enabled
2246+
database always_enabled
2247+
dhcp_relay enabled
2248+
lldp enabled
2249+
pmon enabled
2250+
radv enabled
2251+
snmp enabled
2252+
swss enabled
2253+
syncd enabled
2254+
teamd enabled
2255+
telemetry enabled
2256+
```
2257+
2258+
Optionally, you can specify a feature name in order to display
2259+
status for that feature
2260+
2261+
### Feature config commands
2262+
2263+
**config feature state <feature_name> <state>**
2264+
2265+
This command will configure the state for a specific feature.
2266+
2267+
- Usage:
2268+
```
2269+
config feature state <feature_name> (enabled | disabled)
2270+
```
2271+
2272+
- Example:
2273+
```
2274+
admin@sonic:~$ sudo config feature state bgp disabled
2275+
```
2276+
2277+
**config feature autorestart <feature_name> <autorestart_status>**
2278+
2279+
This command will configure the status of auto-restart for a specific feature container.
2280+
2281+
- Usage:
2282+
```
2283+
config feature autorestart <feature_name> (enabled | disabled)
2284+
```
2285+
2286+
- Example:
2287+
```
2288+
admin@sonic:~$ sudo config feature autorestart bgp disabled
2289+
```
2290+
NOTE: If the existing state or auto-restart value for a feature is "always_enabled" then config
2291+
commands are don't care and will not update state/auto-restart value.
2292+
2293+
Go Back To [Beginning of the document](#) or [Beginning of this section](#feature)
2294+
22492295
## Update Device Hostname Configuration Commands
22502296
22512297
This sub-section of commands is used to change device hostname without traffic being impacted.

sonic-utilities-tests/feature_test.py

+66-18
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@
2222
config.config_db = config_db
2323

2424
show_feature_status_output="""\
25-
Feature State AutoRestart
26-
---------- -------- -------------
27-
bgp enabled enabled
28-
database enabled disabled
29-
dhcp_relay enabled enabled
30-
lldp enabled enabled
31-
nat enabled enabled
32-
pmon enabled enabled
33-
radv enabled enabled
34-
restapi disabled enabled
35-
sflow disabled enabled
36-
snmp enabled enabled
37-
swss enabled enabled
38-
syncd enabled enabled
39-
teamd enabled enabled
40-
telemetry enabled enabled
25+
Feature State AutoRestart
26+
---------- -------------- --------------
27+
bgp enabled enabled
28+
database always_enabled always_enabled
29+
dhcp_relay enabled enabled
30+
lldp enabled enabled
31+
nat enabled enabled
32+
pmon enabled enabled
33+
radv enabled enabled
34+
restapi disabled enabled
35+
sflow disabled enabled
36+
snmp enabled enabled
37+
swss enabled enabled
38+
syncd enabled enabled
39+
teamd enabled enabled
40+
telemetry enabled enabled
4141
"""
4242

4343
show_feature_bgp_status_output="""\
@@ -54,9 +54,9 @@
5454

5555
show_feature_autorestart_output="""\
5656
Feature AutoRestart
57-
---------- -------------
57+
---------- --------------
5858
bgp enabled
59-
database disabled
59+
database always_enabled
6060
dhcp_relay enabled
6161
lldp enabled
6262
nat enabled
@@ -84,6 +84,18 @@
8484
bgp disabled
8585
"""
8686

87+
show_feature_database_always_enabled_state_output="""\
88+
Feature State AutoRestart
89+
--------- -------------- --------------
90+
database always_enabled always_enabled
91+
"""
92+
93+
show_feature_database_always_enabled_autorestart_output="""\
94+
Feature AutoRestart
95+
--------- --------------
96+
database always_enabled
97+
"""
98+
8799
class TestFeature(object):
88100
@classmethod
89101
def setup_class(cls):
@@ -155,6 +167,42 @@ def test_config_bgp_autorestart(self):
155167
assert result.exit_code == 0
156168
assert result.output == show_feature_bgp_disabled_autorestart_output
157169

170+
def test_config_database_feature_state(self):
171+
runner = CliRunner()
172+
result = runner.invoke(config.config.commands["feature"].commands["state"], ["database", "disabled"])
173+
print(result.exit_code)
174+
print(result.output)
175+
result = runner.invoke(show.cli.commands["feature"].commands["status"], ["database"])
176+
print(result.output)
177+
assert result.exit_code == 0
178+
assert result.output == show_feature_database_always_enabled_state_output
179+
result = runner.invoke(config.config.commands["feature"].commands["state"], ["database", "enabled"])
180+
print(result.exit_code)
181+
print(result.output)
182+
result = runner.invoke(show.cli.commands["feature"].commands["status"], ["database"])
183+
print(result.output)
184+
assert result.exit_code == 0
185+
assert result.output == show_feature_database_always_enabled_state_output
186+
187+
def test_config_database_feature_autorestart(self):
188+
runner = CliRunner()
189+
result = runner.invoke(config.config.commands["feature"].commands["autorestart"], ["database", "disabled"])
190+
print(result.exit_code)
191+
print(result.output)
192+
result = runner.invoke(show.cli.commands["feature"].commands["autorestart"], ["database"])
193+
print(result.output)
194+
assert result.exit_code == 0
195+
assert result.output == show_feature_database_always_enabled_autorestart_output
196+
result = runner.invoke(config.config.commands["feature"].commands["autorestart"], ["database", "enabled"])
197+
print(result.exit_code)
198+
print(result.output)
199+
result = runner.invoke(show.cli.commands["feature"].commands["autorestart"], ["database"])
200+
print(result.output)
201+
assert result.exit_code == 0
202+
assert result.output == show_feature_database_always_enabled_autorestart_output
203+
204+
205+
158206
def test_config_unknown_feature(self):
159207
runner = CliRunner()
160208
result = runner.invoke(config.config.commands["feature"].commands['state'], ["foo", "enabled"])

sonic-utilities-tests/mock_tables/config_db.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@
147147
"high_mem_alert": "disabled"
148148
},
149149
"FEATURE|database": {
150-
"state": "enabled",
151-
"auto_restart": "disabled",
150+
"state": "always_enabled",
151+
"auto_restart": "always_enabled",
152152
"high_mem_alert": "disabled"
153153
},
154154
"FEATURE|dhcp_relay": {

0 commit comments

Comments
 (0)