Skip to content

Commit

Permalink
gNOI Reboot changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ndas7 committed Oct 9, 2024
1 parent 0b3232f commit 5cc436a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
16 changes: 13 additions & 3 deletions common_utils/component_state_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,29 @@ import (

sdcfg "github.com/sonic-net/sonic-gnmi/sonic_db_config"
"github.com/go-redis/redis"
log "github.com/golang/glog"
)

const (
dbName = "STATE_DB"
)

func getRedisDBClient() (*redis.Client, error) {
ns, _ := sdcfg.GetDbDefaultNamespace()
addr, err := sdcfg.GetDbTcpAddr(dbName, ns)
if err != nil {
log.Errorf("Addr err: %v", err)
return
}
db, err := sdcfg.GetDbId("STATE_DB", ns)
if err != nil {
log.Errorf("DB err: %v", err)
return
}
rclient := redis.NewClient(&redis.Options{
Network: "tcp",
Addr: sdcfg.GetDbTcpAddr(dbName),
Addr: addr,
Password: "", // no password set
DB: sdcfg.GetDbId(dbName),
DB: db,
DialTimeout: 0,
})
if rclient == nil {
Expand Down
6 changes: 3 additions & 3 deletions gnmi_server/gnoi_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (srv *Server) Reboot(ctx context.Context, req *syspb.RebootRequest) (*syspb
return nil, status.Errorf(codes.InvalidArgument, err.Error())
}
// Initialize State DB.
rclient, err := getRedisDBClient(stateDB)
rclient, err := getRedisDBClient()
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}
Expand Down Expand Up @@ -276,7 +276,7 @@ func (srv *Server) RebootStatus(ctx context.Context, req *syspb.RebootStatusRequ
log.V(1).Info("gNOI: RebootStatus")
resp := &syspb.RebootStatusResponse{}
// Initialize State DB.
rclient, err := getRedisDBClient(stateDB)
rclient, err := getRedisDBClient()
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}
Expand Down Expand Up @@ -311,7 +311,7 @@ func (srv *Server) CancelReboot(ctx context.Context, req *syspb.CancelRebootRequ
return nil, status.Errorf(codes.Internal, "Invalid CancelReboot request: message is empty.")
}
// Initialize State DB.
rclient, err := getRedisDBClient(stateDB)
rclient, err := getRedisDBClient()
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion gnmi_server/gnoi_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestSystem(t *testing.T) {
defer cancel()

sc := syspb.NewSystemClient(conn)
rclient, err := getRedisDBClient(stateDB)
rclient, err := getRedisDBClient()
if err != nil {
t.Fatalf("Cannot connect to the redis server: %v.", err.Error())
}
Expand Down

0 comments on commit 5cc436a

Please sign in to comment.