CESNET / libyang

YANG data modeling language library
BSD 3-Clause "New" or "Revised" License
366 stars 293 forks source link

Incorrect must condition validation in specific cases #1293

Closed danikova closed 3 years ago

danikova commented 3 years ago

I am using yanglint version 1.9.2.

Yanglint incorrectly enforces must condition in this case.

must-error.yang to reproduce the error:

module must-error {
  yang-version 1;
  namespace "http://must";
  prefix must;

  revision 2020-11-26 {
    description
      "Initial revision.";
  }

  container ranges {
    list range {
      key "min";
      leaf min {
          must "not((../../../ranges/range[min > current()]/min) <= current()/../max)" {
              error-message "The ranges element cannot overlap another range.";
          }
          type string {
              pattern '\d*';
          }
      }
      leaf max {
          must "../min <= current()" {
              error-message "The value of the max parameter need to be greater than the min parameter value.";
          }
          type string {
              pattern '\d*';
          }
      }
    }
  }
}

must-error.xml to reproduce the issue:

<?xml version='1.0' encoding='UTF-8'?>
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <ranges xmlns="http://must">
    <range>
      <min>10</min>
      <max>50</max>
    </range>
  </ranges>
</config>

The used validation command: yanglint -s -t auto must-error.yang must-error.xml This results in the following error, which is not correct: err : Must condition "not((../../../ranges/range[min > current()]/min) <= current()/../max)" not satisfied. (/must-error:ranges/range[min='10']/min) err : The ranges element cannot overlap another range. (/must-error:ranges/range[min='10']/min)

Pyang/yang2dsdl accepts this xml as valid.

yang2dsdl -t config -v must-error.xml must-error.yang
== Generating RELAX NG schema './must-error-config.rng'
Done.

== Generating Schematron schema './must-error-config.sch'
Done.

== Generating DSRL schema './must-error-config.dsrl'
Done.

== Validating grammar and datatypes ...
must-error.xml validates

== Adding default values... done.

== Validating semantic constraints ...
No errors found.

The must condition is right, because when i'm introduce a new range which is overlap the another range, yang2dsdl throw an error too.

updated must-error.xml:

<?xml version='1.0' encoding='UTF-8'?>
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <ranges xmlns="http://must">
    <range>
      <min>10</min>
      <max>50</max>
    </range>
    <range>
      <min>40</min>
      <max>70</max>
    </range>
  </ranges>
</config>

Pyang/yang2dsdl output:

yang2dsdl -t config -v must-error.xml must-error.yang
== Generating RELAX NG schema './must-error-config.rng'
Done.

== Generating Schematron schema './must-error-config.sch'
Done.

== Generating DSRL schema './must-error-config.dsrl'
Done.

== Validating grammar and datatypes ...
must-error.xml validates

== Adding default values... done.

== Validating semantic constraints ...
--- Failed assert at "/nc:config/must:ranges/must:range/must:min":
    The ranges element cannot overlap another range.

Thanks, Dani

michalvasko commented 3 years ago

Okay, should be fixed now.

danikova commented 3 years ago

Hi, i checked out to the devel branch to give it a try, and if i am not wrong, the error is still exists.

$ yanglint --version: yanglint SO 1.9.20

$yanglint -s -t auto must-error.yang must-error.xml: err : Must condition "not((../../../ranges/range[min > current()]/min) <= current()/../max)" not satisfied. (/must-error:ranges/range[min='10']/min) err : The ranges element cannot overlap another range. (/must-error:ranges/range[min='10']/min)

michalvasko commented 3 years ago

Just tested with the exact same command and the files you provided here, it works fine. Please provide similar output to the following.

# ldconfig -p | grep libyang
        libyang.so.1 (libc6,x86-64) => /usr/local/lib64/libyang.so.1
        libyang.so (libc6,x86-64) => /usr/local/lib64/libyang.so
# ls -l /usr/local/lib64/ | grep libyang
lrwxrwxrwx 1 root root      12 nov 26 10:52 libyang.so -> libyang.so.1
lrwxrwxrwx 1 root root      17 nov 30 18:47 libyang.so.1 -> libyang.so.1.9.20
-rwxr-xr-x 1 root root 2411720 nov 30 09:25 libyang.so.1.9.19
-rwxr-xr-x 1 root root 2411496 nov 30 18:42 libyang.so.1.9.20
drwxr-xr-x 4 root root    4096 nov 26 10:47 libyang1
danikova commented 3 years ago

I got too many links, according to ldconfig, so i did a major clean up and make install, now it's working fine. Thanks for your help.