Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ygot Validate error, when yang leaf type is union #123

Open
songlinglingpml opened this issue Feb 28, 2024 · 0 comments
Open

ygot Validate error, when yang leaf type is union #123

songlinglingpml opened this issue Feb 28, 2024 · 0 comments

Comments

@songlinglingpml
Copy link

Hi, @faraazbrcm

I am using version 202012
When I use restful to send delete messages, sometimes the following error occurs

URL:
restconf/data/openconfig-network-instance:network-instances/network-instance=DEFAULT/protocols/protocol=oc-pol-types:ISIS,DEFAULT/isis/interfaces/interface=Ethernet8/levels/level=2/afi-safi/af=oc-isis-types:IPV4,oc-isis-types:UNICAST/segment-routing/adjacency-sids/adjacency-sid=172.60.61.1,321536

Code1:

baseTreeNode, err := ytypes.GetNode(ygSchema.RootSchema(), deviceObj, path)
basePathObj, ok := (baseTreeNode[0].Data).(ygot.ValidatedGoStruct)
if ok {
err := basePathObj.Validate(&ytypes.LeafrefOptions{IgnoreMissingData: true})
......

Code2:
In the following code, 'fieldVal(321536)' can be converted to both int32 and string, which was committed in ygot patch (
49e5a22)

in sonic-mgmt-common/vendor/github.com/openconfig/ygot/ytypes/list.go
if keyLeafKind == yang.Yunion && strings.HasSuffix(ft.Name(), "_Union") {
	sks, err := getUnionKindsNotEnums(cschema)
	if err != nil {
		return err
	}
	for _, sk := range sks {
		gv, err := StringToType(reflect.TypeOf(yangBuiltinTypeToGoType(sk)), fieldVal)
		if err == nil {
			mn := "To_" + ft.Name()
			mapMethod := val.MethodByName(mn)
			if !mapMethod.IsValid() {
				return fmt.Errorf("%s does not have a %s function", val, mn)
			}
			ec := mapMethod.Call([]reflect.Value{gv})
			if len(ec) != 2 {
				return fmt.Errorf("%s %s function returns %d params", ft.Name(), mn, len(ec))
			}
			ei := ec[0].Interface()
			ee := ec[1].Interface()
			if ee != nil {
				return fmt.Errorf("unmarshaled %v type %T does not have a union type: %v", fieldVal, fieldVal, ee)
			}
			nv = reflect.ValueOf(ei)
			break
		}
	}
	...
}

error-message
"/device/network-instances/network-instance: /device/network-instances/network-instance/protocols/protocol: /device/network-instances/network-instance/protocols/protocol/isis/interfaces: /device/network-instances/network-instance/protocols/protocol/isis/interfaces/interface: /device/network-instances/network-instance/protocols/protocol/isis/interfaces/interface/levels/level: /device/network-instances/network-instance/protocols/protocol/isis/interfaces/interface/levels/level/afi-safi/af: /device/network-instances/network-instance/protocols/protocol/isis/interfaces/interface/levels/level/afi-safi/af/segment-routing/adjacency-sids: /device/network-instances/network-instance/protocols/protocol/isis/interfaces/interface/levels/level/afi-safi/af/segment-routing/adjacency-sids/adjacency-sid: "321536" does not match regular expression pattern "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$" for schema "

yang info:

sid-id is in openconfig-segment-routing.yang,and it's type union

leaf sid-id {
  type oc-srt:sr-sid-type;
  description
    "The Segment Identifier to be used when advertising the IGP Prefix SID.";
}
typedef sr-sid-type {
type union {
type oc-mplst:mpls-label; ===》openconfig-mpls-types.yang
type oc-inet:ipv6-address; ===》openconfig-inet-types.yang
}
description
"The defined value of a segment identifier.";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant