Skip to content

Commit f1f933e

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

File tree

5 files changed

+103
-2
lines changed

5 files changed

+103
-2
lines changed

config/main.py

Lines changed: 13 additions & 0 deletions
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' group ('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+
def state(state):
7532+
"""Set local-users-passwords-reset feature state"""
7533+
7534+
config_db = ConfigDBConnector()
7535+
config_db.connect()
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

Lines changed: 39 additions & 1 deletion
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 state <enabled|disabled>
13327+
Usage: config config local-users-passwords-reset state <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 state
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

Lines changed: 20 additions & 0 deletions
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.group('local-users-passwords-reset', invoke_without_command=True)
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)

tests/config_test.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2741,4 +2741,28 @@ def teardown_class(cls):
27412741
from .mock_tables import dbconnector
27422742
from .mock_tables import mock_single_asic
27432743
importlib.reload(mock_single_asic)
2744-
dbconnector.load_database_config()
2744+
dbconnector.load_database_config()
2745+
2746+
2747+
class TestConfigLocalUsersPasswordsReset(object):
2748+
@classmethod
2749+
def setup_class(cls):
2750+
print('SETUP')
2751+
import config.main
2752+
importlib.reload(config.main)
2753+
2754+
@patch('utilities_common.cli.run_command',
2755+
mock.MagicMock(side_effect=mock_run_command_side_effect))
2756+
def test_local_users_passwords_reset_state(self):
2757+
runner = CliRunner()
2758+
obj = {'db': Db().cfgdb}
2759+
2760+
result = runner.invoke(
2761+
config.config.commands['local-users-passwords-reset'].commands['state'],
2762+
['enabled'], obj=obj)
2763+
2764+
assert result.exit_code == 0
2765+
2766+
@classmethod
2767+
def teardown_class(cls):
2768+
print('TEARDOWN')

tests/show_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,12 @@ def test_rc_syslog(self, mock_rc):
10641064
assert result.exit_code == 0
10651065
assert '[1.1.1.1]' in result.output
10661066

1067+
@patch('show.main.run_command')
1068+
def test_show_local_users_passwords_reset(self, mock_run_command):
1069+
runner = CliRunner()
1070+
result = runner.invoke(show.cli.commands['local-users-passwords-reset'])
1071+
assert result.exit_code == 0
1072+
10671073
@classmethod
10681074
def teardown_class(cls):
10691075
print('TEARDOWN')

0 commit comments

Comments
 (0)