yanglint FEATURE schema mount support (#1901)
* modify existing context if provided
In ly_ctx_new_yldata(), check if *ctx is NULL. If so, proceed as before
with allocating a new context. Otherwise, load modules into the existing
context.
Signed-off-by: Eric Kinzie <ekinzie@labn.net>
* add parent-reference xpath helper to schema-mount plugin
This new function produces a list of schema nodes from the expanded
parent-reference xpath expressions.
Signed-off-by: Eric Kinzie <ekinzie@labn.net>
* add context lookup to schema-mount plugin
This function allocates a new context for a particular instance of the
yangmnt:mount-point extension.
Signed-off-by: Eric Kinzie <ekinzie@labn.net>
* yanglint: schema-mount extension callback
Add a commandline argument "-x" that accepts a file containing extension
data, used to create a context for the schema-mount extension. This file
has the same format as what is provided to the "-Y" option. A callback
function for the schema-mount extenion is registered if the new option
is specified.
This allows validating instance data for models that include a schema
mount point.
Signed-off-by: Eric Kinzie <ekinzie@labn.net>
* yanglint: print mounted schema trees
Display "mp" flag for mount point and print mounted tree. Also display
the / and @ opts in node names.
Signed-off-by: Eric Kinzie <ekinzie@labn.net>
* add unit test for tree mount-point flag
Test is courtesy of aPiecek <piecek@cesnet.cz>.
Signed-off-by: Eric Kinzie <ekinzie@labn.net>
* add example data files for validation with schema-mount
From tools/lint/examples directory:
% ../../../build/yanglint \
-f json -t config -p ../../../models -p . \
-Y ./sm-context-main.xml -x ./sm-context-extension.xml sm-data.xml
% ../../../build/yanglint \
-f tree -p ../../../models -p . \
-Y ./sm-context-main.xml -x ./sm-context-extension.xml sm-main.yang
Signed-off-by: Eric Kinzie <ekinzie@labn.net>
Signed-off-by: Eric Kinzie <ekinzie@labn.net>
Co-authored-by: Eric Kinzie <ekinzie@labn.net>
diff --git a/tools/lint/examples/sm-context-extension.xml b/tools/lint/examples/sm-context-extension.xml
new file mode 100644
index 0000000..747c60f
--- /dev/null
+++ b/tools/lint/examples/sm-context-extension.xml
@@ -0,0 +1,64 @@
+<yang-library xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library"
+ xmlns:ds="urn:ietf:params:xml:ns:yang:ietf-datastores">
+ <module-set>
+ <name>test-set</name>
+ <module>
+ <name>ietf-datastores</name>
+ <revision>2018-02-14</revision>
+ <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>
+ </module>
+ <module>
+ <name>ietf-yang-library</name>
+ <revision>2019-01-04</revision>
+ <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>
+ </module>
+ <module>
+ <name>sm-extension</name>
+ <namespace>urn:sm-ext</namespace>
+ </module>
+ <module>
+ <name>iana-if-type</name>
+ <namespace>urn:ietf:params:xml:ns:yang:iana-if-type</namespace>
+ </module>
+ <import-only-module>
+ <name>ietf-yang-types</name>
+ <revision>2013-07-15</revision>
+ <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace>
+ </import-only-module>
+ <import-only-module>
+ <name>sm-mod</name>
+ <revision>2017-01-26</revision>
+ <namespace>urn:yanglint:sm-mod</namespace>
+ </import-only-module>
+ </module-set>
+ <schema>
+ <name>test-schema</name>
+ <module-set>test-set</module-set>
+ </schema>
+ <datastore>
+ <name>ds:running</name>
+ <schema>test-schema</schema>
+ </datastore>
+ <datastore>
+ <name>ds:operational</name>
+ <schema>test-schema</schema>
+ </datastore>
+ <content-id>1</content-id>
+ </yang-library>
+ <modules-state xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library">
+ <module-set-id>1</module-set-id>
+ </modules-state>
+ <schema-mounts xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount">
+ <namespace>
+ <prefix>if</prefix>
+ <uri>urn:ietf:params:xml:ns:yang:ietf-interfaces</uri>
+ </namespace>
+ <mount-point>
+ <module>sm-main</module>
+ <label>mnt-root</label>
+ <shared-schema>
+ <parent-reference>/if:interfaces/if:interface/if:name</parent-reference>
+ <parent-reference>/if:interfaces/if:interface/if:type</parent-reference>
+ </shared-schema>
+ </mount-point>
+ </schema-mounts>