weixin_39588432
weixin_39588432
2020-12-01 19:08

lys_parse_path fails to resolve leafref inside Action

Executing lys_parse_path on a yang module containing the following container:


  container kernel-modules {
    list kernel-module {
      key "name";

      leaf name {
        type string;
      }

      leaf location {
        type string;
        default "/lib/modules";
      }

      leaf loaded {
        type boolean;
      }

      action get-dependencies {
        output {
          leaf-list dependency {
            type string;
          }
          leaf location {
            type leafref {
                path "/kernel-modules/kernel-module[name = current()/../../name]/location";
            }
          }
        }
      }
   }
}

yields error:


[ERR] No resolvents found for leafref predicate "current()/../../name]/location".
[ERR] libyang: Module "test-module" parsing failed.

Also fails with leafref shortened to just:


  leaf location {
     type leafref {
        path "../../location";
     }
  }

Whereas pyang accepts both versions.

Also, have one question: Once successfully parsed, will the leafref node have the LYS_XPATH_DEP flag set, or does it relate only to when/must?

该提问来源于开源项目:CESNET/libyang

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • weixin_39588432 weixin_39588432 4月前

    Hi Michal, it is working now with the longer variant that uses current, but still fails for path "../../location"

    re LYS_XPATH_DEP: I believe that for validation of RPC/Action/Notification I will also have to attach data trees of nodes referenced by leafrefs (?), just like in the case of when and must conditions. I could check if the scheme node of the operation is a predecessor of the leafref target node, but if you can do it in a cleaner / more efficient way, then it would be certainly useful.

    Thanks, Milan

    点赞 评论 复制链接分享
  • weixin_39857792 weixin_39857792 4月前

    Hi Milan, version 0.10.208 should now mark these outer dependencies for leafrefs as well. Flag was renamed to LYS_VALID_DEP.

    Regards, Michal

    点赞 评论 复制链接分享
  • weixin_39588432 weixin_39588432 4月前

    I can confirm that lys_parse_path now accepts both absolute and relative references. Thanks Michal for the patches.

    Regarding LYS_VALID_DEP: I'm getting an unexpected behaviour -- a leafref inside RPC referencing external leaf, but without the flag being set.

    The relevant part of the schema:

    
      rpc activate-software-image {
        input {
          leaf image-name {
            type string;
          }
          leaf location {
            type string;
            default "/";
          }
          leaf ref {
            type leafref {
              path "../../top-level-default";
            }
          }
        }
        output {
          leaf status {
            type string;
          }
          leaf version {
            type string;
          }
          leaf location {
            type string;
            default "/";
          }
          container init-log {
            list log-msg {
              key "msg time";
              leaf msg {
                type string;
              }
              leaf time {
                type uint32;
              }
              leaf msg-type {
                type enumeration {
                  enum "error" {
                    value 1;
                  }
                  enum "warning" {
                    value 2;
                  }
                  enum "debug" {
                    value 3;
                  }
                }
              }
            }
          }
        }
      }
    
      leaf top-level-default {
        type string;
        default "default value";
      }
    

    Also tried with an absolute path and got the same outcome:

    
    ...
          leaf ref {
            type leafref {
              path "/top-level-default";
            }
          }
    ...
    
    
    (gdb) print node->name
    $16 = 0x7c2600 "ref"
    (gdb) print ((struct lys_node_leaf *)node)->type.base 
    $22 = LY_TYPE_LEAFREF
    (gdb) print ((struct lys_node_leaf *)node)->type.info.lref
    $24 = {path = 0x7c2820 "/top-level-default", target = 0x7c3010, req = 0 '\000'}
    (gdb) print node->flags
    $17 = 0
    
    点赞 评论 复制链接分享
  • weixin_39857792 weixin_39857792 4月前

    Hi Milan, I have forgotten about standard RPCs, it should work now in version 0.10.211.

    Regards, Michal

    点赞 评论 复制链接分享
  • weixin_39588432 weixin_39588432 4月前

    Hi Michal, Yes, I can confirm that it is working now. Thanks!

    点赞 评论 复制链接分享