-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Banner] Add new feature including config, yang and tests (#16957)
- Why I did it Added Banner feature related services according to HLD: sonic-net/SONiC#1361 - How I did it Added banner-config systemd service, YANG model for new ConfDB table and YANG model tests - How to verify it Manual test Co-authored-by: Sviatoslav Boichuk <[email protected]>
- Loading branch information
1 parent
b0f5398
commit 0b8b503
Showing
11 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[Unit] | ||
Description=Update banner config based on configdb | ||
Requires=config-setup.service | ||
After=config-setup.service | ||
Before=systemd-logind.service sshd.service | ||
BindsTo=database.service | ||
BindsTo=sonic.target | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=no | ||
ExecStart=/usr/bin/banner-config.sh | ||
|
||
[Install] | ||
WantedBy=sonic.target | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash -e | ||
|
||
STATE=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["state"]') | ||
LOGIN= | ||
MOTD= | ||
LOGOUT= | ||
|
||
if [[ $STATE == "enabled" ]]; then | ||
LOGIN=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["login"]') | ||
MOTD=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["motd"]') | ||
LOGOUT=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["logout"]') | ||
|
||
echo -e "$LOGIN" > /etc/issue.net | ||
echo -e "$LOGIN" > /etc/issue | ||
echo -e "$MOTD" > /etc/motd | ||
echo -e "$LOGOUT" > /etc/logout_message | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
LOGOUT_MESSAGE_PATH="/etc/logout_message" | ||
LOGOUT_MESSAGE= | ||
|
||
if [[ -f "$LOGOUT_MESSAGE_PATH" ]]; then | ||
LOGOUT_MESSAGE=$(cat $LOGOUT_MESSAGE_PATH) | ||
fi | ||
|
||
if [[ -n "$LOGOUT_MESSAGE" ]]; then | ||
# Print logout message | ||
echo $LOGOUT_MESSAGE | ||
fi | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/sonic-yang-models/tests/yang_model_tests/tests/sonic-banner.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"BANNER_MESSAGE_TEST_STATE": { | ||
"desc": "Configure Banner feature state." | ||
}, | ||
"BANNER_MESSAGE_TEST_LOGIN" : { | ||
"desc": "Banner login messages configuration in BANNER_MESSAGE table." | ||
}, | ||
"BANNER_MESSAGE_TEST_MOTD" : { | ||
"desc": "Banner MOTD messages configuration in BANNER_MESSAGE table." | ||
}, | ||
"BANNER_MESSAGE_TEST_LOGOUT" : { | ||
"desc": "Banner logout messages configuration in BANNER_MESSAGE table." | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/sonic-yang-models/tests/yang_model_tests/tests_config/sonic-banner.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"BANNER_MESSAGE_TEST_STATE": { | ||
"sonic-banner:sonic-banner": { | ||
"sonic-banner:BANNER_MESSAGE": { | ||
"global": { | ||
"state": "enabled", | ||
"login": "Some login message", | ||
"motd": "Some message of the day", | ||
"logout": "Some logout message" | ||
} | ||
} | ||
} | ||
}, | ||
"BANNER_MESSAGE_TEST_LOGIN": { | ||
"sonic-banner:sonic-banner": { | ||
"sonic-banner:BANNER_MESSAGE": { | ||
"global": { | ||
"state": "enabled", | ||
"login": "Some login message", | ||
"motd": "Some message of the day", | ||
"logout": "Some logout message" | ||
} | ||
} | ||
} | ||
}, | ||
"BANNER_MESSAGE_TEST_MOTD": { | ||
"sonic-banner:sonic-banner": { | ||
"sonic-banner:BANNER_MESSAGE": { | ||
"global": { | ||
"state": "enabled", | ||
"login": "Some login message", | ||
"motd": "Some message of the day", | ||
"logout": "Some logout message" | ||
} | ||
} | ||
} | ||
}, | ||
"BANNER_MESSAGE_TEST_LOGOUT": { | ||
"sonic-banner:sonic-banner": { | ||
"sonic-banner:BANNER_MESSAGE": { | ||
"global": { | ||
"state": "enabled", | ||
"login": "Some login message", | ||
"motd": "Some message of the day", | ||
"logout": "Some logout message" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module sonic-banner { | ||
yang-version 1.1; | ||
namespace "http://github.com/sonic-net/sonic-banner"; | ||
prefix banner_message; | ||
|
||
import sonic-types { | ||
prefix stypes; | ||
} | ||
|
||
description "BANNER_MESSAGE YANG Module for SONiC-based OS"; | ||
revision 2023-05-18 { | ||
description "First Revision"; | ||
} | ||
container sonic-banner { | ||
container BANNER_MESSAGE { | ||
description "BANNER_MESSAGE part of config_db.json"; | ||
container global { | ||
leaf state { | ||
type stypes:admin_mode; | ||
description "Banner feature state"; | ||
default disabled; | ||
} | ||
leaf login { | ||
type string; | ||
description "Banner message displayed to user before login prompt"; | ||
default "Debian GNU/Linux 11"; | ||
} | ||
leaf motd { | ||
type string; | ||
description "Banner message displayed to user after login prompt"; | ||
default "You are on | ||
____ ___ _ _ _ ____ | ||
/ ___| / _ \\| \\ | (_)/ ___| | ||
\\___ \\| | | | \\| | | | | ||
___) | |_| | |\\ | | |___ | ||
|____/ \\___/|_| \\_|_|\\____| | ||
-- Software for Open Networking in the Cloud -- | ||
Unauthorized access and/or use are prohibited. | ||
All access and/or use are subject to monitoring. | ||
Help: https://sonic-net.github.io/SONiC/ | ||
"; | ||
} | ||
leaf logout { | ||
type string; | ||
description "Banner message dispalyed to the users on logout"; | ||
default ""; | ||
} | ||
} /* end of container MESSAGE */ | ||
} /* end of container BANNER_MESSAGE */ | ||
} /* end of top level container */ | ||
} |