Skip to content

Commit db4231a

Browse files
committed
Added CLI commands to configure Local Users' Passwords Reset feature and display current configuration
1 parent 61d0ec9 commit db4231a

File tree

4 files changed

+106
-1
lines changed

4 files changed

+106
-1
lines changed

config/main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7667,5 +7667,18 @@ def notice(db, category_list, max_events, namespace):
76677667
handle_asic_sdk_health_suppress(db, 'notice', category_list, max_events, namespace)
76687668

76697669

7670+
#
7671+
# 'local_users_passwords_reset' command ('config local-users-passwords-reset ...')
7672+
#
7673+
@config.command('local-users-passwords-reset')
7674+
@click.argument('state', metavar='<enabled|disabled>', required=True, type=click.Choice(['enabled', 'disabled']))
7675+
@clicommon.pass_db
7676+
def state(db, state):
7677+
"""Set local-users-passwords-reset feature state"""
7678+
7679+
config_db = db.cfgdb
7680+
config_db.mod_entry(swsscommon.CFG_LOCAL_USERS_PASSWORDS_RESET, 'global', {'state': state})
7681+
7682+
76707683
if __name__ == '__main__':
76717684
config()

doc/Command-Reference.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@
217217
* [Static DNS show command](#static-dns-show-command)
218218
* [Wake-on-LAN Commands](#wake-on-lan-commands)
219219
* [Send Wake-on-LAN Magic Packet command](#send-wake-on-lan-magic-packet-command)
220-
220+
* [Local Users' Passwords Reset Commands](#local-users-passwords-reset-commands)
221+
* [Local Users' Passwords Config Command](#local-users-passwords-reset-config-command)
222+
* [Reset Local Users' Passwords Show command](#local-users-passwords-reset-show-command)
221223
## Document History
222224

223225
| Version | Modification Date | Details |
@@ -13587,3 +13589,39 @@ Sending 3 magic packet to 11:33:55:77:99:bb via interface Vlan1000
1358713589
```
1358813590
1358913591
For the 4th example, it specifise 2 target MAC addresses and `count` is 3. So it'll send 6 magic packets in total.
13592+
13593+
# Local Users Passwords Reset Commands
13594+
13595+
This sub-section explains the list of the configuration options available for Local Users' Passwords Reset feature.
13596+
13597+
Please note, The commands will not have any effect if the feature is disabled in `rules/config`.
13598+
13599+
## Local Users Passwords Reset Config Command
13600+
13601+
- Set Local Users' Passwords Reset feature state
13602+
13603+
```
13604+
admin@sonic:~$ config local-users-passwords-reset <enabled|disabled>
13605+
Usage: config config local-users-passwords-reset <enabled|disabled>
13606+
Set local-users-passwords-reset feature state
13607+
Options:
13608+
-?, -h, --help Show this message and exit.
13609+
```
13610+
13611+
## Local Users Passwords Reset Show Command
13612+
13613+
- show local-users-passwords-reset
13614+
13615+
```
13616+
admin@sonic:~$ show local-users-passwords-reset
13617+
Usage: show local-users-passwords-reset
13618+
Show local-users-passwords-reset
13619+
Options:
13620+
-h, -?, --help Show this message and exit.
13621+
```
13622+
```
13623+
admin@sonic:~$ show local-users-passwords-reset
13624+
state
13625+
-------
13626+
enabled
13627+
```

show/main.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,26 @@ def received(db, namespace):
22542254
ctx.fail("ASIC/SDK health event is not supported on the platform")
22552255

22562256

2257+
#
2258+
# 'local-users-passwords-reset' command group ("show local-users-passwords-reset ...")
2259+
#
2260+
@cli.command('local-users-passwords-reset')
2261+
@clicommon.pass_db
2262+
def local_users_passwords_reset(db):
2263+
"""Show local-users-passwords-reset state"""
2264+
2265+
feature_table = db.cfgdb.get_entry('LOCAL_USERS_PASSWORDS_RESET', 'global')
2266+
2267+
hdrs = ['state']
2268+
data = []
2269+
2270+
for key in hdrs:
2271+
data.append(feature_table.get(key, '').replace('\\n', '\n'))
2272+
2273+
messages = [data]
2274+
click.echo(tabulate(messages, headers=hdrs, tablefmt='simple', missingval=''))
2275+
2276+
22572277
# Load plugins and register them
22582278
helper = util_base.UtilHelper()
22592279
helper.load_and_register_plugins(plugins, cli)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from click.testing import CliRunner
2+
3+
import config.main as config
4+
import show.main as show
5+
from utilities_common.db import Db
6+
7+
8+
class TestLocalUsersPasswordsReset:
9+
def test_config_command(self):
10+
runner = CliRunner()
11+
12+
db = Db()
13+
14+
result = runner.invoke(config.config.commands['local-users-passwords-reset'], ['enabled'], obj=db)
15+
print(result.output)
16+
assert result.exit_code == 0
17+
assert db.cfgdb.get_entry('LOCAL_USERS_PASSWORDS_RESET', 'global')['state'] == 'enabled'
18+
19+
result = runner.invoke(show.cli.commands['local-users-passwords-reset'], obj=db)
20+
assert result.exit_code == 0
21+
assert 'enabled' in result.output
22+
23+
result = runner.invoke(config.config.commands['local-users-passwords-reset'], ['disabled'], obj=db)
24+
print(result.output)
25+
assert result.exit_code == 0
26+
assert db.cfgdb.get_entry('LOCAL_USERS_PASSWORDS_RESET', 'global')['state'] == 'disabled'
27+
28+
result = runner.invoke(show.cli.commands['local-users-passwords-reset'], obj=db)
29+
assert result.exit_code == 0
30+
assert 'disabled' in result.output
31+
32+
result = runner.invoke(config.config.commands['local-users-passwords-reset'], ['invalid-input'], obj=db)
33+
print(result.output)
34+
assert result.exit_code != 0

0 commit comments

Comments
 (0)