Skip to content

Commit

Permalink
Remove the dependency on Jipanyang's personal repository (#345)
Browse files Browse the repository at this point in the history
Microsoft ADO: 27225139

Why I did it
We should not use Jipanyang's personal repo in sonic-gnmi

How I did it
Use google/gnxi to replace jipanyang/gnxi and update related patches

How to verify it
Run gnmi unit test and end to end test
  • Loading branch information
ganglyu authored Feb 5, 2025
1 parent 34b97ce commit f8c2979
Show file tree
Hide file tree
Showing 11 changed files with 307 additions and 216 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ go.mod:

$(GO_DEPS): go.mod $(PATCHES) swsscommon_wrap
$(GO) mod vendor
$(GO) mod download github.com/jipanyang/[email protected]20181221084354-f0a90cca6fd0
cp -r $(GOPATH)/pkg/mod/github.com/jipanyang/[email protected]20181221084354-f0a90cca6fd0/* vendor/github.com/jipanyang/gnxi/
$(GO) mod download github.com/google/[email protected]20181220173256-89f51f0ce1e2
cp -r $(GOPATH)/pkg/mod/github.com/google/[email protected]20181220173256-89f51f0ce1e2/* vendor/github.com/google/gnxi/

# Apply patch from sonic-mgmt-common, ignore glog.patch because glog version changed
sed -i 's/patch -d $${DEST_DIR}\/github.com\/golang\/glog/\#patch -d $${DEST_DIR}\/github.com\/golang\/glog/g' $(MGMT_COMMON_DIR)/patches/apply.sh
Expand Down Expand Up @@ -103,12 +103,12 @@ endif
git apply patches/0001-Updated-to-filter-and-write-to-file.patch

ifeq ($(CROSS_BUILD_ENVIRON),y)
$(GO) build -o ${GOBIN}/gnmi_get -mod=vendor github.com/jipanyang/gnxi/gnmi_get
$(GO) build -o ${GOBIN}/gnmi_set -mod=vendor github.com/jipanyang/gnxi/gnmi_set
$(GO) build -o ${GOBIN}/gnmi_get -mod=vendor github.com/google/gnxi/gnmi_get
$(GO) build -o ${GOBIN}/gnmi_set -mod=vendor github.com/google/gnxi/gnmi_set
$(GO) build -o ${GOBIN}/gnmi_cli -mod=vendor github.com/openconfig/gnmi/cmd/gnmi_cli
else
$(GO) install -mod=vendor github.com/jipanyang/gnxi/gnmi_get
$(GO) install -mod=vendor github.com/jipanyang/gnxi/gnmi_set
$(GO) install -mod=vendor github.com/google/gnxi/gnmi_get
$(GO) install -mod=vendor github.com/google/gnxi/gnmi_set
$(GO) install -mod=vendor github.com/openconfig/gnmi/cmd/gnmi_cli
endif

Expand Down
210 changes: 105 additions & 105 deletions gnmi_server/server_test.go

Large diffs are not rendered by default.

96 changes: 48 additions & 48 deletions gnmi_server/transl_sub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ func TestTranslSubscribe(t *testing.T) {

sub := doSubscribe(t, req, codes.OK)
sub.Verify(
Updated(acl1Path+"/name", "ONE"),
Updated(acl1Path+"/type", "ACL_IPV4"),
Updated(acl1Path+"/config/name", "ONE"),
Updated(acl1Path+"/config/type", "ACL_IPV4"),
Updated(acl1Path+"/state/name", "ONE"),
Updated(acl1Path+"/state/type", "ACL_IPV4"),
Updated("/openconfig"+acl1Path+"/name", "ONE"),
Updated("/openconfig"+acl1Path+"/type", "ACL_IPV4"),
Updated("/openconfig"+acl1Path+"/config/name", "ONE"),
Updated("/openconfig"+acl1Path+"/config/type", "ACL_IPV4"),
Updated("/openconfig"+acl1Path+"/state/name", "ONE"),
Updated("/openconfig"+acl1Path+"/state/type", "ACL_IPV4"),
client.Sync{},
)
})
Expand All @@ -160,8 +160,8 @@ func TestTranslSubscribe(t *testing.T) {
t.Logf("Verify poll updates include ACL1 data")
sub.Poll()
sub.Verify(
Updated(acl1Path+"/config/name", "ONE"),
Updated(acl1Path+"/config/type", "ACL_IPV4"),
Updated("/openconfig"+acl1Path+"/config/name", "ONE"),
Updated("/openconfig"+acl1Path+"/config/type", "ACL_IPV4"),
client.Sync{},
)

Expand All @@ -172,11 +172,11 @@ func TestTranslSubscribe(t *testing.T) {
t.Logf("Verify poll updates include both ACL1 and ACL2 data")
sub.Poll()
sub.Verify(
Updated(acl1Path+"/config/name", "ONE"),
Updated(acl1Path+"/config/type", "ACL_IPV4"),
Updated(acl2Path+"/config/name", "TWO"),
Updated(acl2Path+"/config/type", "ACL_IPV4"),
Updated(acl2Path+"/config/description", "foo"),
Updated("/openconfig"+acl1Path+"/config/name", "ONE"),
Updated("/openconfig"+acl1Path+"/config/type", "ACL_IPV4"),
Updated("/openconfig"+acl2Path+"/config/name", "TWO"),
Updated("/openconfig"+acl2Path+"/config/type", "ACL_IPV4"),
Updated("/openconfig"+acl2Path+"/config/description", "foo"),
client.Sync{},
)

Expand All @@ -187,8 +187,8 @@ func TestTranslSubscribe(t *testing.T) {
t.Logf("Verify poll updates now include ACL1 data only")
sub.Poll()
sub.Verify(
Updated(acl1Path+"/config/name", "ONE"),
Updated(acl1Path+"/config/type", "ACL_IPV4"),
Updated("/openconfig"+acl1Path+"/config/name", "ONE"),
Updated("/openconfig"+acl1Path+"/config/type", "ACL_IPV4"),
client.Sync{},
)
})
Expand All @@ -213,28 +213,28 @@ func TestTranslSubscribe(t *testing.T) {

t.Logf("Verify update notifications for ACL2 data")
sub.Verify(
Updated(acl2Path+"/config/name", "TWO"),
Updated(acl2Path+"/config/type", "ACL_IPV4"),
Updated(acl2Path+"/config/description", "foo"),
Updated("/openconfig"+acl2Path+"/config/name", "TWO"),
Updated("/openconfig"+acl2Path+"/config/type", "ACL_IPV4"),
Updated("/openconfig"+acl2Path+"/config/description", "foo"),
)

t.Logf("Create ACL1 and delete description of ACL2")
doSet(t, acl1CreatePb, acl2DescDeletePb)

t.Logf("Verify delete notification for ACL2 description and updates for ACL1 data")
sub.Verify(
Updated(acl1Path+"/config/name", "ONE"),
Updated(acl1Path+"/config/type", "ACL_IPV4"),
Deleted(acl2Path+"/config/description"),
Updated("/openconfig"+acl1Path+"/config/name", "ONE"),
Updated("/openconfig"+acl1Path+"/config/type", "ACL_IPV4"),
Deleted("/openconfig"+acl2Path+"/config/description"),
)

t.Logf("Delete ACL1 and set description for ACL2")
doSet(t, acl2DescUpdatePb, acl1DeletePb)

t.Logf("Verify delete for ACL1 and update for ACL2 description")
sub.Verify(
Deleted(acl1Path+"/config"),
Updated(acl2Path+"/config/description", "new"),
Deleted("/openconfig"+acl1Path+"/config"),
Updated("/openconfig"+acl2Path+"/config/description", "new"),
)
})

Expand Down Expand Up @@ -272,8 +272,8 @@ func TestTranslSubscribe(t *testing.T) {

t.Logf("Verify initial updates include ACL1 data only")
sub.Verify(
Updated(acl1Path+"/state/name", "ONE"),
Updated(acl1Path+"/state/type", "ACL_IPV4"),
Updated("/openconfig"+acl1Path+"/state/name", "ONE"),
Updated("/openconfig"+acl1Path+"/state/type", "ACL_IPV4"),
client.Sync{},
)

Expand All @@ -285,11 +285,11 @@ func TestTranslSubscribe(t *testing.T) {
t.Logf("interval %d", i)
sub.VerifyT(sampleInterval - 3*time.Second) // check no notifications before the interval
sub.Verify(
Updated(acl1Path+"/state/name", "ONE"),
Updated(acl1Path+"/state/type", "ACL_IPV4"),
Updated(acl2Path+"/state/name", "TWO"),
Updated(acl2Path+"/state/type", "ACL_IPV4"),
Updated(acl2Path+"/state/description", "foo"),
Updated("/openconfig"+acl1Path+"/state/name", "ONE"),
Updated("/openconfig"+acl1Path+"/state/type", "ACL_IPV4"),
Updated("/openconfig"+acl2Path+"/state/name", "TWO"),
Updated("/openconfig"+acl2Path+"/state/type", "ACL_IPV4"),
Updated("/openconfig"+acl2Path+"/state/description", "foo"),
)
}

Expand All @@ -299,17 +299,17 @@ func TestTranslSubscribe(t *testing.T) {
t.Logf("Verify next iteration includes deletes and updates (for remaining ACL2 data)")
sub.VerifyT(sampleInterval - 3*time.Second)
sub.Verify(
Deleted(acl1Path+"/state"),
Deleted(acl2Path+"/state/description"),
Updated(acl2Path+"/state/name", "TWO"),
Updated(acl2Path+"/state/type", "ACL_IPV4"),
Deleted("/openconfig"+acl1Path+"/state"),
Deleted("/openconfig"+acl2Path+"/state/description"),
Updated("/openconfig"+acl2Path+"/state/name", "TWO"),
Updated("/openconfig"+acl2Path+"/state/type", "ACL_IPV4"),
)

t.Logf("Verify next iteration has updates only")
sub.VerifyT(sampleInterval - 3*time.Second)
sub.Verify(
Updated(acl2Path+"/state/name", "TWO"),
Updated(acl2Path+"/state/type", "ACL_IPV4"),
Updated("/openconfig"+acl2Path+"/state/name", "TWO"),
Updated("/openconfig"+acl2Path+"/state/type", "ACL_IPV4"),
)
})

Expand All @@ -334,11 +334,11 @@ func TestTranslSubscribe(t *testing.T) {

t.Logf("Verify initial updates")
sub.Verify(
Updated(acl1Path+"/config/name", "ONE"),
Updated(acl1Path+"/config/type", "ACL_IPV4"),
Updated(acl2Path+"/config/name", "TWO"),
Updated(acl2Path+"/config/type", "ACL_IPV4"),
Updated(acl2Path+"/config/description", "foo"),
Updated("/openconfig"+acl1Path+"/config/name", "ONE"),
Updated("/openconfig"+acl1Path+"/config/type", "ACL_IPV4"),
Updated("/openconfig"+acl2Path+"/config/name", "TWO"),
Updated("/openconfig"+acl2Path+"/config/type", "ACL_IPV4"),
Updated("/openconfig"+acl2Path+"/config/description", "foo"),
client.Sync{},
)

Expand All @@ -351,8 +351,8 @@ func TestTranslSubscribe(t *testing.T) {
t.Logf("Verify next iteration includes deletes and updates for modified paths only")
sub.VerifyT(
sampleInterval+3*time.Second,
Deleted(acl1Path+"/config"),
Updated(acl2Path+"/config/description", "new"),
Deleted("/openconfig"+acl1Path+"/config"),
Updated("/openconfig"+acl2Path+"/config/description", "new"),
)

t.Logf("Delete ACL2 description")
Expand All @@ -361,7 +361,7 @@ func TestTranslSubscribe(t *testing.T) {
t.Logf("Verify next iteration includes description delete only")
sub.VerifyT(
sampleInterval+3*time.Second,
Deleted(acl2Path+"/config/description"),
Deleted("/openconfig"+acl2Path+"/config/description"),
)

t.Logf("Verify next iteration has no data")
Expand Down Expand Up @@ -393,7 +393,7 @@ func TestTranslSubscribe(t *testing.T) {
t.Logf("Verify next iteration has the description value")
sub.VerifyT(sampleInterval - 3*time.Second) // check no notifications before the interval
sub.Verify(
Updated(acl2Path+"/state/description", "foo"),
Updated("/openconfig"+acl2Path+"/state/description", "foo"),
)

t.Logf("Update ACL2 description")
Expand All @@ -402,7 +402,7 @@ func TestTranslSubscribe(t *testing.T) {
t.Logf("Verify next iteration has the updated description")
sub.VerifyT(sampleInterval - 3*time.Second)
sub.Verify(
Updated(acl2Path+"/state/description", "new"),
Updated("/openconfig"+acl2Path+"/state/description", "new"),
)

t.Logf("Delete ACL2")
Expand All @@ -411,7 +411,7 @@ func TestTranslSubscribe(t *testing.T) {
t.Logf("Verify next iteration has delete notification")
sub.VerifyT(sampleInterval - 3*time.Second)
sub.Verify(
Deleted(acl2Path + "/state/description"),
Deleted("/openconfig"+acl2Path + "/state/description"),
)

t.Logf("Verify next iteration has no notifications")
Expand Down Expand Up @@ -458,7 +458,7 @@ func TestTranslSubscribe(t *testing.T) {
t.Logf("Verify updates are received after default interval")
sub.VerifyT(
(translib.MinSubscribeInterval+2)*time.Second,
Updated(acl2Path+"/state/description", "foo"),
Updated("/openconfig"+acl2Path+"/state/description", "foo"),
)
})

Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ require (
github.com/gogo/protobuf v1.3.2
github.com/golang/glog v1.2.0
github.com/golang/protobuf v1.5.4
github.com/google/gnxi v0.0.0-20191016182648-6697a080bc2d
github.com/jipanyang/gnmi v0.0.0-20180820232453-cb4d464fa018
github.com/jipanyang/gnxi v0.0.0-20181221084354-f0a90cca6fd0
github.com/google/gnxi v0.0.0-20181220173256-89f51f0ce1e2
github.com/kylelemons/godebug v1.1.0
github.com/msteinert/pam v0.0.0-20201130170657-e61372126161
github.com/openconfig/gnmi v0.0.0-20200617225440-d2b4e6a45802
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/gnxi v0.0.0-20191016182648-6697a080bc2d h1:OtErLAncPdsEEhOI4ueR48dr6uThRIPkwWcOAdQ4LyI=
github.com/google/gnxi v0.0.0-20191016182648-6697a080bc2d/go.mod h1:6kkMbKS62iZMyk1q0zukcqkEJwnIhcbgg/hmoFmRDZk=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
Expand All @@ -73,10 +71,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jipanyang/gnmi v0.0.0-20180820232453-cb4d464fa018 h1:M++7b2XCTGqQwqu+AB0B3XzXiV+vVawnXJ4tvxUMrTU=
github.com/jipanyang/gnmi v0.0.0-20180820232453-cb4d464fa018/go.mod h1:+aiusdWGFuKzi7B8/Y75kTlIA3UDF+sUBfY5+1e2NLs=
github.com/jipanyang/gnxi v0.0.0-20181221084354-f0a90cca6fd0 h1:Dr/hrfbZxVlT/VvLfv8glHZAf9dLfuTSCJQq7cRGydo=
github.com/jipanyang/gnxi v0.0.0-20181221084354-f0a90cca6fd0/go.mod h1:vL9tMB3I625wwTPrEWmJ+kWrsHHFN/J79IEQD9knVi0=
github.com/google/gnxi v0.0.0-20181220173256-89f51f0ce1e2 h1:Cb0tImy52kinqtUXYR59HSNXYz83Y69yD8/zoKScE3s=
github.com/google/gnxi v0.0.0-20181220173256-89f51f0ce1e2/go.mod h1:6kkMbKS62iZMyk1q0zukcqkEJwnIhcbgg/hmoFmRDZk=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
Expand Down
93 changes: 79 additions & 14 deletions patches/gnmi_cli.all.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
--- ./github.com/openconfig/gnmi/client/gnmi/client.go 2019-11-22 14:03:29.839103602 -0800
patch--- ./github.com/openconfig/gnmi/client/gnmi/client.go 2019-11-22 14:03:29.839103602 -0800
+++ ./github.com/openconfig/gnmi/client/gnmi/client.go 2019-10-11 13:48:49.226145599 -0700
@@ -257,7 +257,7 @@
@@ -37,7 +37,6 @@
"github.com/openconfig/gnmi/client"
"github.com/openconfig/gnmi/client/grpcutil"
"github.com/openconfig/gnmi/path"
- "github.com/openconfig/gnmi/value"

gpb "github.com/openconfig/gnmi/proto/gnmi"
)
@@ -246,7 +245,7 @@
s := &gpb.SubscribeRequest_Subscribe{
Subscribe: &gpb.SubscriptionList{
Mode: getType(q.Type),
- Prefix: &gpb.Path{Target: q.Target},
+ Prefix: &gpb.Path{Target: q.Target, Origin: q.Origin},
},
}
if q.UpdatesOnly {
@@ -257,11 +256,58 @@
if err != nil {
return nil, fmt.Errorf("invalid query path %q: %v", qq, err)
}
Expand All @@ -9,6 +26,66 @@
}
return &gpb.SubscribeRequest{Request: s}, nil
}

+// decimalToFloat converts a *gnmi_proto.Decimal64 to a float32. Downcasting to float32 is performed as the
+// precision of a float64 is not required.
+func decimalToFloat(d *gpb.Decimal64) float32 {
+ return float32(float64(d.Digits) / math.Pow(10, float64(d.Precision)))
+}
+
+// ToScalar will convert TypedValue scalar types to a Go native type. It will
+// return an error if the TypedValue does not contain a scalar type.
+func toScalar(tv *gpb.TypedValue) (interface{}, error) {
+ var i interface{}
+ switch tv.Value.(type) {
+ case *gpb.TypedValue_DecimalVal:
+ i = decimalToFloat(tv.GetDecimalVal())
+ case *gpb.TypedValue_StringVal:
+ i = tv.GetStringVal()
+ case *gpb.TypedValue_IntVal:
+ i = tv.GetIntVal()
+ case *gpb.TypedValue_UintVal:
+ i = tv.GetUintVal()
+ case *gpb.TypedValue_BoolVal:
+ i = tv.GetBoolVal()
+ case *gpb.TypedValue_FloatVal:
+ i = tv.GetFloatVal()
+ case *gpb.TypedValue_LeaflistVal:
+ elems := tv.GetLeaflistVal().GetElement()
+ ss := make([]interface{}, len(elems))
+ for x, e := range elems {
+ v, err := toScalar(e)
+ if err != nil {
+ return nil, fmt.Errorf("ToScalar for ScalarArray %+v: %v", e.Value, err)
+ }
+ ss[x] = v
+ }
+ i = ss
+ case *gpb.TypedValue_BytesVal:
+ i = tv.GetBytesVal()
+ case *gpb.TypedValue_JsonIetfVal:
+ var val interface{}
+ val = tv.GetJsonIetfVal()
+ json.Unmarshal(val.([]byte), &i)
+ //i = tv.GetJsonIetfVal()
+ default:
+ return nil, fmt.Errorf("non-scalar type %+v", tv.Value)
+ }
+ return i, nil
+}
+
func noti(prefix []string, pp *gpb.Path, ts time.Time, u *gpb.Update) (client.Notification, error) {
sp := path.ToStrings(pp, false)
// Make a full new copy of prefix + u.Path to avoid any reuse of underlying
@@ -274,7 +320,7 @@
return client.Delete{Path: p, TS: ts}, nil
}
if u.Val != nil {
- val, err := value.ToScalar(u.Val)
+ val, err := toScalar(u.Val)
if err != nil {
return nil, err
}
--- ./github.com/openconfig/gnmi/cmd/gnmi_cli/gnmi_cli.go 2019-11-22 14:03:29.839103602 -0800
+++ ./github.com/openconfig/gnmi/cmd/gnmi_cli/gnmi_cli.go 2019-11-21 09:30:52.453893674 -0800
@@ -76,6 +76,11 @@
Expand Down Expand Up @@ -87,15 +164,3 @@
default:
return nil, fmt.Errorf("non-scalar type %+v", tv.Value)
}

--- ./github.com/openconfig/gnmi/client/gnmi/client.go 2019-11-22 14:03:29.847103498 -0800
+++ ./github.com/openconfig/gnmi/client/gnmi/client.go 2019-10-11 13:48:49.234145530 -0700
@@ -246,7 +246,7 @@
s := &gpb.SubscribeRequest_Subscribe{
Subscribe: &gpb.SubscriptionList{
Mode: getType(q.Type),
- Prefix: &gpb.Path{Target: q.Target},
+ Prefix: &gpb.Path{Target: q.Target, Origin: q.Origin},
},
}
if q.UpdatesOnly {
Loading

0 comments on commit f8c2979

Please sign in to comment.