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 2, 2024
1 parent 099d40c commit 2c13573
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 2 deletions.
13 changes: 13 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7523,5 +7523,18 @@ def date(date, time):
clicommon.run_command(['timedatectl', 'set-time', date_time])


#
# 'local_users_passwords_reset' group ('config local-users-passwords-reset ...')
#
@config.command('local-users-passwords-reset')
@click.argument('state', metavar='<enabled|disabled>', required=True, type=click.Choice(['enabled', 'disabled']))
def state(state):
"""Set local-users-passwords-reset feature state"""

config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry('LOCAL_USERS_PASSWORDS_RESET', 'global', {'state': state})


if __name__ == '__main__':
config()
39 changes: 38 additions & 1 deletion doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,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 @@ -13309,3 +13311,38 @@ 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 state <enabled|disabled>
Usage: config config local-users-passwords-reset state <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 state
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 @@ -2157,6 +2157,26 @@ def suppress_pending_fib(db):
click.echo(state)


#
# 'local-users-passwords-reset' command group ("show local-users-passwords-reset ...")
#
@cli.group('local-users-passwords-reset', invoke_without_command=True)
@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, '').replace('\\n', '\n'))

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
26 changes: 25 additions & 1 deletion tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2741,4 +2741,28 @@ def teardown_class(cls):
from .mock_tables import dbconnector
from .mock_tables import mock_single_asic
importlib.reload(mock_single_asic)
dbconnector.load_database_config()
dbconnector.load_database_config()


class TestConfigLocalUsersPasswordsReset(object):
@classmethod
def setup_class(cls):
print('SETUP')
import config.main
importlib.reload(config.main)

@patch('utilities_common.cli.run_command',
mock.MagicMock(side_effect=mock_run_command_side_effect))
def test_local_users_passwords_reset_state(self):
runner = CliRunner()
obj = {'db': Db().cfgdb}

result = runner.invoke(
config.config.commands['local-users-passwords-reset'].commands['state'],
['enabled'], obj=obj)

assert result.exit_code == 0

@classmethod
def teardown_class(cls):
print('TEARDOWN')
6 changes: 6 additions & 0 deletions tests/show_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,12 @@ def test_rc_syslog(self, mock_rc):
assert result.exit_code == 0
assert '[1.1.1.1]' in result.output

@patch('show.main.run_command')
def test_show_local_users_passwords_reset(self, mock_run_command):
runner = CliRunner()
result = runner.invoke(show.cli.commands['local-users-passwords-reset'])
assert result.exit_code == 0

@classmethod
def teardown_class(cls):
print('TEARDOWN')

0 comments on commit 2c13573

Please sign in to comment.