From 8e6b194b17dba970f762132717135ee6d0ce73fb Mon Sep 17 00:00:00 2001 From: Lawrence Lee Date: Mon, 10 Jan 2022 12:24:51 -0800 Subject: [PATCH] [YANG]: Add support for dual ToR attributes (#9698) Fixes #9561 Fixes #9570 Fixes #9563 Partial fix for #9556 #### Why I did it - Attributes for dual ToR configs lack YANG model support #### How I did it - Extend YANG tests to cover dual ToR use cases - Extend YANG model to cover dual ToR use cases - Reduce the default log level to warning so only test failures are printed #### How to verify it - Run the YANG model unit tests --- .../tests/device_metadata.json | 23 ++++- .../tests/yang_model_tests/tests/port.json | 7 ++ .../tests/yang_model_tests/tests/vlan.json | 18 ++++ .../tests_config/device_metadata.json | 54 +++++++++++ .../yang_model_tests/tests_config/port.json | 39 ++++++++ .../yang_model_tests/tests_config/vlan.json | 92 ++++++++++++++++++- .../yang-models/sonic-device_metadata.yang | 18 +++- .../yang-models/sonic-port.yang | 4 + .../yang-models/sonic-vlan.yang | 20 ++++ .../yang-templates/sonic-types.yang.j2 | 7 +- 10 files changed, 276 insertions(+), 6 deletions(-) diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/device_metadata.json b/src/sonic-yang-models/tests/yang_model_tests/tests/device_metadata.json index 62ebf55b68..070495b8df 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/device_metadata.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/device_metadata.json @@ -60,6 +60,27 @@ }, "DEVICE_METADATA_CORRECT_CLOUDTYPE_REGION_CONFIG": { "desc": "Verifying cloudtype and region configuration." - } + }, + "DEVICE_METADATA_VALID_SUBTYPE": { + "desc": "Verifying valid subtype value" + }, + "DEVICE_METADATA_INVALID_SUBTYPE": { + "desc": "Verifying invalid subtype value", + "eStrKey": "Pattern" + }, + "DEVICE_METADATA_VALID_PEER_SWITCH": { + "desc": "Verifying valid peer switch hostname" + }, + "DEVICE_METADATA_INVALID_PEER_SWITCH": { + "desc": "Verifying test fails with hostname that is too long", + "eStrKey": "Range" + }, + "DEVICE_METADATA_VALID_STORAGE_DEVICE": { + "desc": "Verifying valid storage device value" + }, + "DEVICE_METADATA_INVALID_STORAGE_DEVICE": { + "desc": "Verifying invalid storage device value", + "eStrKey": "InvalidValue" + } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/port.json b/src/sonic-yang-models/tests/yang_model_tests/tests/port.json index 174dcc4de7..f936d7a0b8 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/port.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/port.json @@ -66,5 +66,12 @@ "desc": "PORT_INVALID_TPID_TEST invalid tpid value failure.", "eStrKey" : "Pattern", "eStr": ["0x8100|0x9100|0x9200|0x88a8|0x88A8"] + }, + "PORT_VALID_MUX_CABLE_TEST": { + "desc": "PORT_VALID_MUX_CABLE_TEST no failure." + }, + "PORT_INVALID_MUX_CABLE_TEST": { + "desc": "PORT_INVALID_MUX_CABLE_TEST non-boolean values, expect fail", + "eStrKey": "InvalidValue" } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/vlan.json b/src/sonic-yang-models/tests/yang_model_tests/tests/vlan.json index 7f898d297c..a872784ff2 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/vlan.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/vlan.json @@ -56,5 +56,23 @@ }, "DHCPV6_SERVER_VALID_FORMAT": { "desc": "Add dhcpv6_server in correct format." + }, + "INVALID_VLAN_MAC": { + "desc": "VLAN with invalid MAC address", + "eStrKey": "Pattern" + }, + "VLAN_INTERFACE_VALID_GRAT_ARP": { + "desc": "VLAN_INTERFACE with valid grat_arp value" + }, + "VLAN_INTERFACE_VALID_PROXY_ARP": { + "desc": "VLAN_INTERFACE with valid proxy_arp value" + }, + "VLAN_INTERFACE_INVALID_GRAT_ARP": { + "desc": "VLAN_INTERFACE with invalid grat_arp value", + "eStrKey": "Pattern" + }, + "VLAN_INTERFACE_INVALID_PROXY_ARP": { + "desc": "VLAN_INTERFACE with invalid proxy_arp value", + "eStrKey": "Pattern" } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/device_metadata.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/device_metadata.json index 545b343376..950d9d874c 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/device_metadata.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/device_metadata.json @@ -159,5 +159,59 @@ } } } + }, + "DEVICE_METADATA_VALID_SUBTYPE": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "sonic-device_metadata:localhost": { + "subtype": "DualToR" + } + } + } + }, + "DEVICE_METADATA_INVALID_SUBTYPE": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "sonic-device_metadata:localhost": { + "subtype": "FakeSubtype" + } + } + } + }, + "DEVICE_METADATA_VALID_PEER_SWITCH": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "sonic-device_metadata:localhost": { + "peer_switch": "peer_01_hostname" + } + } + } + }, + "DEVICE_METADATA_INVALID_PEER_SWITCH": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "sonic-device_metadata:localhost": { + "peer_switch": "this_super_duper_long_hostname_is_too_long_according_to_RFC_1035" + } + } + } + }, + "DEVICE_METADATA_VALID_STORAGE_DEVICE": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "sonic-device_metadata:localhost": { + "storage_device": "true" + } + } + } + }, + "DEVICE_METADATA_INVALID_STORAGE_DEVICE": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "sonic-device_metadata:localhost": { + "storage_device": "yes" + } + } + } } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/port.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/port.json index 7423ecd6d4..5d7fff2cd8 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/port.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/port.json @@ -275,5 +275,44 @@ ] } } + }, + + "PORT_VALID_MUX_CABLE_TEST": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet8", + "alias": "eth8", + "lanes": "65", + "speed": 50000, + "mux_cable": "true" + }, + { + "name": "Ethernet12", + "alias": "eth12", + "lanes": "6", + "speed": 50000, + "mux_cable": "false" + } + ] + } + } + }, + + "PORT_INVALID_MUX_CABLE_TEST": { + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet8", + "alias": "eth8", + "lanes": "65", + "speed": 50000, + "mux_cable": "enabled" + } + ] + } + } } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/vlan.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/vlan.json index 9f6bdd8b3a..2ae87a7b82 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/vlan.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/vlan.json @@ -21,7 +21,8 @@ "10.186.72.66" ], "mtu": "9100", - "name": "Vlan200" + "name": "Vlan200", + "mac": "00:aa:bb:cc:dd:ee" } ] } @@ -524,5 +525,94 @@ ] } } + }, + "INVALID_VLAN_MAC": { + "sonic-vlan:sonic-vlan": { + "sonic-vlan:VLAN": { + "VLAN_LIST": [ + { + "admin_status": "up", + "name": "Vlan1000", + "mac": "12345678" + } + ] + } + } + }, + "VLAN_INTERFACE_VALID_GRAT_ARP": { + "sonic-vlan:sonic-vlan": { + "sonic-vlan:VLAN": { + "VLAN_LIST": [ + { + "name": "Vlan1000" + }, + { + "name": "Vlan2000" + } + ] + }, + "sonic-vlan:VLAN_INTERFACE": { + "VLAN_INTERFACE_LIST": [ + { + "name": "Vlan1000", + "grat_arp": "enabled" + }, + { + "name": "Vlan2000", + "grat_arp": "disabled" + } + ] + } + } + }, + "VLAN_INTERFACE_VALID_PROXY_ARP": { + "sonic-vlan:sonic-vlan": { + "sonic-vlan:VLAN": { + "VLAN_LIST": [ + { + "name": "Vlan1000" + }, + { + "name": "Vlan2000" + } + ] + }, + "sonic-vlan:VLAN_INTERFACE": { + "VLAN_INTERFACE_LIST": [ + { + "name": "Vlan1000", + "proxy_arp": "enabled" + }, + { + "name": "Vlan2000", + "proxy_arp": "disabled" + } + ] + } + } + }, + "VLAN_INTERFACE_INVALID_GRAT_ARP": { + "sonic-vlan:sonic-vlan": { + "sonic-vlan:VLAN_INTERFACE": { + "VLAN_INTERFACE_LIST": [ + { + "name": "Vlan1000", + "grat_arp": "true" + } + ] + } + } + }, + "VLAN_INTERFACE_INVALID_PROXY_ARP": { + "sonic-vlan:sonic-vlan": { + "sonic-vlan:VLAN_INTERFACE": { + "VLAN_INTERFACE_LIST": [ + { + "name": "Vlan1000", + "proxy_arp": "true" + } + ] + } + } } } diff --git a/src/sonic-yang-models/yang-models/sonic-device_metadata.yang b/src/sonic-yang-models/yang-models/sonic-device_metadata.yang index 7ca7f44915..8c736997e1 100644 --- a/src/sonic-yang-models/yang-models/sonic-device_metadata.yang +++ b/src/sonic-yang-models/yang-models/sonic-device_metadata.yang @@ -56,9 +56,7 @@ module sonic-device_metadata { } leaf hostname { - type string { - length 1..255; - } + type stypes:hostname; } leaf platform { @@ -128,6 +126,20 @@ module sonic-device_metadata { leaf region { type string; } + + leaf subtype { + type string { + pattern "DualToR"; + } + } + + leaf peer_switch { + type stypes:hostname; + } + + leaf storage_device { + type boolean; + } } /* end of container localhost */ } diff --git a/src/sonic-yang-models/yang-models/sonic-port.yang b/src/sonic-yang-models/yang-models/sonic-port.yang index 0e1c5db0b8..b2031688af 100644 --- a/src/sonic-yang-models/yang-models/sonic-port.yang +++ b/src/sonic-yang-models/yang-models/sonic-port.yang @@ -138,6 +138,10 @@ module sonic-port{ type stypes:tpid_type; } + leaf mux_cable { + type boolean; + } + } /* end of list PORT_LIST */ } /* end of container PORT */ diff --git a/src/sonic-yang-models/yang-models/sonic-vlan.yang b/src/sonic-yang-models/yang-models/sonic-vlan.yang index 5c45b9a93b..960f4b44c0 100644 --- a/src/sonic-yang-models/yang-models/sonic-vlan.yang +++ b/src/sonic-yang-models/yang-models/sonic-vlan.yang @@ -9,6 +9,10 @@ module sonic-vlan { prefix inet; } + import ietf-yang-types { + prefix yang; + } + import sonic-types { prefix stypes; } @@ -85,6 +89,18 @@ module sonic-vlan { enum disable; } } + + leaf grat_arp { + type string { + pattern "enabled|disabled"; + } + } + + leaf proxy_arp { + type string { + pattern "enabled|disabled"; + } + } } /* end of VLAN_INTERFACE_LIST */ @@ -184,6 +200,10 @@ module sonic-vlan { leaf admin_status { type stypes:admin_status; } + + leaf mac { + type yang:mac-address; + } } /* end of VLAN_LIST */ } diff --git a/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 b/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 index 04aff692d6..2c381af297 100644 --- a/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 +++ b/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 @@ -229,9 +229,14 @@ module sonic-types { } } + typedef hostname { + type string { + length 1..63; + } + } - /* Required for CVL */ {% if yang_model_type == "cvl" %} + /* Required for CVL */ container operation { description "This definition is used internally by CVL and