Skip to content

Login messages config#1

Closed
fastiuk wants to merge 1 commit intomasterfrom
login-message-config
Closed

Login messages config#1
fastiuk wants to merge 1 commit intomasterfrom
login-message-config

Conversation

@fastiuk
Copy link
Owner

@fastiuk fastiuk commented Jul 29, 2022

This PR depends on fastiuk/sonic-buildimage#4

Why I did it

  • Add an ability to configure login messages: /etc/motd, /etc/issue*
  • Be able to use table defines from swsscommon

How to verify it

Build SONiC
or
When SONiC was already built:

rm -f target/python-wheels/bullseye/sonic_yang_models-1.0-py3-none-any.whl
BLDENV=bullseye make -f Makefile.work target/python-wheels/bullseye/sonic_yang_models-1.0-py3-none-any.whl
rm -f target/python-wheels/bullseye/sonic_host_services-1.0-py3-none-any.whl
BLDENV=bullseye make -f Makefile.work target/python-wheels/bullseye/sonic_host_services-1.0-py3-none-any.whl

Login into the switch.
Set messages:

redis-cli -n 4 HSET "LOGIN_MESSAGE|pre_login" "message" "Test pre login"
redis-cli -n 4 HSET "LOGIN_MESSAGE|post_login" "message" "Test post login"

Logout/login and see the results:
Screenshot 2022-07-02 at 22 58 11
Clear messages:

redis-cli -n 4 HSET "LOGIN_MESSAGE|pre_login" "message" ""
redis-cli -n 4 HSET "LOGIN_MESSAGE|post_login" "message" ""

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111

Description for the changelog

  • Add an ability to configure pre-login and post-login messages: /etc/motd, /etc/issue*

Link to config_db schema for YANG module changes

sonic-login_message.yang

Superproject PR:

PR title State
Login messages config GitHub issue/pull request detail

A picture of a cute animal

1-46

@fastiuk fastiuk force-pushed the login-message-config branch from da4a086 to f16caec Compare July 29, 2022 20:07
* Handle pre-login message.
* Handle post-login message.

Signed-off-by: Yevhen Fastiuk <[email protected]>
@fastiuk
Copy link
Owner Author

fastiuk commented Aug 16, 2022

@stepanblyschak please review

Comment on lines +1276 to +1279
self.cache['pre-login'] = login_msgs.get('pre-login',{}
).get('message', '')
self.cache['post-login'] = login_msgs.get('post-login', {}
).get('message', '')

Choose a reason for hiding this comment

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

Suggested change
self.cache['pre-login'] = login_msgs.get('pre-login',{}
).get('message', '')
self.cache['post-login'] = login_msgs.get('post-login', {}
).get('message', '')
self.cache['pre-login'] = login_msgs.get('pre-login', {}).get('message', '')
self.cache['post-login'] = login_msgs.get('post-login', {}).get('message', '')

Copy link
Owner Author

Choose a reason for hiding this comment

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

The total line width will exceed 80 chars. Which will break python code style

Choose a reason for hiding this comment

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

There are lines longer then 80 chars in this file. We don't follow that guideline and a newline in the middle hurts readability.

login_msgs = self.config_db.get_table(
swsscommon.CFG_LOGIN_MESSAGE_TABLE_NAME)
for key in login_msgs:
self.loginmsgcfg.set_login_message(key, login_msgs[key])

Choose a reason for hiding this comment

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

load will save configuration into the cache, so this call to set_login_message will not set anything because it is the same as in the cache?

Comment on lines +1294 to +1297
msg = None if not isinstance(data, dict) else data.get('message')
if type(msg) != str:
# Nothing to handle
return

Choose a reason for hiding this comment

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

Suggested change
msg = None if not isinstance(data, dict) else data.get('message')
if type(msg) != str:
# Nothing to handle
return
msg = data.get('message')
if not msg:
# Nothing to handle
return

if key == 'pre_login':
# Write pre-login to /etc/issue file
run_cmd(self.cmds.login_message_pre.format(not_newline, msg),
True, True)

Choose a reason for hiding this comment

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

add log_err and raise_exception as you do on next lines for readability


class LoginCfg(object):
"""
LoginCfg Config Daemon

Choose a reason for hiding this comment

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

The Daemon word confuses since it is not a deamon

"modify pam_limits config file failed with exception: {}"
.format(e))

class LoginCfg(object):

Choose a reason for hiding this comment

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

No need in python3:

Suggested change
class LoginCfg(object):
class LoginCfg:

Comment on lines +1260 to +1261
Handles changes in LOGIN_MESSAGE table.
1) Handle change for pre-login and post-login messages.

Choose a reason for hiding this comment

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

Suggested change
Handles changes in LOGIN_MESSAGE table.
1) Handle change for pre-login and post-login messages.
Handles changes in LOGIN_MESSAGE table for pre-login and post-login messages.

Comment on lines +1287 to +1291
cache: Cache to compare/save data.
db: DB instance.
table: DB table that was changed.
key: DB table's key that was triggered change.
data: Read table data.

Choose a reason for hiding this comment

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

Suggested change
cache: Cache to compare/save data.
db: DB instance.
table: DB table that was changed.
key: DB table's key that was triggered change.
data: Read table data.
key: DB table's key that was triggered change.
data: Read table data.

@stepanblyschak
Copy link

Requires UT

fastiuk pushed a commit that referenced this pull request Mar 22, 2023
Signed-off-by: Gang Lv [email protected]

Why I did it
GNMI needs to use host service to invoke generic_config_updater and config reload.

How I did it
Add host_modules for generic_config_updater and config reload.
Add unit test for host modules.

How to verify it
Run unit test for sonic-host-services.
@fastiuk fastiuk closed this May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants