Skip to content

Commit b41277b

Browse files
committed
Added CLI commands to configure Local Users' Passwords Reset feature and display current configuration
1 parent 099d40c commit b41277b

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

config/main.py

+13
Original file line numberDiff line numberDiff line change
@@ -7523,5 +7523,18 @@ def date(date, time):
75237523
clicommon.run_command(['timedatectl', 'set-time', date_time])
75247524

75257525

7526+
#
7527+
# 'local_users_passwords_reset' command ('config local-users-passwords-reset ...')
7528+
#
7529+
@config.command('local-users-passwords-reset')
7530+
@click.argument('state', metavar='<enabled|disabled>', required=True, type=click.Choice(['enabled', 'disabled']))
7531+
@clicommon.pass_db
7532+
def state(db, state):
7533+
"""Set local-users-passwords-reset feature state"""
7534+
7535+
config_db = db.cfgdb
7536+
config_db.mod_entry(swsscommon.CFG_LOCAL_USERS_PASSWORDS_RESET, 'global', {'state': state})
7537+
7538+
75267539
if __name__ == '__main__':
75277540
config()

doc/Command-Reference.md

+39-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@
211211
* [Static DNS show command](#static-dns-show-command)
212212
* [Wake-on-LAN Commands](#wake-on-lan-commands)
213213
* [Send Wake-on-LAN Magic Packet command](#send-wake-on-lan-magic-packet-command)
214-
214+
* [Local Users' Passwords Reset Commands](#local-users-passwords-reset-commands)
215+
* [Local Users' Passwords Config Command](#local-users-passwords-reset-config-command)
216+
* [Reset Local Users' Passwords Show command](#local-users-passwords-reset-show-command)
215217
## Document History
216218

217219
| Version | Modification Date | Details |
@@ -13309,3 +13311,39 @@ Sending 3 magic packet to 11:33:55:77:99:bb via interface Vlan1000
1330913311
```
1331013312
1331113313
For the 4th example, it specifise 2 target MAC addresses and `count` is 3. So it'll send 6 magic packets in total.
13314+
13315+
# Local Users Passwords Reset Commands
13316+
13317+
This sub-section explains the list of the configuration options available for Local Users' Passwords Reset feature.
13318+
13319+
Please note, The commands will not have any effect if the feature is disabled in `rules/config`.
13320+
13321+
## Local Users Passwords Reset Config Command
13322+
13323+
- Set Local Users' Passwords Reset feature state
13324+
13325+
```
13326+
admin@sonic:~$ config local-users-passwords-reset <enabled|disabled>
13327+
Usage: config config local-users-passwords-reset <enabled|disabled>
13328+
Set local-users-passwords-reset feature state
13329+
Options:
13330+
-?, -h, --help Show this message and exit.
13331+
```
13332+
13333+
## Local Users Passwords Reset Show Command
13334+
13335+
- show local-users-passwords-reset
13336+
13337+
```
13338+
admin@sonic:~$ show local-users-passwords-reset
13339+
Usage: show local-users-passwords-reset
13340+
Show local-users-passwords-reset
13341+
Options:
13342+
-h, -?, --help Show this message and exit.
13343+
```
13344+
```
13345+
admin@sonic:~$ show local-users-passwords-reset
13346+
state
13347+
-------
13348+
enabled
13349+
```

show/main.py

+20
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,26 @@ def suppress_pending_fib(db):
21572157
click.echo(state)
21582158

21592159

2160+
#
2161+
# 'local-users-passwords-reset' command group ("show local-users-passwords-reset ...")
2162+
#
2163+
@cli.command('local-users-passwords-reset')
2164+
@clicommon.pass_db
2165+
def local_users_passwords_reset(db):
2166+
"""Show local-users-passwords-reset state"""
2167+
2168+
feature_table = db.cfgdb.get_entry('LOCAL_USERS_PASSWORDS_RESET', 'global')
2169+
2170+
hdrs = ['state']
2171+
data = []
2172+
2173+
for key in hdrs:
2174+
data.append(feature_table.get(key, '').replace('\\n', '\n'))
2175+
2176+
messages = [data]
2177+
click.echo(tabulate(messages, headers=hdrs, tablefmt='simple', missingval=''))
2178+
2179+
21602180
# Load plugins and register them
21612181
helper = util_base.UtilHelper()
21622182
helper.load_and_register_plugins(plugins, cli)
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from click.testing import CliRunner
2+
3+
import config.main as config
4+
import show.main as show
5+
from swsscommon import swsscommon
6+
from utilities_common.db import Db
7+
8+
9+
class TestLocalUsersPasswordsReset:
10+
def test_config_command(self):
11+
runner = CliRunner()
12+
13+
db = Db()
14+
15+
result = runner.invoke(config.config.commands['local-users-passwords-reset'], ['enabled'], obj=db)
16+
print(result.output)
17+
assert result.exit_code == 0
18+
assert db.cfgdb.get_entry('LOCAL_USERS_PASSWORDS_RESET', 'global')['state'] == 'enabled'
19+
20+
result = runner.invoke(show.cli.commands['local-users-passwords-reset'], obj=db)
21+
assert result.exit_code == 0
22+
assert 'enabled' in result.output
23+
24+
result = runner.invoke(config.config.commands['local-users-passwords-reset'], ['disabled'], obj=db)
25+
print(result.output)
26+
assert result.exit_code == 0
27+
assert db.cfgdb.get_entry('LOCAL_USERS_PASSWORDS_RESET', 'global')['state'] == 'disabled'
28+
29+
result = runner.invoke(show.cli.commands['local-users-passwords-reset'], obj=db)
30+
assert result.exit_code == 0
31+
assert 'disabled' in result.output
32+
33+
result = runner.invoke(config.config.commands['local-users-passwords-reset'], ['invalid-input'], obj=db)
34+
print(result.output)
35+
assert result.exit_code != 0

0 commit comments

Comments
 (0)