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

GNOI Implementation of OS.Verify #342

Merged
merged 18 commits into from
Jan 28, 2025
Merged
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
server implementation for verify.
hdwhdw committed Jan 23, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 3465fdfeac8092b17b744da853764dcf3bc4d2df
30 changes: 28 additions & 2 deletions gnmi_server/gnoi.go
Original file line number Diff line number Diff line change
@@ -116,8 +116,34 @@ func KillOrRestartProcess(restart bool, serviceName string) error {
return err
}

func (src *OSServer) Verify(ctx context.Context, req *gnoi_os_pb.VerifyRequest) (*gnoi_os_pb.VerifyResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "")
func (srv *OSServer) Verify(ctx context.Context, req *gnoi_os_pb.VerifyRequest) (*gnoi_os_pb.VerifyResponse, error) {
_, err := authenticate(srv.config, ctx, false)
if err != nil {
log.V(2).Infof("Failed to authenticate: %v", err)
return nil, err
}

log.V(1).Info("gNOI: Verify")
dbus, err := ssc.NewDbusClient()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dbus

Ensure DbusClient be closed or released to avoid resource leaks. Use defer to clean up.

defer dbus.Close()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and I'll put forward a PR to complete this for everything here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I take this back. The Close() method does not exist and that's why I don't see this statement in any other methods. Let me address this with another PR but for now let's just follow the surrounding code.

if err != nil {
log.V(2).Infof("Failed to create dbus client: %v", err)
return nil, err
}

images, err := dbus.ListImages()
if err != nil {
log.V(2).Infof("Failed to list images: %v", err)
return nil, err
}

current_image, ok := images["current"].(string)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current_image, ok := images["current"].(string)

If images["current"] is missing, it will cause a runtime panic. Add a check for the existence of the key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check added.

if !ok {
return nil, status.Errorf(codes.Internal, "Failed to assert current image as string")
}
resp := &gnoi_os_pb.VerifyResponse{
Version: current_image,
}
return resp, nil
}

func (srv *SystemServer) KillProcess(ctx context.Context, req *gnoi_system_pb.KillProcessRequest) (*gnoi_system_pb.KillProcessResponse, error) {
2 changes: 2 additions & 0 deletions gnmi_server/server.go
Original file line number Diff line number Diff line change
@@ -189,6 +189,7 @@ func NewServer(config *Config, opts []grpc.ServerOption) (*Server, error) {

fileSrv := &FileServer{Server: srv}
systemSrv := &SystemServer{Server: srv}
osSrv := &OSServer{Server: srv}

var err error
if srv.config.Port < 0 {
@@ -203,6 +204,7 @@ func NewServer(config *Config, opts []grpc.ServerOption) (*Server, error) {
if srv.config.EnableTranslibWrite || srv.config.EnableNativeWrite {
gnoi_system_pb.RegisterSystemServer(srv.s, systemSrv)
gnoi_file_pb.RegisterFileServer(srv.s, fileSrv)
gnoi_os_pb.RegisterOSServer(srv.s, osSrv)
}
if srv.config.EnableTranslibWrite {
spb_gnoi.RegisterSonicServiceServer(srv.s, srv)