Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CLI commands to configure Local Users' Passwords Reset feature #3302

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add config db json for test as well? https://github.com/sonic-net/sonic-utilities/tree/master/tests

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
Loading