Skip to content

Commit

Permalink
Added CLI commands to configure Local Users' Passwords Reset feature …
Browse files Browse the repository at this point in the history
…and display current configuration
  • Loading branch information
azmyali98 committed May 16, 2024
1 parent 61d0ec9 commit 1d84e34
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
13 changes: 13 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7667,5 +7667,18 @@ def notice(db, category_list, max_events, namespace):
handle_asic_sdk_health_suppress(db, 'notice', 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='<enabled|disabled>', 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})


if __name__ == '__main__':
config()
40 changes: 39 additions & 1 deletion doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,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)
## Document History

| Version | Modification Date | Details |
Expand Down Expand Up @@ -13587,3 +13589,39 @@ 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 <enabled|disabled>
Usage: config config local-users-passwords-reset <enabled|disabled>
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
```
20 changes: 20 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,26 @@ def received(db, namespace):
ctx.fail("ASIC/SDK health event is not supported on the platform")


#
# '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=''))


# Load plugins and register them
helper = util_base.UtilHelper()
helper.load_and_register_plugins(plugins, cli)
Expand Down
34 changes: 34 additions & 0 deletions tests/local_users_passwords_reset_test.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1d84e34

Please sign in to comment.