Skip to content

Commit

Permalink
Merge pull request #80 from openconfig/lookupall
Browse files Browse the repository at this point in the history
Fix compliance error handling in LookupAll
  • Loading branch information
DanG100 authored Dec 21, 2022
2 parents 897697d + 1dbfbac commit f87058c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ygnmi/ygnmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,10 @@ func LookupAll[T any](ctx context.Context, c *Client, q WildcardQuery[T], opts .
return nil, fmt.Errorf("failed to unmarshal data: %w", err)
}
if v.ComplianceErrors != nil {
if q.isLeaf() {
continue
}
log.V(0).Infof("noncompliant data encountered while unmarshalling: %v", v.ComplianceErrors)
continue
}
vals = append(vals, v)
}
Expand Down
56 changes: 55 additions & 1 deletion ygnmi/ygnmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,27 @@ func TestLookupAll(t *testing.T) {
},
wantVals: nil,
wantSubscriptionPath: leafPath,
}, {
desc: "non compliant value",
stub: func(s *testutil.Stubber) {
s.Notification(&gpb.Notification{
Timestamp: 100,
Update: []*gpb.Update{{
Path: testutil.GNMIPath(t, "model/a/single-key[key=10]/state/value"),
Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 10}},
}, {
Path: testutil.GNMIPath(t, "model/a/single-key[key=11]/state/fake-val"),
Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 11}},
}},
}).Sync()
},
wantVals: []*ygnmi.Value[int64]{
(&ygnmi.Value[int64]{
Path: testutil.GNMIPath(t, "model/a/single-key[key=10]/state/value"),
Timestamp: time.Unix(0, 100),
}).SetVal(10),
},
wantSubscriptionPath: leafPath,
}, {
desc: "success multiples value in same notification",
stub: func(s *testutil.Stubber) {
Expand Down Expand Up @@ -1574,6 +1595,35 @@ func TestLookupAll(t *testing.T) {
}),
},
wantSubscriptionPath: nonLeafPath,
}, {
desc: "non compliant values",
stub: func(s *testutil.Stubber) {
s.Notification(&gpb.Notification{
Timestamp: 100,
Update: []*gpb.Update{{
Path: testutil.GNMIPath(t, "model/a/single-key[key=10]/state/value-fake"),
Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 100}},
}, {
Path: testutil.GNMIPath(t, "model/a/single-key[key=10]/state/key"),
Val: &gpb.TypedValue{Value: &gpb.TypedValue_StringVal{StringVal: "10"}},
}},
}).Sync()
},
wantVals: []*ygnmi.Value[*exampleoc.Model_SingleKey]{
(&ygnmi.Value[*exampleoc.Model_SingleKey]{
Path: testutil.GNMIPath(t, "model/a/single-key[key=10]"),
Timestamp: time.Unix(0, 100),
ComplianceErrors: &ygnmi.ComplianceErrors{
PathErrors: []*ygnmi.TelemetryError{{
Value: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 100}},
Path: testutil.GNMIPath(t, "model/a/single-key[key=10]/state/value-fake"),
}},
},
}).SetVal(&exampleoc.Model_SingleKey{
Key: ygot.String("10"),
}),
},
wantSubscriptionPath: nonLeafPath,
}, {
desc: "no values",
stub: func(s *testutil.Stubber) {
Expand All @@ -1596,7 +1646,11 @@ func TestLookupAll(t *testing.T) {
for _, val := range got {
checkJustReceived(t, val.RecvTimestamp)
}
if diff := cmp.Diff(tt.wantVals, got, cmp.AllowUnexported(ygnmi.Value[*exampleoc.Model_SingleKey]{}), cmpopts.IgnoreFields(ygnmi.Value[*exampleoc.Model_SingleKey]{}, "RecvTimestamp"), protocmp.Transform()); diff != "" {
if diff := cmp.Diff(tt.wantVals, got,
cmp.AllowUnexported(ygnmi.Value[*exampleoc.Model_SingleKey]{}),
cmpopts.IgnoreFields(ygnmi.TelemetryError{}, "Err"),
cmpopts.IgnoreFields(ygnmi.Value[*exampleoc.Model_SingleKey]{}, "RecvTimestamp"),
protocmp.Transform()); diff != "" {
t.Errorf("LookupAll() returned unexpected diff (-want,+got):\n%s", diff)
}
})
Expand Down

0 comments on commit f87058c

Please sign in to comment.