CESNET / libyang

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

Unable to parse the yang file properly with libyang1, it omits the path in leafref when used inside the union. #2224

Closed punjaniraghav closed 7 months ago

punjaniraghav commented 7 months ago

ISSUE:

  1. Libyang goes on to parse the yang and replace the content from another yang i.e it resolves the union whereas pyang output remains the same as the 1st yang was created.
  2. Due to issue 1 it is unable to find the module name of the 3rd yang i.e libyang-test-2 because it's imported in yang no. 2(libyang-test-1.yang) and not in 1(libyang-test.yang). So after resolution of union, libyang corrupts the path of leafref.

    YANG 1: libyang-test.yang

    module libyang-test{
    yang-version 1.1;
    namespace "urn:libyang:params:xml:ns:yang:libyang-test";
    prefix test;
    
    import libyang-test-1 {
    prefix test1;
    }
    
    container y {
    leaf z {
      type test1:x;
    }
    }
    }

YANG 2: libyang-test-1.yang

module libyang-test-1{
  yang-version 1.1;
  namespace "urn:libyang:params:xml:ns:yang:libyang-test-1";
  prefix test1;

  import libyang-test-2 {
    prefix test2;
  }
  typedef x {
    type union {
        type leafref {
           path "/test2:a/test2:b";
        }
        type string;
    }
  }

}

YANG 3: libyang-test-2.yang

module libyang-test-2{
  yang-version 1.1;
  namespace "urn:libyang:params:xml:ns:yang:libyang-test-2";
  prefix test2;

  list a
  {
    key b;
    leaf b {
      type string;
    }
  }
}

INVALID OUTPUT :

-bash-4.2$ ./yanglint
> add /localdisk/libyang-test/libyang-test.yang
> print -f yang libyang-test
module libyang-test {
  yang-version 1.1;
  namespace "urn:libyang:params:xml:ns:yang:libyang-test";
  prefix test;

  import libyang-test-1 {
    prefix test1;
  }

  container y {
    leaf z {
      type union {
        type leafref {
libyang[0]: Module name "libyang-test-2" refers to an unknown module.
        }
        type string;
      }
    }
  }
}
>

PYANG OUTPUT :

-bash-4.2$ pyang -f yang libyang-test.yang
module libyang-test {
  yang-version 1.1;
  namespace "urn:libyang:params:xml:ns:yang:libyang-test";
  prefix test;

  import libyang-test-1 {
    prefix test1;
  }

  container y {
    leaf z {
      type test1:x;
    }
  }
}
michalvasko commented 7 months ago

I am sorry, but we do not support libyang v1 anymore, you will have to update to a more recent version.