diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5ff026ff..4cd4563d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -69,6 +69,7 @@ Developers may need to change their code
### 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: [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)
diff --git a/lib/src/clixon_yang_module.c b/lib/src/clixon_yang_module.c
index 830d9b52..e19a8d1f 100644
--- a/lib/src/clixon_yang_module.c
+++ b/lib/src/clixon_yang_module.c
@@ -180,6 +180,9 @@ yms_build(clicon_handle h,
yang_stmt *yc;
yang_stmt *ymod; /* generic module */
yang_stmt *yns = NULL; /* namespace */
+ yang_stmt *yinc;
+ yang_stmt *ysub;
+ char *name;
if ((ylib = yang_find(yspec, Y_MODULE, module)) == NULL &&
(ylib = yang_find(yspec, Y_SUBMODULE, module)) == NULL){
@@ -196,8 +199,7 @@ yms_build(clicon_handle h,
ymod = NULL;
while ((ymod = yn_each(yspec, ymod)) != NULL) {
- if (yang_keyword_get(ymod) != Y_MODULE &&
- yang_keyword_get(ymod) != Y_SUBMODULE)
+ if (yang_keyword_get(ymod) != Y_MODULE)
continue;
cprintf(cb,"");
cprintf(cb,"%s", yang_argument_get(ymod));
@@ -228,21 +230,20 @@ yms_build(clicon_handle h,
}
cprintf(cb, "implement");
}
- yc = NULL;
- while ((yc = yn_each(ymod, yc)) != NULL) {
- switch(yang_keyword_get(yc)){
- case Y_SUBMODULE:
- cprintf(cb,"");
- cprintf(cb,"%s", yang_argument_get(yc));
- if ((ys = yang_find(yc, Y_REVISION, NULL)) != NULL)
+ yinc = NULL;
+ while ((yinc = yn_each(ymod, yinc)) != NULL) {
+ if (yang_keyword_get(yinc) != Y_INCLUDE)
+ continue;
+ cprintf(cb,"");
+ name = yang_argument_get(yinc);
+ cprintf(cb,"%s", name);
+ if ((ysub = yang_find(yspec, Y_SUBMODULE, name)) != NULL){
+ if ((ys = yang_find(ysub, Y_REVISION, NULL)) != NULL)
cprintf(cb,"%s", yang_argument_get(ys));
else
cprintf(cb,"");
- cprintf(cb,"");
- break;
- default:
- break;
}
+ cprintf(cb,"");
}
cprintf(cb,"");
}
diff --git a/test/test_submodule.sh b/test/test_submodule.sh
index 8b9878cb..95fa98c6 100755
--- a/test/test_submodule.sh
+++ b/test/test_submodule.sh
@@ -32,6 +32,7 @@ restconf_config none false
cat < $cfg
+ main:A
$cfg
/usr/local/share/clixon
$dir
@@ -44,7 +45,7 @@ cat < $cfg
example_backend.so$
/usr/local/lib/$APPNAME/restconf
/usr/local/var/$APPNAME
- false
+ true
$RESTCONFIG
EOF
@@ -55,11 +56,19 @@ module main{
yang-version 1.1;
prefix ex;
namespace "urn:example:clixon";
+
include sub1;
import extra{
description "Uses the same prefix as submodule but for another module";
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{
uses xtra:mygroup;
leaf x{
@@ -248,6 +257,12 @@ expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+jso
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'
+new "NETCONF get module state"
+expecteof "$clixon_netconf -qf $cfg -D $DBG" 0 "$DEFAULTHELLO]]>]]>" "main2021-03-08urn:example:clixonAimplementsub1"
+
+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' "main2021-03-08urn:example:clixonAimplementsub1"
+
if [ $RC -ne 0 ]; then
new "Kill restconf daemon"
stop_restconf