Skip to content

Commit

Permalink
[sonic-head.yang]: Libyang sweep host bits from inet:ip-prefix, fixin… (
Browse files Browse the repository at this point in the history
sonic-net#56)

* [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.
  • Loading branch information
Praveen Chaudhary committed Mar 4, 2020
1 parent 7498d55 commit 6eb21f6
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 122 deletions.
7 changes: 4 additions & 3 deletions sonic-slave-stretch/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/sonic-yang-mgmt/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
103 changes: 0 additions & 103 deletions src/sonic-yang-mgmt/yang-models/Sonic Yang Tree

This file was deleted.

26 changes: 24 additions & 2 deletions src/sonic-yang-mgmt/yang-models/sonic-head.yang
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,40 @@ 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;
enum IPv6;
}
}

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;
Expand Down
6 changes: 4 additions & 2 deletions src/sonic-yang-mgmt/yang-models/sonic-interface.yang
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions src/sonic-yang-mgmt/yang-models/sonic-vlan.yang
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6eb21f6

Please sign in to comment.