openconfig / ygot

A YANG-centric Go toolkit - Go/Protobuf Code Generation; Validation; Marshaling/Unmarshaling
Apache License 2.0
284 stars 106 forks source link

ResolveLeafrefTarget Not returning correct vlaue in case of List inside choice where list's key is a leafref #981

Open Sneh-Prabha opened 1 month ago

Sneh-Prabha commented 1 month ago

I used ygot/generator/generator.go to generate the gostruct file using yang files as input. I have a scenario where following heirarchy of elements causing the error.

/container/choice/case/container/list/leaf (leaf is of leafref type)

I have debugged and found that in api ResolveLeafrefTarget in ygot/yangschema/yangschema.go file fixedPath, err := fixSchemaTreePath(path, contextEntry) --> here value is fixedPath doesnt has choice and case name which is ended in error of "could not resolve leafref path"

Let me know if this kind of scenario is supported in ygot.

robshakir commented 1 month ago

Please can you provide a module that creates this issue. It's likely that we have a test coverage issue, since choice and case are not widely used in models that we see heavy use of.

Sneh-Prabha commented 2 weeks ago

Hi , Sorry for the delay in response. Following module creates this issue :

module test { yang-version 1.1; namespace "http://www.test.com/yang/ocnos/test"; prefix "test"; grouping a-state { container b-state { choice c-detail { case tagged { container details { list detail { key "id port-name tag-value"; max-elements 1; leaf id { type leafref { path "../config/id"; } } leaf port-name { type leafref { path "../config/port-name"; } } leaf tag-value { type leafref { path "../config/tag-value"; } } container config { uses config-common; uses config-tagged; } } } } } } } container abc { uses a-state; } grouping config-common { leaf id { type uint32 { range "0..65535" { } } } leaf port-name { type string { length "3..64"; pattern "[^?' =,>|]+"; } } } grouping config-tagged { leaf tag-value { type tag_value_t; } leaf tag-format { type tag_format_t; mandatory true; } } typedef tag_value_t { type string { length 1..4; pattern "([2-9])|([1-9][0-9])|([1-9][0-9][0-9])|([1-3][0-9][0-9][0-9])|(40[0-9][0-4])"; } } typedef tag_format_t { type string { length 4..6; pattern "(0x8100)|(0x88a8)"; } } }

I ran following command : go run /root/go/pkg/mod/github.com/openconfig/ygot\@v0.25.4/generator/generator.go -generate_fakeroot -output_file test.go -package_name goabc -exclude_modules ietf-interfaces -path http://github.com/openconfig/public --generate_simple_unions abc.yang

Got following error : F0829 13:50:40.354242 21675 generator.go:382] ERROR Generating GoStruct Code: could not resolve leafref path: [abc b-state details detail config id]