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.Activate #351

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

hdwhdw
Copy link
Contributor

@hdwhdw hdwhdw commented Jan 31, 2025

Why I did it

Support OS.Activate for GNOI.

How I did it

Implement OS.Activate.

How to verify it

On physical switch:

admin@switch:~$ sudo sonic-installer list
Current: SONiC-OS-20240510.24
Next: SONiC-OS-master.762661-a3792f837
Available:
SONiC-OS-master.762661-a3792f837
SONiC-OS-20240510.24
admin@switch:~$ docker exec gnmi gnoi_client -target 127.0.0.1:50052 -logtostderr -insecure -module OS -rpc Activate -jsonin  '{"version": "SONiC-OS-20240510.24"}'
OS Activate
{"Response":{"ActivateOk":{}}}
admin@switch:~$ sudo sonic-installer list
Current: SONiC-OS-20240510.24
Next: SONiC-OS-20240510.24
Available:
SONiC-OS-master.762661-a3792f837
SONiC-OS-20240510.24
admin@switch:~$ docker exec gnmi gnoi_client -target 127.0.0.1:50052 -logtostderr -insecure -module OS -rpc Activate -jsonin  '{"version": "Foo"}'
OS Activate
{"Response":{"ActivateError":{"type":1,"detail":"Error: Image does not exist\n"}}}

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@mssonicbld
Copy link

/azp run

Copy link

linux-foundation-easycla bot commented Jan 31, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@hdwhdw hdwhdw requested a review from Copilot February 3, 2025 20:49

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 7 changed files in this pull request and generated no comments.

Files not reviewed (2)
  • sonic_service_client/dbus_client_test.go: Evaluated as low risk
  • common_utils/context.go: Evaluated as low risk
Comments suppressed due to low confidence (3)

gnoi_client/os/os.go:35

  • [nitpick] The error message could be more descriptive. Consider changing it to 'Failed to unmarshal JSON: ' + err.Error()'.
panic(err.Error())

gnoi_client/os/os.go:39

  • [nitpick] The error message could be more descriptive. Consider changing it to 'Failed to activate OS: ' + err.Error()'.
panic(err.Error())

gnoi_client/os/os.go:43

  • [nitpick] The error message could be more descriptive. Consider changing it to 'Failed to marshal response: ' + err.Error()'.
panic(err.Error())
@mssonicbld
Copy link

/azp run

@hdwhdw hdwhdw requested a review from Copilot February 3, 2025 20:59
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 8 changed files in this pull request and generated no comments.

Files not reviewed (3)
  • gnoi_client/os/verify.go: Evaluated as low risk
  • common_utils/context.go: Evaluated as low risk
  • gnoi_client/gnoi_client.go: Evaluated as low risk
@hdwhdw hdwhdw marked this pull request as ready for review February 3, 2025 21:35
image := req.GetVersion()
log.Infof("Requested to activate image %s", image)

dbus, err := ssc.NewDbusClient()
Copy link

@xincunli-sonic xincunli-sonic Feb 3, 2025

Choose a reason for hiding this comment

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

dbus

Please call close after the client created?

defer dbus.Close() #Closed

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.

}

var resp gnoi_os_pb.ActivateResponse
err = dbus.ActivateImage(image)

Choose a reason for hiding this comment

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

ActivateImage

The logic checking for "not" and "exist" in err.Error() is fragile. It relies on string matching rather than structured error handling, which may break if error messages change.

Suggestion: If dbus.ActivateImage(image) provides structured error types, check against those instead of relying on string searches.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did try to do this previously but sonic-installer set-next-boot does not provide proper error code (it just return 1 instead, arguably it should return 2 (ENOENT)). The error code is propagated through DBUS and then to GNMI so I have to rely on the message.

I will add a check here and correct this in both host-services and sonic-installer script.

Copy link

@xincunli-sonic xincunli-sonic Feb 4, 2025

Choose a reason for hiding this comment

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

I understand the sonic-installer set-next-boot command line just returned string, what I meant is actual place where calls command line then it did wrap over there.

admin@vslab1:~$ sudo sonic-installer set-next-boot foo
Error: Image does not exist

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doing it in sonic-net/sonic-host-services#210, add a check for errno here. We can still keep the message check in an "either-or" condition just to be doubly safe.

},
}
}
return &resp, nil

Choose a reason for hiding this comment

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

nil

Why would not we return actual error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this is a server error. See https://github.com/openconfig/gnoi/blob/main/os/os.proto#L372, this is an application level error instead of server error.

Choose a reason for hiding this comment

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

But this is server side handling? And since the err is not nil, you did wrap the response, how would the client of this server handle the error, only relying on response?

Choose a reason for hiding this comment

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

Okay, I saw the gnoi_client just handles response. Do you think is there any other caller?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function is a grpc internal server implementation, so the only caller is grpc server. If we return error, that means the grpc handler cannot proceed because we encountered an internal error. "Image not found" is not that and based on the server definition in openconfig, we should report that directly to the client, instead of making it a server failure. Whatever clients want to do with the response error is up to the client.

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -56,6 +56,8 @@ func main() {
switch *config.Rpc {
case "Verify":
gnoi_os.Verify(conn, ctx)
case "Activate":
Copy link
Collaborator

Choose a reason for hiding this comment

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

Activate

wondering whether upstream repo already has a feature rich gnoi_client?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -161,6 +161,56 @@ func (srv *OSServer) Verify(ctx context.Context, req *gnoi_os_pb.VerifyRequest)
return resp, nil
}

func (srv *OSServer) Activate(ctx context.Context, req *gnoi_os_pb.ActivateRequest) (*gnoi_os_pb.ActivateResponse, error) {
_, err := authenticate(srv.config, ctx, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Need RW permission

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.

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants