Skip to content

Commit

Permalink
Missing container in list support in YANG Model sonic-net#16704
Browse files Browse the repository at this point in the history
Add support container in list
Add support for single choice statement in container/list

Signed-off-by: vkuk <vkuhk@marvell.com>
  • Loading branch information
VladimirKuk committed Feb 25, 2024
1 parent f95fdac commit ccd336d
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/sonic-yang-mgmt/sonic_yang_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,17 @@ def _createLeafDict(self, model, table):
#choices, this is tricky, since leafs are under cases in tree.
choices = model.get('choice')
if choices:
for choice in choices:
cases = choice['case']
# If single choice exists in container/list
if isinstance(choices, dict):
cases = choices['case']
for case in cases:
self._fillLeafDict(case.get('leaf'), leafDict)
# If multiple choices exist in container/list
else:
for choice in choices:
cases = choice['case']
for case in cases:
self._fillLeafDict(case.get('leaf'), leafDict)

# leaf-lists
self._fillLeafDict(model.get('leaf-list'), leafDict, True)
Expand Down
34 changes: 34 additions & 0 deletions src/sonic-yang-mgmt/tests/libyang-python-tests/config_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,39 @@
}
]
}
},

"test-yang-structure:test-yang-container": {
"test-yang-structure:YANG_STRUCT_TEST": {
"YANG_LIST_TEST_LIST": [{
"name" : "Vlan1001",
"leaf-list-test": [
"fc02:2000::1",
"fc02:2000::2"
],
"container-in-list-test": {
"leaf-1": true,
"leaf-2": "test1",
"mc-case-leaf-1": 55,
"mc-case-leaf-3": 1234
},
"case-leaf-1": 101
},
{
"name" : "Test123",
"leaf-list-test": [
"3003:2000::1",
"2002:2001::2"
],
"container-in-list-test": {
"leaf-1": false,
"leaf-2": "test2",
"mc-case-leaf-2": 77,
"mc-case-leaf-3": 4321
},
"case-leaf-2": 1001
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
module test-yang-structure {

namespace "http://github.com/sonic-net/test";
prefix yangstructtest;

yang-version 1.1;

import ietf-yang-types {
prefix yang;
}

import ietf-inet-types {
prefix inet;
}

import test-head {
prefix head;
revision-date 2019-07-01;
}

revision 2021-10-30 {
description "First Revision";
}

container test-yang-container {

container YANG_STRUCT_TEST {

description "sample test container";

list YANG_LIST_TEST_LIST {

key "name";

leaf name {
type string;
}

leaf-list leaf-list-test {
description "Test leaf-list statement";
type inet:ipv6-address;
}

container container-in-list-test {
leaf leaf-1 {
description "test leaf in container";
type string {
pattern "false|true";
}
}

leaf leaf-2 {
description "test leaf in container";
type string;
}

choice multi-choice-in-container-test-1 {
case mc-case-test-1 {
leaf mc-case-leaf-1 {
description "test leaf in multi choice";
type uint32;
}
}

case mc-case-test-2 {
leaf mc-case-leaf-2 {
description "test leaf in multi choice";
type uint8;
}
}
}

choice multi-choice-in-container-test-2 {
case mc-case-test-3 {
leaf mc-case-leaf-3 {
description "test leaf in multi choice";
type uint16;
}
}
}
}

choice single-choice-in-list-test {
case case-test-1 {
leaf case-leaf-1 {
description "test leaf in single choice";
type uint32;
}
}

case case-test-2 {
leaf case-leaf-2 {
description "test leaf in single choice";
type uint16;
}
}
}
}
/* end of YANG_LIST_TEST_LIST */
}
/* end of container YANG_STRUCT_TEST */
}
/* end of container test-yang-container */
}
/* end of module test-yang-structure */
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@
{
"file" : "test-vlan.yang",
"module" : "test-vlan"
},
{
"file" : "test-yang-structure.yang",
"module" : "test-yang-structure"
}
],
"new_nodes" : [
Expand Down Expand Up @@ -244,6 +248,10 @@
{
"module_name" : "test-vlan",
"module_prefix" : "vlan"
},
{
"module_name" : "test-yang-structure",
"module_prefix" : "yangstructtest"
}
],
"schema_dependencies" : [
Expand Down

0 comments on commit ccd336d

Please sign in to comment.