Panic on GNMI delete with union leafs#167
Conversation
|
One way to avoid so much code change is to add a new test case based on a synthetic schema that does the minimum that you need (such that it can be added to a subset of the code generation). I think this then allows you to just regenerate the specific schema that you need, but might need an additional test. |
robshakir
left a comment
There was a problem hiding this comment.
Thanks for this change -- I agree that there's a lot of code here :-). I added a comment that I think minimises this, but this looks a reasonable change.
I looked to see whether there was a useful helper function in ygot/util/reflect.go here -- since we have a number of cases where we have helpers that are structured to avoid panics, but I don't see a specific one for this case, which is essentially IsValidAndNotZero. If we expect that this is something that we'll check elsewhere, we could add it to that library (optional).
We have seen some Ondatra tests failing with a backtrace roughly similar to the test case being added to
ygnmi/ygnmi_test.go:This PR modifies
pathgen/gnmigen.goto check if the reflect value is valid before calling IsZero(). In the case of YANG union values, an uninitialized interface can be passed to reflect.ValueOf() which is one of the few cases it can return a zero value. This condition seems to exist only when a GNMI message is received that contains enough for a struct to be allocated but not enough for values to be populated (DELETE on a YANG keyed list).This PR contains a lot of changes because I have included a test case in
ygnmi/ygnmi_test.gothat reproduces the panic condition. e2ba447 contains just the changes to trigger the panic on the existing code and 77928a6 includes the fix.I am not sure if there is a better way to approach amending the test cases: I added the YANG modeling required to
pathgen/testdata/yang/openconfig-unione.yangand added this YANG file to all of thegen.shscripts. The remainder of the changes in the PR are generated code changes as a result of modifying the YANG testdata to support the conditions for this panic.