From 2bb8306d8e20d798f89535eff9ab57f6f5b2e177 Mon Sep 17 00:00:00 2001 From: suresh-rupanagudi <52159821+suresh-rupanagudi@users.noreply.github.com> Date: Thu, 18 Aug 2022 01:59:40 +0530 Subject: [PATCH] upstream snmp sonic-yang files (#10828) Fix #10549 Fix #10550 #### Why I did it Create sonic yang model for SNMP Tables:SNMP, SNMP_COMMUNITY #### How I did it Defined yang models based for SNMP based on snmp.yml #### How to verify it Added test cases to verify --- src/sonic-yang-models/setup.py | 2 + .../tests/files/sample_config_db.json | 20 ++++- .../tests/yang_model_tests/tests/snmp.json | 28 +++++++ .../yang_model_tests/tests_config/snmp.json | 83 +++++++++++++++++++ .../yang-models/sonic-snmp.yang | 74 +++++++++++++++++ 5 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests/snmp.json create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests_config/snmp.json create mode 100644 src/sonic-yang-models/yang-models/sonic-snmp.yang diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index 6e998737636e..ee4f7e55bca8 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -128,6 +128,7 @@ def run(self): './yang-models/sonic-route-map.yang', './yang-models/sonic-routing-policy-sets.yang', './yang-models/sonic-sflow.yang', + './yang-models/sonic-snmp.yang', './yang-models/sonic-syslog.yang', './yang-models/sonic-system-aaa.yang', './yang-models/sonic-system-tacacs.yang', @@ -190,6 +191,7 @@ def run(self): './cvlyang-models/sonic-route-map.yang', './cvlyang-models/sonic-routing-policy-sets.yang', './cvlyang-models/sonic-sflow.yang', + './cvlyang-models/sonic-snmp.yang', './cvlyang-models/sonic-system-aaa.yang', './cvlyang-models/sonic-system-tacacs.yang', './cvlyang-models/sonic-telemetry.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 332172d925c1..db7798f31835 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -1924,10 +1924,28 @@ ] } }, + + "SNMP": { + "CONTACT": { + "Contact": "testuser@contoso.com" + }, + "LOCATION": { + "Location": "SNMP Server Location" + } + }, + "SNMP_COMMUNITY": { + "public": { + "TYPE": "RO" + }, + "private": { + "TYPE": "RW" + } + }, + "SYSTEM_DEFAULTS": { "tunnel_qos_remap": { "status": "enabled" - } + } }, "LOSSLESS_TRAFFIC_PATTERN": { "AZURE": { diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/snmp.json b/src/sonic-yang-models/tests/yang_model_tests/tests/snmp.json new file mode 100644 index 000000000000..8c4754462830 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/snmp.json @@ -0,0 +1,28 @@ +{ + "SNMP_SYSTEM_TEST": { + "desc": "Load SNMP sysContact and sysLocation." + }, + "SNMP_SYSTEM_CONTACT_NEG_TEST": { + "desc": "Load SNMP sysContact with empty string", + "eStrKey": "Range" + }, + "SNMP_SYSTEM_LOCATION_NEG_TEST": { + "desc": "Load SNMP sysContact with empty string", + "eStrKey": "Range" + }, + "SNMP_COMMUNITY_TEST": { + "desc": "Load SNMP community string." + }, + "SNMP_COMMUNITY_MIN_NEG_TEST": { + "desc": "Load SNMP community string of length < 3.", + "eStrKey": "Range" + }, + "SNMP_COMMUNITY_MAX_NEG_TEST": { + "desc": "Load SNMP community string of lenth > 32.", + "eStrKey": "Range" + }, + "SNMP_COMMUNITY_WRONG_TYPE_TEST": { + "desc": "Load SNMP community string with un supported type.", + "eStrKey": "InvalidValue" + } +} diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/snmp.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/snmp.json new file mode 100644 index 000000000000..31c2f838d343 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/snmp.json @@ -0,0 +1,83 @@ +{ + "SNMP_SYSTEM_TEST": { + "sonic-snmp:sonic-snmp": { + "sonic-snmp:SNMP": { + "CONTACT": { + "Contact": "support@xyz.com" + }, + "LOCATION": { + "Location": "Test location" + } + } + } + }, + "SNMP_SYSTEM_CONTACT_NEG_TEST": { + "sonic-snmp:sonic-snmp": { + "sonic-snmp:SNMP": { + "CONTACT": { + "Contact": "" + } + } + } + }, + "SNMP_SYSTEM_LOCATION_NEG_TEST": { + "sonic-snmp:sonic-snmp": { + "sonic-snmp:SNMP": { + "LOCATION": { + "Location": "" + } + } + } + }, + + "SNMP_COMMUNITY_TEST": { + "sonic-snmp:sonic-snmp": { + "sonic-snmp:SNMP_COMMUNITY": { + "SNMP_COMMUNITY_LIST": [ + { + "name": "sonicSnmp", + "TYPE": "RO" + }, + { + "name": "sonicSnmpRW", + "TYPE": "RW" + } + ] + } + } + }, + "SNMP_COMMUNITY_MIN_NEG_TEST": { + "sonic-snmp:sonic-snmp": { + "sonic-snmp:SNMP_COMMUNITY": { + "SNMP_COMMUNITY_LIST": [ + { + "name": "abc" + } + ] + } + } + }, + "SNMP_COMMUNITY_MAX_NEG_TEST": { + "sonic-snmp:sonic-snmp": { + "sonic-snmp:SNMP_COMMUNITY": { + "SNMP_COMMUNITY_LIST": [ + { + "name": "01234567890123456789012345678901234" + } + ] + } + } + }, + "SNMP_COMMUNITY_WRONG_TYPE_TEST": { + "sonic-snmp:sonic-snmp": { + "sonic-snmp:SNMP_COMMUNITY": { + "SNMP_COMMUNITY_LIST": [ + { + "name": "sonicSnmp", + "TYPE": "RR" + } + ] + } + } + } +} diff --git a/src/sonic-yang-models/yang-models/sonic-snmp.yang b/src/sonic-yang-models/yang-models/sonic-snmp.yang new file mode 100644 index 000000000000..7e3db7b5dd09 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-snmp.yang @@ -0,0 +1,74 @@ +module sonic-snmp { + namespace "http://github.com/Azure/sonic-snmp"; + prefix ssnmp; + yang-version 1.1; + + + organization + "SONiC"; + + contact + "SONiC"; + + description + "SONIC SNMP"; + + revision 2022-05-13 { + description + "Initial revision."; + } + + + container sonic-snmp { + + container SNMP { + container CONTACT { + leaf Contact { + type string { + length "1..255"; + } + description + "SNMP System Contact."; + } + } + container LOCATION { + leaf Location { + type string { + length "1..255"; + } + description + "SNMP System Location."; + } + + } + } + + container SNMP_COMMUNITY { + list SNMP_COMMUNITY_LIST { + key name; + description + "List of communities."; + + leaf name { + type string { + length "4..32"; + pattern '[^ @,\\' +"']*" { + error-message 'Invalid snmp community string (Valid chars are ASCII printable except SPACE, single quote,"@", "," and "\")'; + } + } + description + "Index into the community list which must be the community name."; + } + + leaf TYPE { + type enumeration { + enum RO; + enum RW; + } + description + "Type of community, read-only or read-write."; + } + } + } + } +}