Fixed: [yang submodule show error in modules-state #190](yang submodule show error in modules-state #190)

This commit is contained in:
Olof hagsand 2021-03-17 15:44:45 +01:00
parent fb9917e81e
commit f8830dc27e
3 changed files with 31 additions and 14 deletions

View file

@ -69,6 +69,7 @@ Developers may need to change their code
### Corrected Bugs ### Corrected Bugs
* Fixed: [yang submodule show error in modules-state #190](yang submodule show error in modules-state #190)
* Fixed: [Backend can not read datastore with container named "config" #147](https://github.com/clicon/clixon/issues/147) * Fixed: [Backend can not read datastore with container named "config" #147](https://github.com/clicon/clixon/issues/147)
* Fixed: [The config false leaf shouldn't be configed in startup stage #189](https://github.com/clicon/clixon/issues/189) * Fixed: [The config false leaf shouldn't be configed in startup stage #189](https://github.com/clicon/clixon/issues/189)
* Fixed: [CLIXON is not waiting for the hello message #184](https://github.com/clicon/clixon/issues/184) * Fixed: [CLIXON is not waiting for the hello message #184](https://github.com/clicon/clixon/issues/184)

View file

@ -180,6 +180,9 @@ yms_build(clicon_handle h,
yang_stmt *yc; yang_stmt *yc;
yang_stmt *ymod; /* generic module */ yang_stmt *ymod; /* generic module */
yang_stmt *yns = NULL; /* namespace */ yang_stmt *yns = NULL; /* namespace */
yang_stmt *yinc;
yang_stmt *ysub;
char *name;
if ((ylib = yang_find(yspec, Y_MODULE, module)) == NULL && if ((ylib = yang_find(yspec, Y_MODULE, module)) == NULL &&
(ylib = yang_find(yspec, Y_SUBMODULE, module)) == NULL){ (ylib = yang_find(yspec, Y_SUBMODULE, module)) == NULL){
@ -196,8 +199,7 @@ yms_build(clicon_handle h,
ymod = NULL; ymod = NULL;
while ((ymod = yn_each(yspec, ymod)) != NULL) { while ((ymod = yn_each(yspec, ymod)) != NULL) {
if (yang_keyword_get(ymod) != Y_MODULE && if (yang_keyword_get(ymod) != Y_MODULE)
yang_keyword_get(ymod) != Y_SUBMODULE)
continue; continue;
cprintf(cb,"<module>"); cprintf(cb,"<module>");
cprintf(cb,"<name>%s</name>", yang_argument_get(ymod)); cprintf(cb,"<name>%s</name>", yang_argument_get(ymod));
@ -228,21 +230,20 @@ yms_build(clicon_handle h,
} }
cprintf(cb, "<conformance-type>implement</conformance-type>"); cprintf(cb, "<conformance-type>implement</conformance-type>");
} }
yc = NULL; yinc = NULL;
while ((yc = yn_each(ymod, yc)) != NULL) { while ((yinc = yn_each(ymod, yinc)) != NULL) {
switch(yang_keyword_get(yc)){ if (yang_keyword_get(yinc) != Y_INCLUDE)
case Y_SUBMODULE: continue;
cprintf(cb,"<submodule>"); cprintf(cb,"<submodule>");
cprintf(cb,"<name>%s</name>", yang_argument_get(yc)); name = yang_argument_get(yinc);
if ((ys = yang_find(yc, Y_REVISION, NULL)) != NULL) cprintf(cb,"<name>%s</name>", name);
if ((ysub = yang_find(yspec, Y_SUBMODULE, name)) != NULL){
if ((ys = yang_find(ysub, Y_REVISION, NULL)) != NULL)
cprintf(cb,"<revision>%s</revision>", yang_argument_get(ys)); cprintf(cb,"<revision>%s</revision>", yang_argument_get(ys));
else else
cprintf(cb,"<revision></revision>"); cprintf(cb,"<revision></revision>");
cprintf(cb,"</submodule>");
break;
default:
break;
} }
cprintf(cb,"</submodule>");
} }
cprintf(cb,"</module>"); cprintf(cb,"</module>");
} }

View file

@ -32,6 +32,7 @@ restconf_config none false
cat <<EOF > $cfg cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config"> <clixon-config xmlns="http://clicon.org/config">
<CLICON_FEATURE>main:A</CLICON_FEATURE>
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE> <CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR> <CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
<CLICON_YANG_DIR>$dir</CLICON_YANG_DIR> <CLICON_YANG_DIR>$dir</CLICON_YANG_DIR>
@ -44,7 +45,7 @@ cat <<EOF > $cfg
<CLICON_BACKEND_REGEXP>example_backend.so$</CLICON_BACKEND_REGEXP> <CLICON_BACKEND_REGEXP>example_backend.so$</CLICON_BACKEND_REGEXP>
<CLICON_RESTCONF_DIR>/usr/local/lib/$APPNAME/restconf</CLICON_RESTCONF_DIR> <CLICON_RESTCONF_DIR>/usr/local/lib/$APPNAME/restconf</CLICON_RESTCONF_DIR>
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR> <CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
<CLICON_MODULE_LIBRARY_RFC7895>false</CLICON_MODULE_LIBRARY_RFC7895> <CLICON_MODULE_LIBRARY_RFC7895>true</CLICON_MODULE_LIBRARY_RFC7895>
$RESTCONFIG $RESTCONFIG
</clixon-config> </clixon-config>
EOF EOF
@ -55,11 +56,19 @@ module main{
yang-version 1.1; yang-version 1.1;
prefix ex; prefix ex;
namespace "urn:example:clixon"; namespace "urn:example:clixon";
include sub1; include sub1;
import extra{ import extra{
description "Uses the same prefix as submodule but for another module"; description "Uses the same prefix as submodule but for another module";
prefix xtra; prefix xtra;
} }
revision 2021-03-08;
feature A{
description "This test feature is enabled";
}
feature B{
description "This test feature is not enabled";
}
container main{ container main{
uses xtra:mygroup; uses xtra:mygroup;
leaf x{ leaf x{
@ -248,6 +257,12 @@ expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+jso
new "restconf edit augment 2" new "restconf edit augment 2"
expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" $RCPROTO://localhost/restconf/data/main:sub2 -d '{"main:aug2":"foo"}')" 0 'HTTP/1.1 201 Created' expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" $RCPROTO://localhost/restconf/data/main:sub2 -d '{"main:aug2":"foo"}')" 0 'HTTP/1.1 201 Created'
new "NETCONF get module state"
expecteof "$clixon_netconf -qf $cfg -D $DBG" 0 "$DEFAULTHELLO<rpc $DEFAULTNS><get><filter type=\"xpath\" select=\"/yl:modules-state/yl:module[yl:name='main']\" xmlns:yl=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\"/></get></rpc>]]>]]>" "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\"><module><name>main</name><revision>2021-03-08</revision><namespace>urn:example:clixon</namespace><feature>A</feature><conformance-type>implement</conformance-type><submodule><name>sub1</name><revision/></submodule></module>"
new "RESTCONF get module state"
expectpart "$(curl $CURLOPTS -X GET -H "Accept: application/yang-data+xml" $RCPROTO://localhost/restconf/data/ietf-yang-library:modules-state/module=main,2021-03-08?config=nonconfig)" 0 'HTTP/1.1 200 OK' "<module xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\"><name>main</name><revision>2021-03-08</revision><namespace>urn:example:clixon</namespace><feature>A</feature><conformance-type>implement</conformance-type><submodule><name>sub1</name><revision/></submodule></module>"
if [ $RC -ne 0 ]; then if [ $RC -ne 0 ]; then
new "Kill restconf daemon" new "Kill restconf daemon"
stop_restconf stop_restconf