Skip to content

Commit fe6d6d8

Browse files
committed
added test case, updated to RFC 8791
1 parent 870b9be commit fe6d6d8

File tree

7 files changed

+270
-5
lines changed

7 files changed

+270
-5
lines changed

doc/pyang.1.dbk

+11
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,17 @@ $ osascript foo.scpt</screen>
18521852
</para>
18531853
</listitem>
18541854
</varlistentry>
1855+
<varlistentry>
1856+
<term>
1857+
<option>--tree-print-structures</option>
1858+
</term>
1859+
<listitem>
1860+
<para>
1861+
Print the ietf-yang-structure-ext:structure structures
1862+
defined in the module.
1863+
</para>
1864+
</listitem>
1865+
</varlistentry>
18551866
<varlistentry>
18561867
<term>
18571868
<option>--tree-print-yang-data</option>
+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
module ietf-yang-structure-ext {
2+
yang-version 1.1;
3+
namespace "urn:ietf:params:xml:ns:yang:ietf-yang-structure-ext";
4+
prefix sx;
5+
6+
organization
7+
"IETF NETMOD (NETCONF Data Modeling Language) Working Group";
8+
contact
9+
"WG Web: <https://datatracker.ietf.org/wg/netmod/>
10+
WG List: <mailto:[email protected]>
11+
12+
Author: Andy Bierman
13+
14+
15+
Author: Martin Bjorklund
16+
17+
18+
Author: Kent Watsen
19+
<mailto:[email protected]>";
20+
description
21+
"This module contains conceptual YANG specifications for defining
22+
abstract data structures.
23+
24+
The key words 'MUST', 'MUST NOT', 'REQUIRED', 'SHALL', 'SHALL
25+
NOT', 'SHOULD', 'SHOULD NOT', 'RECOMMENDED', 'NOT RECOMMENDED',
26+
'MAY', and 'OPTIONAL' in this document are to be interpreted as
27+
described in BCP 14 (RFC 2119) (RFC 8174) when, and only when,
28+
they appear in all capitals, as shown here.
29+
30+
Copyright (c) 2020 IETF Trust and the persons identified as
31+
authors of the code. All rights reserved.
32+
33+
Redistribution and use in source and binary forms, with or
34+
without modification, is permitted pursuant to, and subject to
35+
the license terms contained in, the Simplified BSD License set
36+
forth in Section 4.c of the IETF Trust's Legal Provisions
37+
Relating to IETF Documents
38+
(http://trustee.ietf.org/license-info).
39+
40+
This version of this YANG module is part of RFC 8791
41+
(https://www.rfc-editor.org/info/rfc8791); see the RFC itself
42+
for full legal notices.";
43+
44+
revision 2020-06-17 {
45+
description
46+
"Initial revision.";
47+
reference
48+
"RFC 8791: YANG Data Structure Extensions.";
49+
}
50+
51+
extension structure {
52+
argument name {
53+
yin-element true;
54+
}
55+
description
56+
"This extension is used to specify a YANG data structure that
57+
represents conceptual data defined in YANG. It is intended to
58+
describe hierarchical data independent of protocol context or
59+
specific message encoding format. Data definition statements
60+
within a 'structure' extension statement specify the generic
61+
syntax for the specific YANG data structure, whose name is the
62+
argument of the 'structure' extension statement.
63+
64+
Note that this extension does not define a media type. A
65+
specification using this extension MUST specify the message
66+
encoding rules, including the content media type, if
67+
applicable.
68+
69+
The mandatory 'name' parameter value identifies the YANG data
70+
structure that is being defined.
71+
72+
This extension is only valid as a top-level statement, i.e.,
73+
given as a substatement to 'module' or 'submodule'.
74+
75+
The substatements of this extension MUST follow the ABNF
76+
rules below, where the rules are defined in RFC 7950:
77+
78+
*must-stmt
79+
[status-stmt]
80+
[description-stmt]
81+
[reference-stmt]
82+
*(typedef-stmt / grouping-stmt)
83+
*data-def-stmt
84+
85+
A YANG data structure defined with this extension statement is
86+
encoded in the same way as an 'anydata' node. This means
87+
that the name of the structure is encoded as a 'container',
88+
with the instantiated child statements encoded as child nodes
89+
to this node.
90+
91+
The module name and namespace value for the YANG module using
92+
the extension statement are assigned to each of the data
93+
definition statements resulting from the YANG data structure.
94+
95+
The XPath document element is the extension statement itself,
96+
such that the child nodes of the document element are
97+
represented by the data-def-stmt substatements within this
98+
extension. This conceptual document is the context for the
99+
following YANG statements:
100+
101+
- must-stmt
102+
- when-stmt
103+
- path-stmt
104+
- min-elements-stmt
105+
- max-elements-stmt
106+
- mandatory-stmt
107+
- unique-stmt
108+
- ordered-by
109+
- instance-identifier data type
110+
111+
The following data-def-stmt substatements are constrained
112+
when used within a 'structure' extension statement.
113+
114+
- The list-stmt is not required to have a key-stmt defined.
115+
- The config-stmt is ignored if present.
116+
";
117+
}
118+
119+
extension augment-structure {
120+
argument path {
121+
yin-element true;
122+
}
123+
description
124+
"This extension is used to specify an augmentation to a YANG
125+
data structure defined with the 'structure' statement. It is
126+
intended to describe hierarchical data independent of protocol
127+
context or specific message encoding format.
128+
129+
This statement has almost the same structure as the
130+
'augment-stmt'. Data definition statements within this
131+
statement specify the semantics and generic syntax for the
132+
additional data to be added to the specific YANG data
133+
structure, identified by the 'path' argument.
134+
135+
The mandatory 'path' parameter value identifies the YANG
136+
conceptual data node that is being augmented and is
137+
represented as an absolute-schema-nodeid string, where the
138+
first node in the absolute-schema-nodeid string identifies the
139+
YANG data structure to augment, and the rest of the nodes in
140+
the string identifies the node within the YANG structure to
141+
augment.
142+
143+
This extension is only valid as a top-level statement, i.e.,
144+
given as a substatement to 'module' or 'submodule'.
145+
146+
The substatements of this extension MUST follow the ABNF
147+
rules below, where the rules are defined in RFC 7950:
148+
149+
[status-stmt]
150+
[description-stmt]
151+
[reference-stmt]
152+
1*(data-def-stmt / case-stmt)
153+
154+
The module name and namespace value for the YANG module using
155+
the extension statement are assigned to instance document data
156+
conforming to the data definition statements within this
157+
extension.
158+
159+
The XPath document element is the augmented extension
160+
statement itself, such that the child nodes of the document
161+
element are represented by the data-def-stmt substatements
162+
within the augmented 'structure' statement.
163+
164+
The context node of the 'augment-structure' statement is
165+
derived in the same way as the 'augment' statement, as defined
166+
in Section 6.4.1 of [RFC7950]. This conceptual node is
167+
considered the context node for the following YANG statements:
168+
169+
- must-stmt
170+
- when-stmt
171+
- path-stmt
172+
- min-elements-stmt
173+
- max-elements-stmt
174+
- mandatory-stmt
175+
- unique-stmt
176+
- ordered-by
177+
- instance-identifier data type
178+
179+
The following data-def-stmt substatements are constrained
180+
when used within an 'augment-structure' extension statement.
181+
182+
- The list-stmt is not required to have a key-stmt defined.
183+
- The config-stmt is ignored if present.
184+
185+
Example:
186+
187+
module foo {
188+
import ietf-yang-structure-ext { prefix sx; }
189+
190+
sx:structure foo-data {
191+
container foo-con { }
192+
}
193+
}
194+
195+
module bar {
196+
import ietf-yang-structure-ext { prefix sx; }
197+
import foo { prefix foo; }
198+
199+
sx:augment-structure /foo:foo-data/foo:foo-con {
200+
leaf add-leaf1 { type int32; }
201+
leaf add-leaf2 { type string; }
202+
}
203+
}
204+
";
205+
}
206+
}

pyang/plugins/structure.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""YANG structure plugin
22
33
Verifies the grammar of the structure extension statements,
4-
as defined in draft-ietf-netmod-yang-data-ext
4+
as defined in RFC 8791.
55
"""
66

77
import pyang

pyang/plugins/tree.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Tree output plugin
22
3-
Compatible with RFC 8340.
3+
Compatible with RFC 8340 and RFC 8791.
44
55
Idea copied from libsmi.
66
"""
@@ -260,7 +260,7 @@ def print_header(module):
260260
sxs = module.search(('ietf-yang-structure-ext', 'structure'))
261261
if len(sxs) > 0:
262262
if not printed_header:
263-
print_header()
263+
print_header(module)
264264
printed_header = True
265265
section_delimiter_printed = False
266266
for sx in sxs:
@@ -277,7 +277,7 @@ def print_header(module):
277277
'augment-structure'))
278278
if len(sxs) > 0:
279279
if not printed_header:
280-
print_header()
280+
print_header(module)
281281
printed_header = True
282282
section_delimiter_printed = False
283283
for sx in sxs:

test/test_tree/Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test: test1 test2 test3 test4 test5 test6
1+
test: test1 test2 test3 test4 test5 test6 test7
22

33
test1:
44
$(PYANG) -f tree x.yang --tree-line-length 10 | diff x.tree.10.expect -
@@ -19,3 +19,7 @@ test5:
1919
test6:
2020
# Use module name as prefix
2121
$(PYANG) -f tree --tree-module-name-prefix interfaces-ext.yang ietf-interfaces.yang | diff ietf-interfaces-ext.tree.expect -
22+
23+
test7:
24+
$(PYANG) -f tree sx.yang --tree-print-structures| diff sx.tree.expect -
25+

test/test_tree/sx.tree.expect

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module: sx
2+
3+
structure address-book:
4+
+-- address* [last first]
5+
+-- last string
6+
+-- first string
7+
+-- street? string
8+
+-- city? string
9+
+-- state? string

test/test_tree/sx.yang

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module sx {
2+
yang-version 1.1;
3+
namespace "urn:example:example-module";
4+
prefix exm;
5+
6+
import ietf-yang-structure-ext {
7+
prefix sx;
8+
}
9+
10+
sx:structure address-book {
11+
list address {
12+
key "last first";
13+
leaf last {
14+
type string;
15+
description "Last name";
16+
}
17+
leaf first {
18+
type string;
19+
description "First name";
20+
}
21+
leaf street {
22+
type string;
23+
description "Street name";
24+
}
25+
leaf city {
26+
type string;
27+
description "City name";
28+
}
29+
leaf state {
30+
type string;
31+
description "State name";
32+
}
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)