Skip to content

Add support for gNOI File Remove#167

Open
jkmar wants to merge 2 commits intosonic-net:masterfrom
jkmar:gnoi_file_remove
Open

Add support for gNOI File Remove#167
jkmar wants to merge 2 commits intosonic-net:masterfrom
jkmar:gnoi_file_remove

Conversation

@jkmar
Copy link
Copy Markdown

@jkmar jkmar commented May 2, 2025

Add support for gNOI File Remove.
Other PRs:

@mssonicbld
Copy link
Copy Markdown

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@jkmar jkmar force-pushed the gnoi_file_remove branch from 4add408 to 1914691 Compare May 2, 2025 12:18
@mssonicbld
Copy link
Copy Markdown

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@jkmar
Copy link
Copy Markdown
Author

jkmar commented May 14, 2025

@anders-nexthop
Copy link
Copy Markdown

The other two PRs have been closed, is this one still needed?

sonic-gnmi: sonic-net/sonic-gnmi#387
sonic-host-services: sonic-net/sonic-host-services#248

@lihuay lihuay requested a review from Copilot April 4, 2026 14:34
@mssonicbld
Copy link
Copy Markdown

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new SONiC YANG RPC and translib transformer callback to support the gNOI File Remove workflow (coordinated with sonic-gnmi and sonic-host-services PRs).

Changes:

  • Introduces a new YANG module sonic-file-mgmt defining an RPC remove with remote_file input.
  • Adds a YANG annotation module wiring the RPC to a translib RPC callback (rpc_file_remove_cb).
  • Implements the translib RPC callback that forwards the request to host services via D-Bus (HostQuery("file.remove", ...)).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
translib/transformer/xfmr_sonic_file_mgmt.go Adds RPC callback implementation for file remove via HostQuery/D-Bus.
models/yang/sonic/sonic-file-mgmt.yang Defines the new sonic-file-mgmt RPC schema (remove, remote_file).
models/yang/annotations/sonic-file-mgmt-annot.yang Binds the YANG RPC to the translib callback using sonic-ext:rpc-callback.

Comment on lines +36 to +38
var operand struct {
RemoteFile string `json:"remote_file"`
}
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

RPC input unmarshalling doesn't match the JSON structure used by existing RPC callbacks (e.g., xfmr_showtech.go expects a top-level ":input" wrapper). With the current struct tags, operand.RemoteFile will remain empty for RFC7951-style payloads, causing the HostQuery to be invoked with an empty path. Update the operand struct to unmarshal the module-qualified input container and extract remote_file from there.

Copilot uses AI. Check for mistakes.
Comment on lines +47 to +52
result, _ := json.Marshal(&output)

host_output := HostQuery("file.remove", operand.RemoteFile)
if host_output.Err != nil {
glog.Errorf("Error: File Remove host Query failed: err=%v", host_output.Err)
return nil, host_output.Err
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

remote_file is not validated after parsing. If the field is missing/empty (including due to input unmarshalling issues), the code will call HostQuery("file.remove", ""), which can lead to unintended behavior. Reject empty remote_file with tlerr.InvalidArgs (and ideally include which field is missing).

Copilot uses AI. Check for mistakes.
Comment on lines +54 to +55
if host_output.Body[0].(int32) != 0 {
err = tlerr.New(host_output.Body[1].(string))
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

The code assumes host_output.Body has at least two elements and that they are (int32, string). Since HostQuery returns a raw []interface{} from D-Bus, these direct index accesses and type assertions can panic if the host service returns a different signature or an empty body. Add length checks and safe type assertions (with an internal error if the response shape is unexpected).

Suggested change
if host_output.Body[0].(int32) != 0 {
err = tlerr.New(host_output.Body[1].(string))
if len(host_output.Body) < 2 {
err = tlerr.New("Internal error: unexpected response from file.remove host service")
glog.Errorf("Error: File Remove host Query returned invalid body length=%d", len(host_output.Body))
return nil, err
}
status, ok := host_output.Body[0].(int32)
if !ok {
err = tlerr.New("Internal error: unexpected response from file.remove host service")
glog.Errorf("Error: File Remove host Query returned invalid status type=%T", host_output.Body[0])
return nil, err
}
msg, ok := host_output.Body[1].(string)
if !ok {
err = tlerr.New("Internal error: unexpected response from file.remove host service")
glog.Errorf("Error: File Remove host Query returned invalid message type=%T", host_output.Body[1])
return nil, err
}
if status != 0 {
err = tlerr.New(msg)

Copilot uses AI. Check for mistakes.

rpc remove {
description
"Remove removes the specified file from the target";
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

The rpc description text "Remove removes the specified file..." is grammatically awkward/redundant. Consider rewording to something like "Remove deletes the specified file from the target" to improve clarity in generated docs/clients.

Suggested change
"Remove removes the specified file from the target";
"Remove deletes the specified file from the target";

Copilot uses AI. Check for mistakes.
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