clicon / clixon

YANG-based toolchain including NETCONF and RESTCONF interfaces and an interactive CLI
http://www.clicon.org/
Other
215 stars 72 forks source link

Using YANG union with decimal64 and string leads to regexp match fail #226

Closed paul-sirin closed 3 years ago

paul-sirin commented 3 years ago

After we enabled state data XML validation we have an issue with YANG union that can hold either decimal64 or string with pattern. I was able to reproduce the issue on clixon example using following patch:

diff --git a/example/main/clixon-example@2020-12-01.yang b/example/main/clixon-example@2020-12-01.yang
index 412e571d..914340f9 100644
--- a/example/main/clixon-example@2020-12-01.yang
+++ b/example/main/clixon-example@2020-12-01.yang
@@ -64,7 +64,14 @@ module clixon-example {
          config false;
          description "state data for the example application (must be here for example get operation)";
          leaf-list op {
-            type string;
+            type union {
+              type decimal64{
+                fraction-digits 2;
+              }
+              type string{
+                pattern "N/A";
+              }
+            }
          }
     }
     augment "/if:interfaces/if:interface" {
diff --git a/example/main/example.xml b/example/main/example.xml
index 63272346..4cc945f9 100644
--- a/example/main/example.xml
+++ b/example/main/example.xml
@@ -21,4 +21,5 @@
   <CLICON_NACM_MODE>disabled</CLICON_NACM_MODE>
   <CLICON_STREAM_DISCOVERY_RFC5277>true</CLICON_STREAM_DISCOVERY_RFC5277>
   <CLICON_MODULE_LIBRARY_RFC7895>false</CLICON_MODULE_LIBRARY_RFC7895>
+  <CLICON_VALIDATE_STATE_XML>true</CLICON_VALIDATE_STATE_XML>
 </clixon-config>

When I try to run example with state data enabled the issue happens all time when XML validation is enabled:

user@tpg-lt /> show state
May 19 10:54:27: Get configuration: application operation-failed regexp match fail: pattern does not match 41. Internal error, state callback returned
invalid XML <bad-element>op</bad-element>
CLI command error
olofhagsand commented 3 years ago

decimal64 fraction was not correctly read when validating a union. Please verify

paul-sirin commented 3 years ago

Thanks, it works well for both -- example and our code.