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
@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).

if err != nil {
log.Errorf("Failed to activate image %s: %v", image, err)
image_not_exists := os.IsNotExist(err) ||
(strings.Contains(strings.ToLower(err.Error()), "not") &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

even with string check, could we use complete string match instead of "not" && "exist" which will have more corner cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My main concern is error string equality check can easily have false negatives, say someone just remove a redundant space or any minor changes to the error string. Being that specific can make maintaining backend code difficult.

Copy link

@xincunli-sonic xincunli-sonic left a comment

Choose a reason for hiding this comment

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

LGTM

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.

6 participants