Yang schema mount: repaired yanglib statedata mountpoint

Example: patch to fix "dual xpath" issue
This commit is contained in:
Olof hagsand 2023-02-07 17:12:52 +01:00
parent 8699af97fb
commit 8f7ae33262
5 changed files with 31 additions and 10 deletions

View file

@ -70,6 +70,12 @@
/* Command line options to be passed to getopt(3) */
#define BACKEND_EXAMPLE_OPTS "a:nrsS:x:iuUtV:"
/* Enabling this improves performance in tests, but there may trigger the "double XPath"
* problem.
* Disabling it makes perf go down but makes it safe for "double XPath"
*/
#define _STATEFILTER
/*! Yang action
* Start backend with -- -a <instance-id>
* where instance-id points to an action node in some YANG
@ -523,13 +529,15 @@ example_statefile(clicon_handle h,
{
int retval = -1;
cxobj **xvec = NULL;
size_t xlen = 0;
int i;
cxobj *xt = NULL;
yang_stmt *yspec = NULL;
FILE *fp = NULL;
cxobj *x1;
int ret;
#ifdef _STATEFILTER
size_t xlen = 0;
int i;
cxobj *x1;
#endif
/* If -S is set, then read state data from file */
if (!_state || !_state_file)
@ -551,6 +559,7 @@ example_statefile(clicon_handle h,
}
if (_state_file_cached)
xt = _state_xml_cache;
#ifdef _STATEFILTER
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, xpath) < 0)
goto done;
/* Mark elements to copy:
@ -573,6 +582,10 @@ example_statefile(clicon_handle h,
/* Unmark returned state tree */
if (xml_apply(xstate, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset, (void*)(XML_FLAG_MARK|XML_FLAG_CHANGE)) < 0)
goto done;
#else
if (xml_copy(xt, xstate) < 0)
goto done;
#endif
if (_state_file_cached)
xt = NULL; /* ensure cache is not cleared */
ok:

View file

@ -202,7 +202,7 @@ xml_yang_mount_set(cxobj *x,
(yu = yang_find(y, Y_UNKNOWN, "yangmnt:mount-point")) == NULL){
goto done;
}
if (xml2xpath(x, NULL, 0, &xpath) < 0)
if (xml2xpath(x, NULL, 1, &xpath) < 0)
goto done;
if ((cvv = yang_cvec_get(yu)) != NULL &&
(cv = cvec_find(cvv, xpath)) != NULL &&

View file

@ -122,7 +122,7 @@ if [ $RC -ne 0 ]; then
fi
new "wait restconf"
swait_restconf
wait_restconf
rpc="<rpc $DEFAULTNS><edit-config><target><candidate/></target><config>"
rpc+="<interfaces xmlns=\"urn:example:clixon\"><a><name>foo</name><b>"

View file

@ -163,7 +163,7 @@ EOF
# State file with error: wrong namespace
cat <<EOF > $fstate
<mystate xmlns="urn:example:foobar">
<mystate xmlns="urn:example:clixon">
<parameter>
<name>x</name>
<value>x</value>
@ -305,6 +305,16 @@ new "restconf GET augment multi-namespace, no 2nd module in api-path, fail"
expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/augment:route-config/dynamic/ospf)" 0 "HTTP/$HVER 404" '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"invalid-value","error-severity":"error","error-message":"Instance does not exist"}}}'
#----------------------------------------------
# State file with error: wrong namespace
cat <<EOF > $fstate
<mystate xmlns="urn:example:foobar">
<parameter>
<name>x</name>
<value>x</value>
</parameter>
</mystate>
EOF
# Also generate an invalid state XML. This should generate an "Internal" error and the name of the
new "restconf GET failed state"
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPROTO://localhost/restconf/data?content=nonconfig)" 0 "HTTP/$HVER 412" '<errors xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf"><error><error-type>application</error-type><error-tag>operation-failed</error-tag><error-info><bad-element>mystate</bad-element></error-info><error-severity>error</error-severity><error-message>Failed to find YANG spec of XML node: mystate with parent: config in namespace: urn:example:foobar. Internal error, state callback returned invalid XML from plugin: example_backend</error-message></error></errors>'

View file

@ -76,9 +76,9 @@ fi
new "wait backend"
wait_backend
new "Add two mountpoints: x and y"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><edit-config><target><candidate/></target><config><top xmlns=\"urn:example:clixon\"><mylist><name>x</name><root/></mylist><mylist><name>y</name><root/></mylist></top></config></edit-config></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
new "netconf commit"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><commit/></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
@ -86,9 +86,7 @@ new "Retrieve schema-mounts with <get> Operation"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get><filter type=\"subtree\"><schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\"></schema-mounts></filter></get></rpc>" "<rpc-reply $DEFAULTNS><data><schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\"><mount-point><module>clixon-example</module><label>myroot</label><config>true</config><inline/></mount-point></schema-mounts></data></rpc-reply>"
new "get yang-lib at mountpoint"
# XXX maybe too many yangs here, difficult to maintain
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get><filter type=\"subtree\"><top xmlns=\"urn:example:clixon\"><mylist/></top>></filter></get></rpc>" "<rpc-reply $DEFAULTNS><data><top xmlns=\"urn:example:clixon\"><mylist><name>x</name><root>
<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\"><module-set><name>default</name><module><name>clixon-autocli</name><revision>2022-02-11</revision><namespace>http://clicon.org/autocli</namespace></module><module><name>clixon-example</name><revision>2022-11-01</revision><namespace>urn:example:clixon</namespace></module><module><name>ietf-datastores</name><revision>2018-02-14</revision><namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace></module><module><name>ietf-inet-types</name><revision>2021-02-22</revision><namespace>urn:ietf:params:xml:ns:yang:ietf-inet-types</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>ietf-yang-types</name><revision>2013-07-15</revision><namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace></module></module-set><content-id>mount-point</content-id></yang-library></root></mylist><mylist><name>y</name><root><yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\"><module-set><name>default</name><module><name>clixon-autocli</name><revision>2022-02-11</revision><namespace>http://clicon.org/autocli</namespace></module><module><name>clixon-example</name><revision>2022-11-01</revision><namespace>urn:example:clixon</namespace></module><module><name>ietf-datastores</name><revision>2018-02-14</revision><namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace></module><module><name>ietf-inet-types</name><revision>2021-02-22</revision><namespace>urn:ietf:params:xml:ns:yang:ietf-inet-types</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>ietf-yang-types</name><revision>2013-07-15</revision><namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace></module></module-set><content-id>mount-point</content-id></yang-library></root></mylist></top></data></rpc-reply>"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get><filter type=\"subtree\"><top xmlns=\"urn:example:clixon\"><mylist/></top>></filter></get></rpc>" "<rpc-reply $DEFAULTNS><data><top xmlns=\"urn:example:clixon\"><mylist><name>x</name><root><yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\"><module-set><name>mount</name><module><name>clixon-example</name><revision>2022-11-01</revision><namespace>urn:example:urn</namespace></module></module-set></yang-library></root></mylist><mylist><name>y</name><root><yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\"><module-set><name>mount</name><module><name>clixon-example</name><revision>2022-11-01</revision><namespace>urn:example:urn</namespace></module></module-set></yang-library></root></mylist></top></data></rpc-reply>"
if [ $BE -ne 0 ]; then
new "Kill backend"