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

Initial commit for sonic-gnmi. #3

Closed
wants to merge 25 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update for review comment
ganglyu committed Jun 24, 2022

Verified

This commit was signed with the committer’s verified signature.
KyleFromNVIDIA Kyle Edwards
commit 79be626d1cb717fb4be52ba680162efb09988870
9 changes: 2 additions & 7 deletions gnmi_server/server.go
Original file line number Diff line number Diff line change
@@ -6,18 +6,14 @@ import (
"fmt"
"os"
"github.com/sonic-net/sonic-gnmi/common_utils"
//spb "github.com/sonic-net/sonic-gnmi/proto"
spb_jwt_gnoi "github.com/sonic-net/sonic-gnmi/proto/gnoi/jwt"
sdc "github.com/sonic-net/sonic-gnmi/sonic_data_client"
log "github.com/golang/glog"
//"github.com/golang/protobuf/proto"
gnmipb "github.com/openconfig/gnmi/proto/gnmi"
//gnmi_extpb "github.com/openconfig/gnmi/proto/gnmi_ext"
gnoi_system_pb "github.com/openconfig/gnoi/system"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
//"google.golang.org/grpc/peer"
"google.golang.org/grpc/reflection"
"google.golang.org/grpc/status"
"net"
@@ -135,9 +131,8 @@ func NewServer(config *Config, opts []grpc.ServerOption) (*Server, error) {
return nil, errors.New("config not provided")
}

workPath := "/etc/sonic/gnmi"
os.RemoveAll(workPath)
os.MkdirAll(workPath, 0777)
os.RemoveAll(common_utils.GNMI_WORK_PATH)
os.MkdirAll(common_utils.GNMI_WORK_PATH, 0777)
common_utils.InitCounters()

s := grpc.NewServer(opts...)
53 changes: 52 additions & 1 deletion gnmi_server/server_test.go
Original file line number Diff line number Diff line change
@@ -19,13 +19,14 @@ import (
_ "github.com/openconfig/gnmi/client"
_ "github.com/openconfig/ygot/ygot"
_ "github.com/google/gnxi/utils"
_ "github.com/jipanyang/gnxi/utils/xpath"
"github.com/jipanyang/gnxi/utils/xpath"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

"github.com/sonic-net/sonic-gnmi/common_utils"
// Register supported client types.
sdc "github.com/sonic-net/sonic-gnmi/sonic_data_client"
gnmipb "github.com/openconfig/gnmi/proto/gnmi"

"github.com/agiledragon/gomonkey"
"github.com/godbus/dbus/v5"
@@ -238,6 +239,56 @@ func TestAuthUser(t *testing.T) {
}
}

func TestParseOrigin(t *testing.T) {
var test_paths []*gnmipb.Path
var err error

_, err = ParseOrigin("test", test_paths)
if err != nil {
t.Errorf("ParseOrigin failed for empty path: %v", err)
}

test_origin := "sonic-test"
path, err := xpath.ToGNMIPath(test_origin + ":CONFIG_DB/VLAN")
test_paths = append(test_paths, path)
origin, err := ParseOrigin("", test_paths)
if err != nil {
t.Errorf("ParseOrigin failed to get origin: %v", err)
}
if origin != test_origin {
t.Errorf("ParseOrigin return wrong origin: %v", origin)
}
origin, err = ParseOrigin("sonic-invalid", test_paths)
if err == nil {
t.Errorf("ParseOrigin should fail for conflict")
}
}

func TestParseTarget(t *testing.T) {
var test_paths []*gnmipb.Path
var err error

_, err = ParseTarget("test", test_paths)
if err != nil {
t.Errorf("ParseTarget failed for empty path: %v", err)
}

test_target := "TEST_DB"
path, err := xpath.ToGNMIPath("sonic-db:" + test_target + "/VLAN")
test_paths = append(test_paths, path)
target, err := ParseTarget("", test_paths)
if err != nil {
t.Errorf("ParseTarget failed to get target: %v", err)
}
if target != test_target {
t.Errorf("ParseTarget return wrong target: %v", target)
}
target, err = ParseTarget("INVALID_DB", test_paths)
if err == nil {
t.Errorf("ParseTarget should fail for conflict")
}
}

func init() {
// Enable logs at UT setup
flag.Lookup("v").Value.Set("10")