Skip to content

Commit edccb40

Browse files
committed
examples UPDATE extension parsing and validation
1 parent ca0a98e commit edccb40

File tree

4 files changed

+553
-0
lines changed

4 files changed

+553
-0
lines changed

tools/lint/examples/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Available commands:
1818
load Load a new schema from the searchdirs
1919
print Print a module
2020
data Load, validate and optionally print instance data
21+
ext Validate extension data
2122
list List all the loaded modules
2223
feature Print all features of module(s) with their state
2324
searchpath Print/set the search path(s) for schemas
@@ -534,3 +535,28 @@ $ yanglint -f json -t config -p . -Y sm-context-main.xml -x sm-context-extension
534535
}
535536
}
536537
```
538+
539+
## Validating extension data
540+
541+
The input data should be parsed and validated strictly according to the schema tree defined by the extension instance.
542+
543+
The tool parses and validates the input file (ext-data.xml) as a standalone extension data tree, not as part of a complete configuration. It does not allow mixing extension data with normal module data.
544+
545+
Preparation:
546+
547+
```
548+
> clear
549+
550+
> add example-jukebox.yang
551+
> data -i -k rc:yang-data:yang-errors ext-data.xml
552+
```
553+
554+
Output:
555+
556+
```
557+
libyang[0]: Invalid instance-identifier "/example-jukebox:jukebox/library" value - required instance not found. (data path: /ietf-restconf:errors/error[1]/error-path)
558+
YANGLINT[E]: Parsing of extension data failed.
559+
560+
```
561+
This error indicates that the input file refers to data (/example-jukebox:jukebox/library) that do not exist in the extension's schema tree — which violates the rules.
562+
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
module example-jukebox {
2+
3+
namespace "http://example.com/ns/example-jukebox";
4+
prefix "jbox";
5+
6+
organization "Example, Inc.";
7+
contact "support at example.com";
8+
description "Example Jukebox Data Model Module";
9+
revision "2016-08-15" {
10+
description "Initial version.";
11+
reference "example.com document 1-4673";
12+
}
13+
14+
identity genre {
15+
description "Base for all genre types";
16+
}
17+
18+
// abbreviated list of genre classifications
19+
identity alternative {
20+
base genre;
21+
description "Alternative music";
22+
}
23+
identity blues {
24+
base genre;
25+
description "Blues music";
26+
}
27+
identity country {
28+
base genre;
29+
description "Country music";
30+
}
31+
identity jazz {
32+
base genre;
33+
description "Jazz music";
34+
}
35+
identity pop {
36+
base genre;
37+
description "Pop music";
38+
}
39+
identity rock {
40+
base genre;
41+
description "Rock music";
42+
}
43+
44+
container jukebox {
45+
presence
46+
"An empty container indicates that the jukebox
47+
service is available";
48+
49+
description
50+
"Represents a jukebox resource, with a library, playlists,
51+
and a play operation.";
52+
53+
container library {
54+
55+
description "Represents the jukebox library resource.";
56+
57+
list artist {
58+
key name;
59+
60+
description
61+
"Represents one artist resource within the
62+
jukebox library resource.";
63+
64+
leaf name {
65+
type string {
66+
length "1 .. max";
67+
}
68+
description "The name of the artist.";
69+
}
70+
71+
list album {
72+
key name;
73+
74+
description
75+
"Represents one album resource within one
76+
artist resource, within the jukebox library.";
77+
78+
leaf name {
79+
type string {
80+
length "1 .. max";
81+
}
82+
description "The name of the album.";
83+
}
84+
85+
leaf genre {
86+
type identityref { base genre; }
87+
description
88+
"The genre identifying the type of music on
89+
the album.";
90+
}
91+
92+
leaf year {
93+
type uint16 {
94+
range "1900 .. max";
95+
}
96+
description "The year the album was released";
97+
}
98+
99+
container admin {
100+
description
101+
"Administrative information for the album.";
102+
103+
leaf label {
104+
type string;
105+
description "The label that released the album.";
106+
}
107+
leaf catalogue-number {
108+
type string;
109+
description "The album's catalogue number.";
110+
}
111+
}
112+
113+
list song {
114+
key name;
115+
116+
description
117+
"Represents one song resource within one
118+
album resource, within the jukebox library.";
119+
120+
leaf name {
121+
type string {
122+
length "1 .. max";
123+
}
124+
description "The name of the song";
125+
}
126+
leaf location {
127+
type string;
128+
mandatory true;
129+
description
130+
"The file location string of the
131+
media file for the song";
132+
}
133+
leaf format {
134+
type string;
135+
description
136+
"An identifier string for the media type
137+
for the file associated with the
138+
'location' leaf for this entry.";
139+
}
140+
leaf length {
141+
type uint32;
142+
units "seconds";
143+
description
144+
"The duration of this song in seconds.";
145+
}
146+
} // end list 'song'
147+
} // end list 'album'
148+
} // end list 'artist'
149+
150+
leaf artist-count {
151+
type uint32;
152+
units "songs";
153+
config false;
154+
description "Number of artists in the library";
155+
}
156+
leaf album-count {
157+
type uint32;
158+
units "albums";
159+
config false;
160+
description "Number of albums in the library";
161+
}
162+
leaf song-count {
163+
type uint32;
164+
units "songs";
165+
config false;
166+
description "Number of songs in the library";
167+
}
168+
} // end library
169+
170+
list playlist {
171+
key name;
172+
173+
description
174+
"Example configuration data resource";
175+
176+
leaf name {
177+
type string;
178+
description
179+
"The name of the playlist.";
180+
}
181+
leaf description {
182+
type string;
183+
description
184+
"A comment describing the playlist.";
185+
}
186+
list song {
187+
key index;
188+
ordered-by user;
189+
190+
description
191+
"Example nested configuration data resource";
192+
193+
leaf index { // not really needed
194+
type uint32;
195+
description
196+
"An arbitrary integer index for this playlist song.";
197+
}
198+
leaf id {
199+
type instance-identifier;
200+
mandatory true;
201+
description
202+
"Song identifier. Must identify an instance of
203+
/jukebox/library/artist/album/song/name.";
204+
}
205+
}
206+
}
207+
208+
container player {
209+
description
210+
"Represents the jukebox player resource.";
211+
212+
leaf gap {
213+
type decimal64 {
214+
fraction-digits 1;
215+
range "0.0 .. 2.0";
216+
}
217+
units "tenths of seconds";
218+
description "Time gap between each song";
219+
}
220+
}
221+
}
222+
223+
rpc play {
224+
description "Control function for the jukebox player";
225+
input {
226+
leaf playlist {
227+
type string;
228+
mandatory true;
229+
description "playlist name";
230+
}
231+
leaf song-number {
232+
type uint32;
233+
mandatory true;
234+
description "Song number in playlist to play";
235+
}
236+
}
237+
}
238+
}
239+

tools/lint/examples/ext-data.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<errors xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf">
2+
<error>
3+
<error-type>protocol</error-type>
4+
<error-tag>data-exists</error-tag>
5+
<error-path
6+
xmlns:rc="urn:ietf:params:xml:ns:yang:ietf-restconf"
7+
xmlns:jbox="http://example.com/ns/example-jukebox">/jbox:jukebox/jbox:library</error-path>
8+
<error-message>Data already exists; cannot create new resource</error-message>
9+
</error>
10+
</errors>

0 commit comments

Comments
 (0)