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

Remove the dependency on Jipanyang's personal repository #345

Merged
merged 5 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading