TypeFox / yang-lsp

A Language Server for YANG
http://www.yang-central.org
Apache License 2.0
51 stars 13 forks source link

Relative path for leafrefs in actions not resolved #163

Closed andreasjakobik closed 4 years ago

andreasjakobik commented 4 years ago

Hi,

Consider the below yang definition. Relative paths in leafref typed leafs inside an action input / output statement are not resolved correctly. An extra level has to be inserted into the path, but that is against yang spec, and definitely not aligned with how confd tool validates.

Any hints how to correct this issue is much appreciated.

Thanks, Andreas

`container c1 {

    leaf a {
        description "The referenced leaf";
        type int32;
    }

    list list-a {
        key "id";
        leaf id {
            type string;
        }
        leaf y1 {
                type leafref {
                    path "../../a"; // OK
                }              
        }
        leaf y2 {
                type leafref {
                    path "/c1/a"; // OK
                }              
        }
    }

    action func {
        input {
            leaf x1 {
                type leafref {
                    path "../../../a"; // ERROR! (Resolved but requires incorrect path!) 
                }
            }
            leaf x2 {
                type leafref {
                    path "../../a"; // ERROR! (Not Resolved!) 
                }
            }
            leaf x3 {
                type leafref {
                    path "/c1/a";  // OK
                }
            }
        }
    }

}`
RimShao commented 4 years ago

Hi ,

Recently we have another user have the same problem. and this time the leafref leaf is inside the grouping, please consider this use case as well.

Thanks.

andreasjakobik commented 4 years ago

Hello,

Below is a distilled test model that expose the problem with leafref path referencing a node in another grouping.

Thanks, Andreas

    grouping gy-failure-profile-type {
        leaf name {
            type string;
        }
    }
    grouping gy-profile-type {
        leaf name {
            type string;
        }
        leaf failure-profile {
            type leafref {
                // Relative path is not resolved!
                path "../../gy-failure-profile/name";  
                // However absolute path works fine:
                // path "/epg/pgw/credit-control/gy-failure-profile/name"; 
            }
        }
    }

    grouping pgw-type {
        container credit-control {
            list gy-failure-profile {
                key "name";
                uses gy-failure-profile-type;
            }

            list gy-profile {
                key "name";
                uses gy-profile-type;
            }
        }
    }

    container epg {
        container pgw {
            uses pgw-type;
        }
    }
RimShao commented 4 years ago

Hi Miro,

we have another use case that grouping with relative leafref path does not work. generally two groupings used by container, inside one grouping use leafref reference another grouping.

Thanks. //Rim

 container packet-detection {
      description
        "Configuration for packet detection";
      uses applist;
      uses filterlist;
 }    

  grouping applist {
    container application-list {
      description
        "Configuration for packet inspection";
      config false;
      list application {
        choice app-matching-conditions-start-menu {
          leaf filter {
            description
              "Matching Condition Filter identifier to match";
            type leafref {
              // this relative xpath works fine
              path "../../../filter-list/filter/name";
            }
          }
          list and {
            leaf-list filter {
              description
                "Matching Condition Filter identifier to match";
              type leafref {
                // this releative xpath can't resolve 
                path "../../../../filter-list/filter/name";
              }
            }
          }
        }
      }
    }
  }

  grouping filterlist {
    container filter-list {
      description
        "Configuration for packet inspection";
      list filter {
        key "name";
        leaf name {
          description
            "Filter identifier";
          type string;
          mandatory true;
        }
      }
    }
  }
andreasjakobik commented 4 years ago

Hi, In the above test model (beginning with container packet-detection) it seems the choice statement (choice app-matching-conditions-start-menu ) is causing the leafref path error. If I remove the choice statement, the model works fine. Thanks, Andreas