Skip to content

Commit

Permalink
Merge pull request #86 from openconfig/handle-cli-origin
Browse files Browse the repository at this point in the history
Handle CLI origin string values.
  • Loading branch information
wenovus authored Jan 31, 2023
2 parents 430766e + 7c54992 commit bb45069
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ygnmi/gnmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ func populateSetRequest(req *gpb.SetRequest, path *gpb.Path, val interface{}, op
case replacePath, updatePath:
var typedVal *gpb.TypedValue
var err error
if opt.preferProto {
if s, ok := val.(*string); ok && path.Origin == "cli" {
typedVal = &gpb.TypedValue{Value: &gpb.TypedValue_AsciiVal{AsciiVal: *s}}
} else if opt.preferProto {
typedVal, err = ygot.EncodeTypedValue(val, gpb.Encoding_JSON_IETF, &ygot.RFC7951JSONConfig{AppendModuleName: true, PreferShadowPath: preferShadowPath})
} else {
typedVal = &gpb.TypedValue{Value: &gpb.TypedValue_JsonIetfVal{}}
Expand Down
14 changes: 14 additions & 0 deletions ygnmi/ygnmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3205,23 +3205,37 @@ func TestSetBatch(t *testing.T) {
}{{
desc: "leaf update replace delete",
addPaths: func(sb *ygnmi.SetBatch) {
cliPath, err := schemaless.NewConfig[string]("", "cli")
if err != nil {
t.Fatalf("Failed to create CLI ygnmi query: %v", err)
}
ygnmi.BatchUpdate(sb, cliPath, "hello, mercury")
ygnmi.BatchUpdate(sb, exampleocpath.Root().Parent().Child().One().Config(), "foo")
ygnmi.BatchReplace(sb, cliPath, "hello, venus")
ygnmi.BatchReplace(sb, exampleocpath.Root().Parent().Child().One().Config(), "bar")
ygnmi.BatchDelete(sb, cliPath)
ygnmi.BatchDelete(sb, exampleocpath.Root().Parent().Child().One().Config())
},
wantRequest: &gpb.SetRequest{
Prefix: &gpb.Path{
Target: "dut",
},
Update: []*gpb.Update{{
Path: &gpb.Path{Origin: "cli"},
Val: &gpb.TypedValue{Value: &gpb.TypedValue_AsciiVal{AsciiVal: "hello, mercury"}},
}, {
Path: testutil.GNMIPath(t, "parent/child/config/one"),
Val: &gpb.TypedValue{Value: &gpb.TypedValue_JsonIetfVal{JsonIetfVal: []byte("\"foo\"")}},
}},
Replace: []*gpb.Update{{
Path: &gpb.Path{Origin: "cli"},
Val: &gpb.TypedValue{Value: &gpb.TypedValue_AsciiVal{AsciiVal: "hello, venus"}},
}, {
Path: testutil.GNMIPath(t, "parent/child/config/one"),
Val: &gpb.TypedValue{Value: &gpb.TypedValue_JsonIetfVal{JsonIetfVal: []byte("\"bar\"")}},
}},
Delete: []*gpb.Path{
{Origin: "cli"},
testutil.GNMIPath(t, "parent/child/config/one"),
},
},
Expand Down

0 comments on commit bb45069

Please sign in to comment.