From 6eb21f6ff2b8e0a7f5d812ed2358af90fa77c851 Mon Sep 17 00:00:00 2001 From: Praveen Chaudhary Date: Wed, 4 Mar 2020 08:26:11 -0800 Subject: [PATCH] =?UTF-8?q?[sonic-head.yang]:=20Libyang=20sweep=20host=20b?= =?UTF-8?q?its=20from=20inet:ip-prefix,=20fixin=E2=80=A6=20(#56)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [sonic-head.yang]: Libyang sweep host bits from inet:ip-prefix, fixing that problem. Changed inet:ip-prefix to custom ip-prefix. Changed test case accordingly. * [setup.py]: Build yang tree while package build. Changes done: 1.) Build yang tree while package build. 2.) Add sonic_yang_tree as part of package. 3.) Fix sonic-loopback-interface.yang for ip-prefix problem. --- sonic-slave-stretch/Dockerfile.j2 | 7 +- src/sonic-yang-mgmt/setup.py | 10 +- .../libyang-python-tests/test_sonic_yang.py | 11 +- .../yang-models/Sonic Yang Tree | 103 ------------------ .../yang-models/sonic-head.yang | 26 ++++- .../yang-models/sonic-interface.yang | 6 +- .../yang-models/sonic-loopback-interface.yang | 5 +- .../yang-models/sonic-vlan.yang | 6 +- 8 files changed, 52 insertions(+), 122 deletions(-) delete mode 100644 src/sonic-yang-mgmt/yang-models/Sonic Yang Tree diff --git a/sonic-slave-stretch/Dockerfile.j2 b/sonic-slave-stretch/Dockerfile.j2 index 20b6611c3350..4121c0d6a1fa 100644 --- a/sonic-slave-stretch/Dockerfile.j2 +++ b/sonic-slave-stretch/Dockerfile.j2 @@ -371,9 +371,10 @@ RUN pip install pytest-runner==4.4 RUN pip install setuptools==40.8.0 # For sonic_yang_mgmt build -RUN pip install ijson -RUN pip install jsondiff -RUN pip install xmltodict +RUN pip install ijson==2.6.1 +RUN pip install jsondiff==1.2.0 +RUN pip install xmltodict==0.12.0 +RUN pip install pyang==2.1.1 # For mgmt-framework build RUN pip install mmh3 diff --git a/src/sonic-yang-mgmt/setup.py b/src/sonic-yang-mgmt/setup.py index aeb0a3ea7ce0..b841b8b52b5b 100644 --- a/src/sonic-yang-mgmt/setup.py +++ b/src/sonic-yang-mgmt/setup.py @@ -53,6 +53,13 @@ def run (self): else: print("YANG Tests passed\n") + # Generate YANG Tree + pyang_tree_cmd = "pyang -f tree ./yang-models/*.yang > ./yang-models/sonic_yang_tree" + if (system(pyang_tree_cmd)): + print("Failed: {}".format(pyang_tree_cmd)) + else: + print("Passed: {}".format(pyang_tree_cmd)) + # run pytest for libyang python APIs self.pytest_args = [] errno = pytest.main(self.pytest_args) @@ -99,7 +106,8 @@ def run (self): './yang-models/sonic-interface.yang', './yang-models/sonic-port.yang', './yang-models/sonic-portchannel.yang', - './yang-models/sonic-vlan.yang']), + './yang-models/sonic-vlan.yang', + './yang-models/sonic_yang_tree']), ], zip_safe=False, ) diff --git a/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py b/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py index 7db42aad8153..474a3794237b 100644 --- a/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py +++ b/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py @@ -271,14 +271,9 @@ def test_xlate_rev_xlate(self): if syc.jIn == syc.revXlateJson: print("Xlate and Rev Xlate Passed") else: - # Right now, interface and vlan_interface will have default diff due to ip_prefix - from jsondiff import diff - configDiff = diff(syc.jIn, syc.revXlateJson, syntax='symmetric') - for key in configDiff.keys(): - if 'INTERFACE' not in key: - print("Xlate and Rev Xlate failed") - sys.exit(1) - print("Xlate and Rev Xlate Passed") + print("Xlate and Rev Xlate failed") + # make it fail + assert False == True return diff --git a/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree b/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree deleted file mode 100644 index 35ccb0bad2df..000000000000 --- a/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree +++ /dev/null @@ -1,103 +0,0 @@ -module: sonic-acl - +--rw sonic-acl - +--rw ACL_RULE - | +--rw ACL_RULE_LIST* [ACL_TABLE_NAME RULE_NAME] - | +--rw ACL_TABLE_NAME -> /sonic-acl/ACL_TABLE/ACL_TABLE_LIST/ACL_TABLE_NAME - | +--rw RULE_NAME string - | +--rw PACKET_ACTION? head:packet_action - | +--rw IP_TYPE? head:ip_type - | +--rw PRIORITY? uint32 - | +--rw (ip_prefix)? - | | +--:(ip4_prefix) - | | | +--rw SRC_IP? inet:ipv4-prefix - | | | +--rw DST_IP? inet:ipv4-prefix - | | +--:(ip6_prefix) - | | +--rw SRC_IPV6? inet:ipv6-prefix - | | +--rw DST_IPV6? inet:ipv6-prefix - | +--rw IN_PORTS* uint16 - | +--rw OUT_PORTS* uint16 - | +--rw (src_port)? - | | +--:(l4_src_port) - | | | +--rw L4_SRC_PORT? uint16 - | | +--:(l4_src_port_range) - | | +--rw L4_SRC_PORT_RANGE? string - | +--rw (dst_port)? - | | +--:(l4_dst_port) - | | | +--rw L4_DST_PORT? uint16 - | | +--:(l4_dst_port_range) - | | +--rw L4_DST_PORT_RANGE? string - | +--rw ETHER_TYPE? string - | +--rw IP_PROTOCOL? uint8 - | +--rw TCP_FLAGS? string - | +--rw DSCP? uint8 - | +--rw TC? uint8 - | +--rw (icmp)? - | | +--:(icmp4) - | | | +--rw ICMP_TYPE? uint8 - | | | +--rw ICMP_CODE? uint8 - | | +--:(icmp6) - | | +--rw ICMPV6_TYPE? uint8 - | | +--rw ICMPV6_CODE? uint8 - | +--rw INNER_ETHER_TYPE? string - | +--rw INNER_IP_PROTOCOL? uint8 - | +--rw INNER_L4_SRC_PORT? uint16 - | +--rw INNER_L4_DST_PORT? uint16 - +--rw ACL_TABLE - +--rw ACL_TABLE_LIST* [ACL_TABLE_NAME] - +--rw ACL_TABLE_NAME string - +--rw policy_desc? string - +--rw type? head:acl_table_type - +--rw stage? enumeration - +--rw ports* union -module: sonic-interface - +--rw sonic-interface - +--rw INTERFACE - +--rw INTERFACE_LIST* [interface ip-prefix] - +--rw interface -> /port:sonic-port/PORT/PORT_LIST/port_name - +--rw ip-prefix inet:ip-prefix - +--rw scope? enumeration - +--rw family? head:ip-family -module: sonic-port - +--rw sonic-port - +--rw PORT - +--rw PORT_LIST* [port_name] - +--rw port_name string - +--rw alias? string - +--rw lanes? string - +--rw description? string - +--rw speed? uint32 - +--rw mtu? uint16 - +--rw admin_status head:admin_status - +--rw fec? string -module: sonic-portchannel - +--rw sonic-portchannel - +--rw PORTCHANNEL - +--rw PORTCHANNEL_LIST* [portchannel_name] - +--rw portchannel_name string - +--rw members* -> /port:sonic-port/PORT/PORT_LIST/port_name - +--rw min_links? uint8 - +--rw description? string - +--rw mtu? uint16 - +--rw admin_status head:admin_status -module: sonic-vlan - +--rw sonic-vlan - +--rw VLAN_INTERFACE - | +--rw VLAN_INTERFACE_LIST* [vlan_name ip-prefix] - | +--rw vlan_name -> /sonic-vlan/VLAN/VLAN_LIST/vlan_name - | +--rw ip-prefix inet:ip-prefix - | +--rw scope? enumeration - | +--rw family? head:ip-family - +--rw VLAN - | +--rw VLAN_LIST* [vlan_name] - | +--rw vlan_name string - | +--rw vlanid? uint16 - | +--rw description? string - | +--rw dhcp_servers* inet:ip-address - | +--rw mtu? uint16 - | +--rw admin_status head:admin_status - | +--rw members* -> /port:sonic-port/PORT/PORT_LIST/port_name - +--rw VLAN_MEMBER - +--rw VLAN_MEMBER_LIST* [vlan_name port] - +--rw vlan_name -> /sonic-vlan/VLAN/VLAN_LIST/vlan_name - +--rw port -> /port:sonic-port/PORT/PORT_LIST/port_name - +--rw tagging_mode head:vlan_tagging_mode diff --git a/src/sonic-yang-mgmt/yang-models/sonic-head.yang b/src/sonic-yang-mgmt/yang-models/sonic-head.yang index 45822f8b7e8d..f0422c1febcc 100644 --- a/src/sonic-yang-mgmt/yang-models/sonic-head.yang +++ b/src/sonic-yang-mgmt/yang-models/sonic-head.yang @@ -8,11 +8,11 @@ module sonic-head { contact "lnos_coders@linkedin.com"; description "Head yang Module for SONiC OS"; - + revision 2019-07-01 { description "First Revision"; } - + typedef ip-family { type enumeration { enum IPv4; @@ -20,6 +20,28 @@ module sonic-head { } } + typedef sonic-ip4-prefix { + type string { + pattern + '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}' + + '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])' + + '/(([0-9])|([1-2][0-9])|(3[0-2]))'; + } + } + + typedef sonic-ip6-prefix { + type string { + pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}' + + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|' + + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}' + + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))' + + '(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))'; + pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|' + + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)' + + '(/.+)'; + } + } + typedef admin_status { type enumeration { enum up; diff --git a/src/sonic-yang-mgmt/yang-models/sonic-interface.yang b/src/sonic-yang-mgmt/yang-models/sonic-interface.yang index 061edb5efe0e..196e687a5838 100644 --- a/src/sonic-yang-mgmt/yang-models/sonic-interface.yang +++ b/src/sonic-yang-mgmt/yang-models/sonic-interface.yang @@ -77,8 +77,10 @@ module sonic-interface { } leaf ip-prefix { - /* TODO: this should be custom, not inet:ip-prefix.*/ - type inet:ip-prefix; + type union { + type head:sonic-ip4-prefix; + type head:sonic-ip6-prefix; + } } leaf scope { diff --git a/src/sonic-yang-mgmt/yang-models/sonic-loopback-interface.yang b/src/sonic-yang-mgmt/yang-models/sonic-loopback-interface.yang index 0ecf5f2216ff..d9bb55e5ab39 100644 --- a/src/sonic-yang-mgmt/yang-models/sonic-loopback-interface.yang +++ b/src/sonic-yang-mgmt/yang-models/sonic-loopback-interface.yang @@ -58,7 +58,10 @@ module sonic-loopback-interface { } leaf ip-prefix { - type inet:ip-prefix; + type union { + type head:sonic-ip4-prefix; + type head:sonic-ip6-prefix; + } } leaf scope { diff --git a/src/sonic-yang-mgmt/yang-models/sonic-vlan.yang b/src/sonic-yang-mgmt/yang-models/sonic-vlan.yang index 17d922246bc2..de52cb1f07b3 100644 --- a/src/sonic-yang-mgmt/yang-models/sonic-vlan.yang +++ b/src/sonic-yang-mgmt/yang-models/sonic-vlan.yang @@ -75,8 +75,10 @@ module sonic-vlan { } leaf ip-prefix { - mandatory true; - type inet:ip-prefix; + type union { + type head:sonic-ip4-prefix; + type head:sonic-ip6-prefix; + } } leaf scope {