From 6bed69af6d7c6e649709c493c83edd82d4f6fbba Mon Sep 17 00:00:00 2001 From: EdenGri <63317673+EdenGri@users.noreply.github.com> Date: Mon, 31 Oct 2022 10:42:12 +0200 Subject: [PATCH] Add a yang model for the new "Logger" table in the CONFIG DB (#12067) - Why I did it Add the ability to the user to save the loglevel and make it persistent to reboot. - How I did it Move the logger tables from the LOGLEVEL DB to the CONFIG DB. Add new yang model to verify the new config schema. - How to verify it 1. change the orchagent loglevel (for example) -> swssloglevel -c orchagent -l DEBUG 2. save the loglevel -> run config save 3. reboot 4. verify that the orchagent log level is still DEBUG ->run run redis-cli -n 4 hgetall "LOGGER|orchagent" --- src/sonic-yang-models/doc/Configuration.md | 29 ++++++++ src/sonic-yang-models/setup.py | 2 + .../tests/files/sample_config_db.json | 14 ++++ .../tests/yang_model_tests/tests/logger.json | 18 +++++ .../yang_model_tests/tests_config/logger.json | 55 ++++++++++++++ .../yang-models/sonic-logger.yang | 73 +++++++++++++++++++ 6 files changed, 191 insertions(+) create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests/logger.json create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests_config/logger.json create mode 100644 src/sonic-yang-models/yang-models/sonic-logger.yang diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md index d09e2c8bac0b..ba51e8e1aa1b 100644 --- a/src/sonic-yang-models/doc/Configuration.md +++ b/src/sonic-yang-models/doc/Configuration.md @@ -58,6 +58,7 @@ Table of Contents * [VOQ Inband Interface](#voq-inband-interface) * [VXLAN](#vxlan) * [Virtual router](#virtual-router) + * [LOGGER](#logger) * [WRED_PROFILE](#wred_profile) * [PASSWORD_HARDENING](#password_hardening) * [SYSTEM_DEFAULTS table](#systemdefaults-table) @@ -1705,6 +1706,34 @@ The packet action could be: } } ``` + +### Logger + +In this table, the loglevel and logoutput of the components are defined. Each component +will have the component name as its key; and LOGLEVEL and LOGOUTPUT as attributes. +The LOGLEVEL attribute will define the verbosity of the component. +The LOGOUTPUT attribute will define the file of printing the logs. + +``` +{ + "LOGGER": { + "orchagent": { + "LOGLEVEL": "NOTICE", + "LOGOUTPUT": "SYSLOG" + }, + "syncd": { + "LOGLEVEL": "DEBUG", + "LOGOUTPUT": "STDOUT" + }, + "SAI_API_LAG": { + "LOGLEVEL": "ERROR", + "LOGOUTPUT": "STDERR" + } + } +} + +``` + ### PASSWORD_HARDENING Password Hardening, a user password is the key credential used in order to verify the user accessing the switch and acts as the first line of defense in regards to securing the switch. PASSWORD_HARDENING - support the enforce strong policies. diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index 11756fe01614..8c318e583fa0 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -169,6 +169,7 @@ def run(self): './yang-models/sonic-peer-switch.yang', './yang-models/sonic-pfc-priority-queue-map.yang', './yang-models/sonic-pfc-priority-priority-group-map.yang', + './yang-models/sonic-logger.yang', './yang-models/sonic-port-qos-map.yang', './yang-models/sonic-static-route.yang', './yang-models/sonic-macsec.yang']), @@ -234,6 +235,7 @@ def run(self): './cvlyang-models/sonic-tc-queue-map.yang', './cvlyang-models/sonic-pfc-priority-queue-map.yang', './cvlyang-models/sonic-pfc-priority-priority-group-map.yang', + './cvlyang-models/sonic-logger.yang', './cvlyang-models/sonic-port-qos-map.yang', './cvlyang-models/sonic-static-route.yang', './cvlyang-models/sonic-macsec.yang']), diff --git a/src/sonic-yang-models/tests/files/sample_config_db.json b/src/sonic-yang-models/tests/files/sample_config_db.json index ecb0be1c4ce8..ab4aae47a1d9 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -837,6 +837,20 @@ "tpid": "0x8100" } }, + "LOGGER": { + "orchagent": { + "LOGLEVEL": "NOTICE", + "LOGOUTPUT": "SYSLOG" + }, + "syncd": { + "LOGLEVEL": "NOTICE", + "LOGOUTPUT": "SYSLOG" + }, + "SAI_API_LAG": { + "LOGLEVEL": "SAI_LOG_LEVEL_NOTICE", + "LOGOUTPUT": "SYSLOG" + } + }, "ACL_TABLE": { "V4-ACL-TABLE": { "type": "L3", diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/logger.json b/src/sonic-yang-models/tests/yang_model_tests/tests/logger.json new file mode 100644 index 000000000000..523755afd40b --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/logger.json @@ -0,0 +1,18 @@ +{ + "LOGGER_CORRECT_LOGLEVEL_AND_LOGOUTPUT": { + "desc": "LOGGER_CORRECT_LOGLEVEL_AND_LOGOUTPUT_1 no failure." + }, + "LOGGER_WRONG_LOGLEVEL": { + "desc": "LOGGER_WRONG_LOGLEVEL pattern failure.", + "eStr": ["wrong", "LOGLEVEL"] + }, + "LOGGER_WRONG_LOGOUTPUT": { + "desc": "LOGGER_WRONG_LOGOUTPUT pattern failure.", + "eStr": ["wrong", "LOGOUTPUT"] + }, + "LOGGER_MANDATORY_LOGLEVEL": { + "desc": "LOGGER_MANDATORY_LOGOUTPUT no logoutput.", + "estr": ["LOGLEVEL"], + "eStrKey": "Mandatory" + } +} diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/logger.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/logger.json new file mode 100644 index 000000000000..8ee308c8485f --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/logger.json @@ -0,0 +1,55 @@ +{ + "LOGGER_CORRECT_LOGLEVEL_AND_LOGOUTPUT": { + "sonic-logger:sonic-logger": { + "sonic-logger:LOGGER": { + "LOGGER_LIST": [{ + "name": "orchagent", + "LOGLEVEL": "NOTICE", + "LOGOUTPUT": "SYSLOG" + }, + { + "name": "syncd", + "LOGLEVEL": "DEBUG", + "LOGOUTPUT": "STDOUT" + }, + { + "name": "SAI_API_LAG", + "LOGLEVEL": "SAI_LOG_LEVEL_ERROR", + "LOGOUTPUT": "STDERR" + }] + } + } + }, + "LOGGER_WRONG_LOGLEVEL": { + "sonic-logger:sonic-logger": { + "sonic-logger:LOGGER": { + "LOGGER_LIST": [{ + "name": "orchagent", + "LOGLEVEL": "wrong", + "LOGOUTPUT": "SYSLOG" + }] + } + } + }, + "LOGGER_WRONG_LOGOUTPUT": { + "sonic-logger:sonic-logger": { + "sonic-logger:LOGGER": { + "LOGGER_LIST": [{ + "name": "orchagent", + "LOGLEVEL": "NOTICE", + "LOGOUTPUT": "wrong" + }] + } + } + }, + "LOGGER_MANDATORY_LOGLEVEL": { + "sonic-logger:sonic-logger": { + "sonic-logger:LOGGER": { + "LOGGER_LIST": [{ + "name": "orchagent", + "LOGOUTPUT": "SYSLOG" + }] + } + } + } +} diff --git a/src/sonic-yang-models/yang-models/sonic-logger.yang b/src/sonic-yang-models/yang-models/sonic-logger.yang new file mode 100644 index 000000000000..f9a89bda49e8 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-logger.yang @@ -0,0 +1,73 @@ +module sonic-logger{ + + yang-version 1.1; + + namespace "http://github.com/Azure/sonic-logger"; + prefix logger; + + import sonic-types { + prefix stypes; + } + + description "Logger Table yang Module for SONiC"; + + typedef swss_loglevel { + type enumeration { + enum EMERG; + enum ALERT; + enum CRIT; + enum ERROR; + enum WARN; + enum NOTICE; + enum INFO; + enum DEBUG; + } + } + + typedef sai_loglevel { + type enumeration { + enum SAI_LOG_LEVEL_CRITICAL; + enum SAI_LOG_LEVEL_ERROR; + enum SAI_LOG_LEVEL_WARN; + enum SAI_LOG_LEVEL_NOTICE; + enum SAI_LOG_LEVEL_INFO; + enum SAI_LOG_LEVEL_DEBUG; + } + } + + container sonic-logger { + + container LOGGER { + + description "Logger table in config_db.json"; + + list LOGGER_LIST { + + key "name"; + + leaf name { + description "Component name in LOGGER table (example for component: orchagent, Syncd, SAI components)."; + type string; + } + + leaf LOGLEVEL { + description "The log verbosity for the component"; + mandatory true; + type union { + type swss_loglevel; + type sai_loglevel; + } + } + + leaf LOGOUTPUT { + type enumeration { + enum SYSLOG; + enum STDOUT; + enum STDERR; + } + default SYSLOG; + } + }/* end of list LOGGER_LIST */ + }/* end of LOGGER container */ + }/* end of sonic-logger container */ +}/* end of sonic-logger module */