mbj4668 / pyang

An extensible YANG validator and converter in python
ISC License
537 stars 344 forks source link

Unique statement not checked for nodes inside choice #260

Open szabolcsszekely opened 8 years ago

szabolcsszekely commented 8 years ago

If I add a unique statement for a node inside a choice statement, the generated schema contains wrong path.

$ cat main.yang 
module main {
    yang-version 1;
    namespace "http://example.com/main";
    prefix main;

    container my-container {
        list my-list {
            key name;
            unique "unique-test/a/parameter-1";
            leaf name {
                type string;
            }
            choice unique-test {
                case a {
                    leaf parameter-1 {
                        type string;
                    }
                }
                case b {
                    leaf parameter-2 {
                        type string;
                    }
                }
            }
        }
    }
}
$ cat test.xml 
<?xml version='1.0' encoding='UTF-8'?>
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
    <my-container xmlns="http://example.com/main">
        <my-list>
            <name>elem-1</name>
            <parameter-1>para-1</parameter-1>
        </my-list>
        <my-list>
            <name>elem-2</name>
            <parameter-1>para-1</parameter-1>
        </my-list>
        <my-list>
            <name>elem-3</name>
            <parameter-2>para-1</parameter-2>
        </my-list>
    </my-container>
</config>
$ yang2dsdl -t config -v test.xml main.yang 
== Generating RELAX NG schema './main-config.rng'
Done.

== Generating Schematron schema './main-config.sch'
Done.

== Generating DSRL schema './main-config.dsrl'
Done.

== Validating grammar and datatypes ...
test.xml validates.

== Adding default values... done.

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

The error-message should be this: Violated uniqueness for "main:unique-test/main:a/main:parameter-1"

I think the problem is that the generated main-config.sch file contains this rule: <sch:report test="preceding-sibling::main:my-list[main:unique-test/main:a/main:parameter-1=current()/main:unique-test/main:a/main:parameter-1]">Violated uniqueness for &quot;main:unique-test/main:a/main:parameter-1&quot;</sch:report> instead of this: <sch:report test="preceding-sibling::main:my-list[main:parameter-1=current()/main:parameter-1]">Violated uniqueness for &quot;main:unique-test/main:a/main:parameter-1&quot;</sch:report>

If I change the rule to the second one the uniqueness of parameter-1 is checked.

pyang version: pyang 1.7 (on commit 0528aa8 - Martin Björklund, 4 days ago : Fixes #259 - multiple bases in identity)

llhotka commented 8 years ago

Hmm, this looks like an error in RFC 6110. I sort of assumed that schema node identifiers in unique argument only contain data nodes. In your example it would be

unique "parameter-1";

This would work, too, but apparently it is not what RFC 6020 (and now also 7950) says.

szabolcsszekely commented 7 years ago

Hi, Do you have any update regarding this bug? Thanks, Szabolcs

llhotka commented 7 years ago

No, not yet. Feel free to prepare a pull request.

Lada

szabolcsszekely commented 6 years ago

Hi, Can you check this proposed correction? https://github.com/mbj4668/pyang/pull/434 thanks, Szabolcs