From ab0ee0bfae5354adbf36f6fac0144883a5222037 Mon Sep 17 00:00:00 2001 From: Praveen Chaudhary Date: Thu, 24 Dec 2020 01:48:41 -0800 Subject: [PATCH] [yang-models]: Default value for leaf-lists and tests. (#6029) Changes: -- Add Default value for leaf-lists in ACL and portchannel. -- Remove members in VLAN. -- Test modifications. Signed-off-by: Praveen Chaudhary --- .../tests/yang_model_tests/test_yang_model.py | 10 +- .../tests/yang_model_tests/yangTest.json | 97 ++++++++++--------- .../yang-models/sonic-acl.yang | 10 +- .../yang-models/sonic-portchannel.yang | 14 ++- .../yang-models/sonic-vlan.yang | 8 -- 5 files changed, 79 insertions(+), 60 deletions(-) diff --git a/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py b/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py index 3bc2886f38..7579bdcfa8 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py +++ b/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py @@ -129,6 +129,10 @@ class Test_yang_models: 'desc': 'CRM BREAKOUT CFG FLEX COUNTER TABLE.', 'eStr': self.defaultYANGFailure['None'] }, + 'DEV_META_DEV_NEIGH_VERSION_TABLE': { + 'desc': 'DEVICE_METADATA DEVICE_NEIGHBOR VERSION TABLE.', + 'eStr': self.defaultYANGFailure['None'] + }, 'INCORRECT_VLAN_NAME': { 'desc': 'INCORRECT VLAN_NAME FIELD IN VLAN TABLE.', 'eStr': self.defaultYANGFailure['Pattern'] + ["Vlan"] @@ -180,8 +184,7 @@ class Test_yang_models: 'CRM_WITH_HIGH_THRESHOLD_ERR': { 'desc': 'CRM_WITH_HIGH_THRESHOLD_ERR must condition failure \ about high threshold being lower than low threshold.', - 'eStr': self.defaultYANGFailure['high_threshold should be more \ - than low_threshold'] + 'eStr': ['high_threshold should be more than low_threshold'] }, 'CRM_WITH_CORRECT_USED_VALUE': { 'desc': 'CRM_WITH_CORRECT_USED_VALUE no failure.', @@ -390,6 +393,8 @@ class Test_yang_models: try: self.initTest() self.loadYangModel(self.yangDir) + assert len(self.tests) != 0 + print("Tests:{}".format(self.tests)) for test in self.tests: test = test.strip() if test in self.ExceptionTests: @@ -399,6 +404,7 @@ class Test_yang_models: else: raise Exception("Unexpected Test") except Exception as e: + ret = FAIL * len(self.tests) printExceptionDetails() assert ret == 0 diff --git a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json index 527b528332..d898582605 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json +++ b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json @@ -728,6 +728,54 @@ } }, + "DEV_META_DEV_NEIGH_VERSION_TABLE": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "localhost": { + "bgp_asn": "64850", + "mac": "00:11:22:33:44:55", + "hostname": "asw.dc", + "type": "ToRRouter", + "docker_routing_config_mode": "separated", + "hwsku": "Stone" + } + } + }, + "sonic-device_neighbor:sonic-device_neighbor": { + "sonic-device_neighbor:DEVICE_NEIGHBOR": { + "DEVICE_NEIGHBOR_LIST": [ + { + "port": "Eth18", + "name": "dccsw03.nw", + "peer_name": "Ethernet116" + }, + { + "port": "Eth18", + "name": "dccsw02.nw", + "peer_name": "Ethernet114" + }, + { + "port": "Eth18", + "name": "dccsw01.nw", + "peer_name": "Ethernet112" + }, + { + "port": "Eth18", + "name": "dccsw04.nw", + "peer_name": "Ethernet118" + } + ] + } + }, + "sonic-versions:sonic-versions": { + "sonic-versions:VERSIONS": { + "DATABASE": { + "VERSION": "version_2_10_31" + } + } + } + }, + "CRM_WITH_WRONG_PERCENTAGE": { "sonic-crm:sonic-crm": { "sonic-crm:CRM": { @@ -1189,44 +1237,7 @@ ], "vlanid": "111", "mtu": "9216", - "admin_status": "up", - "members": [ - "Ethernet8", - "Ethernet3", - "Ethernet0", - "Ethernet1", - "Ethernet6", - "Ethernet4", - "Ethernet5", - "Ethernet9", - "Ethernet2", - "Ethernet7", - "Ethernet32", - "Ethernet30", - "Ethernet31", - "Ethernet36", - "Ethernet34", - "Ethernet33", - "Ethernet35", - "Ethernet29", - "Ethernet21", - "Ethernet20", - "Ethernet23", - "Ethernet22", - "Ethernet27", - "Ethernet26", - "Ethernet18", - "Ethernet19", - "Ethernet14", - "Ethernet15", - "Ethernet16", - "Ethernet17", - "Ethernet10", - "Ethernet11", - "Ethernet12", - "Ethernet13", - "Ethernet28" - ] + "admin_status": "up" }, "Vlan777": { "description": "pvlan", @@ -1235,15 +1246,7 @@ ], "vlanid": "777", "mtu": "9216", - "admin_status": "up", - "members": [ - "Ethernet9", - "Ethernet2", - "Ethernet8", - "Ethernet27", - "Ethernet14", - "Ethernet35" - ] + "admin_status": "up" } }, "DEVICE_NEIGHBOR": { diff --git a/src/sonic-yang-models/yang-models/sonic-acl.yang b/src/sonic-yang-models/yang-models/sonic-acl.yang index 3ac0abe807..fc2515d0b5 100644 --- a/src/sonic-yang-models/yang-models/sonic-acl.yang +++ b/src/sonic-yang-models/yang-models/sonic-acl.yang @@ -264,7 +264,7 @@ module sonic-acl { } leaf-list ports { - /* union of leafref is allowed in YANG 1.1 */ + /* union of leafref is allowed in YANG 1.1 */ type union { type leafref { path /port:sonic-port/port:PORT/port:PORT_LIST/port:port_name; @@ -272,7 +272,15 @@ module sonic-acl { type leafref { path /lag:sonic-portchannel/lag:PORTCHANNEL/lag:PORTCHANNEL_LIST/lag:portchannel_name; } + type string { + pattern ""; + } } + /* Today in SONiC, we do not delete the list once + * created, instead we set to empty list. Due to that + * below default values are needed. + */ + default ""; } } /* end of ACL_TABLE_LIST */ diff --git a/src/sonic-yang-models/yang-models/sonic-portchannel.yang b/src/sonic-yang-models/yang-models/sonic-portchannel.yang index 69c8fa6ac1..8303cec2d9 100644 --- a/src/sonic-yang-models/yang-models/sonic-portchannel.yang +++ b/src/sonic-yang-models/yang-models/sonic-portchannel.yang @@ -48,9 +48,19 @@ module sonic-portchannel { leaf-list members { /* leaf-list members are unique by default */ - type leafref { - path /port:sonic-port/port:PORT/port:PORT_LIST/port:port_name; + type union { + type leafref { + path /port:sonic-port/port:PORT/port:PORT_LIST/port:port_name; + } + type string { + pattern ""; + } } + /* Today in SONiC, we do not delete the list once + * created, instead we set to empty list. Due to that + * below default values are needed. + */ + default ""; } leaf min_links { diff --git a/src/sonic-yang-models/yang-models/sonic-vlan.yang b/src/sonic-yang-models/yang-models/sonic-vlan.yang index d00e68b390..f7ac7c9d61 100644 --- a/src/sonic-yang-models/yang-models/sonic-vlan.yang +++ b/src/sonic-yang-models/yang-models/sonic-vlan.yang @@ -155,14 +155,6 @@ module sonic-vlan { leaf admin_status { type stypes:admin_status; } - - leaf-list members { - /* leaf-list members are unique by default */ - - type leafref { - path "/port:sonic-port/port:PORT/port:PORT_LIST/port:port_name"; - } - } } /* end of VLAN_LIST */ }