corenova / yang-js

YANG parser and composer
Apache License 2.0
56 stars 18 forks source link

leafref broken for cross module leaf references ? #31

Closed ramukima closed 8 years ago

ramukima commented 8 years ago

I have following models:

foo.yang

module foo {
  prefix foo;
  list foo {
   leaf name {
      type string;
   }
}

bar.yang

module bar {
  prefix bar;
  import foo { prefix f; }

  leaf bar {
    type leafref { path "/f:foo/f:name"; }
  }
}

When I create an instance of foo (under yang-express using published URLs), and then try to create a bar instance supplying correct value of bar leafref, I always see error regarding unable to resolve the leafref.

sekur commented 8 years ago

Hi Amit, I actually don't think that is valid YANG schema? From the context of the module bar, it can use module foo's exported grouping, typedef, etc. it can also augment the foo module. But I don't think it can access data tree elements from module foo.

At least that's how I understood the spec. If there's public examples of how this should be possible, please share the reference.

sekur commented 8 years ago

Sorry, you're right! I didn't realize you should be allowed to go outside your current module for leafref! Ok will need to fix. :-)

   The accessible tree depends on the context node:

   o  If the context node represents configuration data, the tree is the
      data in the NETCONF datastore where the context node exists.  The
      XPath root node has all top-level configuration data nodes in all
      modules as children.

   o  Otherwise, the tree is all state data on the device, and the
      <running/> datastore.  The XPath root node has all top-level data
      nodes in all modules as children.
sekur commented 8 years ago

This should be addressed but I haven't verified.

Here's an example of how to test:

Yang = require 'yang-js'
store = new Yang.Store 'test'
store.import <schema or model>
store.import <schema or model>
console.log store.data.valueOf()

Basically, you can import YANG schema text or Yang expression instance or a Model and it will link all the top-level properties at the store.data property. This will make it possible for XPATH resolution for leafref/path to traverse across module boundaries.

It'd be great if you can give it a try with the latest yang-js published version (0.15.23).

sekur commented 8 years ago

@ramukima - were you able to confirm/verify the cross-module leafref functionality?

ramukima commented 8 years ago

I tested it with petstore example and I could see it work. But I am yet to validate multiple scenarios. Closing for now, will reopen if I find it broken again later.