onosproject / gnxi-simulators

Code for simulating various device and orchestration entities with which ONOS interacts, e.g. gNMI, gNOI, P4Runtime
14 stars 15 forks source link

Yang module with a list giving a panic error #128

Closed ruchakulkarni11 closed 1 year ago

ruchakulkarni11 commented 2 years ago

I am loading a yang module that contains a list. While starting a simulator it gives a panic error as "panic: schema error: could not unzip the schema; json: cannot unmarshal number into Go struct field ListAttr.Dir.Dir.ListAttr.MinElements of type yang.Value"

My yang module is very simple:

module example {
     container examplelist {
        list example {
                key "name";
                leaf name {
                        type string;
                }
                leaf desc {
                    type string;
                }
        }
    }
}

No errors while generating generated.go file and compiling simulator.

Any inputs will be helpful.

Thank you

SeanCondon commented 2 years ago

Please give more details on the command to generate the code. I'm a bit puzzled that the struct field mentions MinElements but you have not defined a min-elements in the YANG.

Also the schema and the Go structs are 2 separate and unrelated outputs in generated.go - are you mixing the 2 here?

ruchakulkarni11 commented 2 years ago

Hi Sean, Thank you for quick response.

I am using this command to generate the generated.go file, _"go run ../ygot/ygot/generator/generator.go -generate_fakeroot -output_file ./pkg/gnmi/modeldata/gostruct/generated.go -package_name gostruct -excludemodules ietf-interfaces -path ../yang/public,../yang/yang ./yang/example.yang"

I tried to use command.sh script to generate the generated.go file but can not do that because it installs latest version of ygot. So the above command is working for me as long as I don't have list in my yang module.

And about the MinElements, Yes I don't have any min elements in the list but error mentions about MinElements, so I was wondering if it is talking about this struct. As it also has a yang.Value.

Please let me know if you need more details.

Thank you.

ruchakulkarni11 commented 2 years ago

I tried to print the schema for debugging and I observed that in the schema MinElements value is the object of type yang.Value type instead it should be integer or null.

"ListAttr":{"MinElements":{"Name":""},"MaxElements":{"Name":""},"OrderedBy":null}

This schema is generated from the above command.

ruchakulkarni11 commented 2 years ago

While generatinga new generetaed.go file for new schema, it needed to install latest ygot for gogen package. When ygot is upgraded to latest version go.mod and go.sum files are changed. There is a check in makefile to check all dependencies are installed so it is expected that go.mod and go.sum are untouched and if they are modified compilation fails. I was facing this issue so I reinstalled ygot v0.8.3 and hence I got the list issue.

I commented the check in a file "gnxi-simulators/build/build-tools/make/onf-common.mk" and after compiling I did not see this issue.

What I did to add new schema:

  1. Generate the generated.go file
  2. Resolve the errors for ygotutils package - https://github.com/openconfig/ygot/issues/583
  3. Comment the "deps" in gnxi-simulators/build/build-tools/make/onf-common.mk
  4. make all