diff --git a/config/main.py b/config/main.py index 2ebc4f077a..665af5fd6f 100644 --- a/config/main.py +++ b/config/main.py @@ -8949,6 +8949,18 @@ def notice(db, category_list, max_events, namespace): # +# 'local_users_passwords_reset' command ('config local-users-passwords-reset ...') +# +@config.command('local-users-passwords-reset') +@click.argument('state', metavar='', required=True, type=click.Choice(['enabled', 'disabled'])) +@clicommon.pass_db +def state(db, state): + """Set local-users-passwords-reset feature state""" + + config_db = db.cfgdb + config_db.mod_entry(swsscommon.CFG_LOCAL_USERS_PASSWORDS_RESET, 'global', {'state': state}) + + # 'serial_console' group ('config serial_console') # @config.group(cls=clicommon.AbbreviationGroup, name='serial_console') diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index fdff48d5c7..b7217bb721 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -225,6 +225,9 @@ * [Static DNS show command](#static-dns-show-command) * [Wake-on-LAN Commands](#wake-on-lan-commands) * [Send Wake-on-LAN Magic Packet command](#send-wake-on-lan-magic-packet-command) +* [Local Users' Passwords Reset Commands](#local-users-passwords-reset-commands) + * [Local Users' Passwords Config Command](#local-users-passwords-reset-config-command) + * [Reset Local Users' Passwords Show command](#local-users-passwords-reset-show-command) * [Banner Commands](#banner-commands) * [Banner config commands](#banner-config-commands) * [Banner show command](#banner-show-command) @@ -13836,6 +13839,42 @@ Sending 3 magic packet to 11:33:55:77:99:bb via interface Vlan1000 For the 4th example, it specifise 2 target MAC addresses and `count` is 3. So it'll send 6 magic packets in total. +# Local Users Passwords Reset Commands + +This sub-section explains the list of the configuration options available for Local Users' Passwords Reset feature. + +Please note, The commands will not have any effect if the feature is disabled in `rules/config`. + +## Local Users Passwords Reset Config Command + +- Set Local Users' Passwords Reset feature state + +``` + admin@sonic:~$ config local-users-passwords-reset + Usage: config config local-users-passwords-reset + Set local-users-passwords-reset feature state + Options: + -?, -h, --help Show this message and exit. + ``` + + ## Local Users Passwords Reset Show Command + +- show local-users-passwords-reset + +``` + admin@sonic:~$ show local-users-passwords-reset + Usage: show local-users-passwords-reset + Show local-users-passwords-reset + Options: + -h, -?, --help Show this message and exit. + ``` + ``` + admin@sonic:~$ show local-users-passwords-reset + state + ------- + enabled + ``` + # Banner Commands This sub-section explains the list of the configuration options available for Banner feature. diff --git a/show/main.py b/show/main.py index 0230da3ffd..a0de752277 100755 --- a/show/main.py +++ b/show/main.py @@ -2694,6 +2694,25 @@ def received(db, namespace): # +# 'local-users-passwords-reset' command group ("show local-users-passwords-reset ...") +# +@cli.command('local-users-passwords-reset') +@clicommon.pass_db +def local_users_passwords_reset(db): + """Show local-users-passwords-reset state""" + + feature_table = db.cfgdb.get_entry('LOCAL_USERS_PASSWORDS_RESET', 'global') + + hdrs = ['state'] + data = [] + + for key in hdrs: + data.append(feature_table.get(key, '')) + + messages = [data] + click.echo(tabulate(messages, headers=hdrs, tablefmt='simple', missingval='')) + + # 'serial_console' command group ("show serial_console ...") # @cli.group('serial_console', invoke_without_command=True) diff --git a/tests/local_users_passwords_reset_test.py b/tests/local_users_passwords_reset_test.py new file mode 100644 index 0000000000..1c178067ce --- /dev/null +++ b/tests/local_users_passwords_reset_test.py @@ -0,0 +1,34 @@ +from click.testing import CliRunner + +import config.main as config +import show.main as show +from utilities_common.db import Db + + +class TestLocalUsersPasswordsReset: + def test_config_command(self): + runner = CliRunner() + + db = Db() + + result = runner.invoke(config.config.commands['local-users-passwords-reset'], ['enabled'], obj=db) + print(result.output) + assert result.exit_code == 0 + assert db.cfgdb.get_entry('LOCAL_USERS_PASSWORDS_RESET', 'global')['state'] == 'enabled' + + result = runner.invoke(show.cli.commands['local-users-passwords-reset'], obj=db) + assert result.exit_code == 0 + assert 'enabled' in result.output + + result = runner.invoke(config.config.commands['local-users-passwords-reset'], ['disabled'], obj=db) + print(result.output) + assert result.exit_code == 0 + assert db.cfgdb.get_entry('LOCAL_USERS_PASSWORDS_RESET', 'global')['state'] == 'disabled' + + result = runner.invoke(show.cli.commands['local-users-passwords-reset'], obj=db) + assert result.exit_code == 0 + assert 'disabled' in result.output + + result = runner.invoke(config.config.commands['local-users-passwords-reset'], ['invalid-input'], obj=db) + print(result.output) + assert result.exit_code != 0