Skip to content

gNOI: Add ConfigSave and ConfigReload RPCs on SonicService - #728

Open
Verma-Anukul wants to merge 1 commit into
sonic-net:masterfrom
Verma-Anukul:upstream/41331-gnoi-config-save-reload
Open

Verma-Anukul wants to merge 1 commit into
sonic-net:masterfrom
Verma-Anukul:upstream/41331-gnoi-config-save-reload

Conversation

@Verma-Anukul

@Verma-Anukul Verma-Anukul commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Expose SONiC config save and config reload over gNOI on gnoi.sonic.SonicService.

Before

No gNOI RPC existed for persisting or reloading configuration. Operators had to use the CLI or SSH.

After

Two new RPCs call existing host-service D-Bus methods directly:

  • ConfigSave → persists running CONFIG_DB to /etc/sonic/config_db.json
  • ConfigReload → reloads from startup file, or from inline JSON when provided

Logs

admin@sonic:~$ 
admin@sonic:~$ redis-cli -n 4
127.0.0.1:6379[4]> 
127.0.0.1:6379[4]> HSET DEVICE_METADATA|localhost frr_mgmt_framework_config "true" docker_routing_config_mode "unified"
(integer) 2
127.0.0.1:6379[4]> HSET GNMI|gnmi "client_auth" "false" "port" 8080 "save_on_set" "true"
(integer) 3
127.0.0.1:6379[4]> HSET "MGMT_VRF_CONFIG|vrf_global" "mgmtVrfEnabled" "true"
(integer) 1
127.0.0.1:6379[4]> HSET NTP|global admin_state enabled authentication disabled dhcp enabled server_role disabled src_intf eth0 vrf default
(integer) 0
127.0.0.1:6379[4]> exit
admin@sonic:~$ 
admin@sonic:~$ sudo cat /etc/sonic/config_db.json | grep GNMI
admin@sonic:~$ sudo cat /etc/sonic/config_db.json | grep MGMT_VRF_CONFIG
admin@sonic:~$ sudo cat /etc/sonic/config_db.json | grep frr_mgmt_framework_config
admin@sonic:~$ 
admin@sonic:~$ 
admin@sonic:~$ docker exec -it gnmi bash
root@sonic:/# 
root@sonic:/#  gnoi_client  -notls -insecure -module Sonic -rpc ConfigSave
panic: Invalid RPC Name

goroutine 1 [running]:
main.main()
        /sonic/src/sonic-gnmi/gnoi_client/gnoi_client.go:127 +0xac5
root@sonic:/# 
root@sonic:/#  gnoi_client  -notls -insecure -module Sonic -rpc configSave
Sonic ConfigSave
{"sonic-config-mgmt:output":{"status-detail":""}}
root@sonic:/# 
root@sonic:/# exit
exit
admin@sonic:~$ 
admin@sonic:~$ sudo cat /etc/sonic/config_db.json | grep GNMI
    "GNMI": {
admin@sonic:~$ 
admin@sonic:~$ sudo cat /etc/sonic/config_db.json | grep MGMT_VRF_CONFIG
    "MGMT_VRF_CONFIG": {
admin@sonic:~$ 
admin@sonic:~$ sudo cat /etc/sonic/config_db.json | grep frr_mgmt_framework_config
            "frr_mgmt_framework_config": "true",
admin@sonic:~$ 
admin@sonic:~$ docker exec -it gnmi bash
root@sonic:/# 
root@sonic:/#  gnoi_client  -notls -insecure -module Sonic -rpc configReload
Sonic ConfigReload
panic: rpc error: code = Unavailable desc = error reading from server: EOF

goroutine 1 [running]:
github.com/sonic-net/sonic-gnmi/gnoi_client/sonic.ConfigReload(0xc00020c400, {0xb5fbf8, 0xc000091e80})
        /sonic/src/sonic-gnmi/gnoi_client/sonic/sonic.go:169 +0x265
main.main()
        /sonic/src/sonic-gnmi/gnoi_client/gnoi_client.go:125 +0x5ca
root@sonic:/# admin@sonic:~$ 
admin@sonic:~$ 
admin@sonic:~$ docker ps -a
CONTAINER ID   IMAGE                                COMMAND                  CREATED          STATUS                      PORTS     NAMES
92e9da11c324   docker-snmp:latest                   "/usr/bin/docker-snm…"   14 minutes ago   Exited (0) 3 seconds ago              snmp
104ae6556fc3   docker-platform-monitor:latest       "/usr/bin/docker_ini…"   14 minutes ago   Exited (0) 3 seconds ago              pmon
44e084044de9   docker-sonic-mgmt-framework:latest   "/usr/local/bin/supe…"   14 minutes ago   Exited (0) 9 seconds ago              mgmt-framework
a76a69dc5644   docker-lldp:latest                   "/usr/bin/docker-lld…"   14 minutes ago   Up 9 minutes                          lldp
7a25eac15969   docker-sonic-gnmi:latest             "/usr/local/bin/supe…"   14 minutes ago   Exited (0) 9 seconds ago              gnmi
b3711664fb4b   docker-dhcp-relay:latest             "/usr/bin/docker_ini…"   15 minutes ago   Exited (0) 6 seconds ago              dhcp_relay
231eea3ea98a   docker-router-advertiser:latest      "/usr/bin/docker-ini…"   15 minutes ago   Exited (0) 8 seconds ago              radv
8b0d054291f4   docker-stp:latest                    "/usr/local/bin/supe…"   15 minutes ago   Exited (0) 7 seconds ago              stp
ba8fa278b248   docker-syncd-cisco:latest            "/usr/local/bin/supe…"   15 minutes ago   Up 10 minutes                         syncd
2806027fad11   docker-eventd:latest                 "/usr/local/bin/supe…"   15 minutes ago   Exited (0) 8 seconds ago              eventd
47e9b9a7d423   docker-fpm-frr:latest                "/usr/bin/docker_ini…"   15 minutes ago   Exited (0) 4 seconds ago              bgp
b3a3dba9dfc8   docker-teamd:latest                  "/usr/local/bin/supe…"   15 minutes ago   Exited (0) 1 second ago               teamd
aa507915fb13   docker-apm:latest                    "/usr/bin/docker-apm…"   15 minutes ago   Exited (0) 9 seconds ago              apm
f87cff320bfe   docker-sysmgr:latest                 "/usr/local/bin/supe…"   15 minutes ago   Exited (0) 10 seconds ago             sysmgr
9e37adccb603   docker-orchagent:latest              "/usr/bin/docker-ini…"   15 minutes ago   Up 10 minutes                         swss
74edfeb00422   docker-database:latest               "/usr/local/bin/dock…"   16 minutes ago   Up 10 minutes                         database
admin@sonic:~$ 
admin@sonic:~$ 
admin@sonic:~$ 
admin@sonic:~$ docker ps -a
CONTAINER ID   IMAGE                                COMMAND                  CREATED          STATUS              PORTS     NAMES
92e9da11c324   docker-snmp:latest                   "/usr/bin/docker-snm…"   17 minutes ago   Up About a minute             snmp
104ae6556fc3   docker-platform-monitor:latest       "/usr/bin/docker_ini…"   17 minutes ago   Up About a minute             pmon
44e084044de9   docker-sonic-mgmt-framework:latest   "/usr/local/bin/supe…"   17 minutes ago   Up About a minute             mgmt-framework
a76a69dc5644   docker-lldp:latest                   "/usr/bin/docker-lld…"   17 minutes ago   Up About a minute             lldp
7a25eac15969   docker-sonic-gnmi:latest             "/usr/local/bin/supe…"   17 minutes ago   Up About a minute             gnmi
b3711664fb4b   docker-dhcp-relay:latest             "/usr/bin/docker_ini…"   18 minutes ago   Up 2 minutes                  dhcp_relay
231eea3ea98a   docker-router-advertiser:latest      "/usr/bin/docker-ini…"   18 minutes ago   Up 2 minutes                  radv
8b0d054291f4   docker-stp:latest                    "/usr/local/bin/supe…"   18 minutes ago   Up 2 minutes                  stp
ba8fa278b248   docker-syncd-cisco:latest            "/usr/local/bin/supe…"   18 minutes ago   Up 2 minutes                  syncd
2806027fad11   docker-eventd:latest                 "/usr/local/bin/supe…"   18 minutes ago   Up 2 minutes                  eventd
47e9b9a7d423   docker-fpm-frr:latest                "/usr/bin/docker_ini…"   18 minutes ago   Up 2 minutes                  bgp
b3a3dba9dfc8   docker-teamd:latest                  "/usr/local/bin/supe…"   19 minutes ago   Up 2 minutes                  teamd
aa507915fb13   docker-apm:latest                    "/usr/bin/docker-apm…"   19 minutes ago   Up 2 minutes                  apm
f87cff320bfe   docker-sysmgr:latest                 "/usr/local/bin/supe…"   19 minutes ago   Up 2 minutes                  sysmgr
9e37adccb603   docker-orchagent:latest              "/usr/bin/docker-ini…"   19 minutes ago   Up 2 minutes                  swss
74edfeb00422   docker-database:latest               "/usr/local/bin/dock…"   19 minutes ago   Up 13 minutes                 database
admin@sonic:~$ 
admin@sonic:~$ sudo cat /etc/sonic/config_db.json | grep GNMI
    "GNMI": {
admin@sonic:~$ sudo cat /etc/sonic/config_db.json | grep MGMT_VRF_CONFIG
    "MGMT_VRF_CONFIG": {
admin@sonic:~$ sudo cat /etc/sonic/config_db.json | grep frr_mgmt_framework_config
            "frr_mgmt_framework_config": "true",
admin@sonic:~$ 

Test plan

  • go test ./gnmi_server/... -run 'TestConfigSave|TestConfigReload'
  • gnoi_client -module Sonic -rpc configSave
  • gnoi_client -module Sonic -rpc configReload (empty and inline JSON)

…t#55)

* MIGSOFTWAR-41331: Add gNOI ConfigSave and ConfigReload RPCs

Expose `config save` (running -> startup) and `config reload` over gNOI
on the SONiC-specific `gnoi.sonic.SonicService`. The handlers call the
existing host-service D-Bus methods directly (no translib indirection):

  - SonicService.ConfigSave   -> org.SONiC.HostService.config.save
  - SonicService.ConfigReload -> org.SONiC.HostService.config.reload

ConfigSave is parameterless and always persists the running CONFIG_DB to
/etc/sonic/config_db.json. ConfigReload accepts an optional inline JSON
payload; when empty the host service reloads from the startup file,
otherwise the JSON is validated and piped to `config reload -y /dev/stdin`.
Both RPCs require write-level gNOI authentication and surface backend
failures as gRPC error codes. The raw reload payload is never logged
(CONFIG_DB may carry credentials); only an inline=<bool> marker is.

Also wires both RPCs into the gnoi_client CLI under -module Sonic
(`configSave`, `configReload`) and adds reachability tests covering the
empty-payload and inline-JSON branches.

Backend D-Bus methods already exist in upstream sonic-host-services, so
no host-side changes are required.

* MIGSOFTWAR-41331: Address review feedback on gNOI ConfigSave/ConfigReload

Style and structure refinements following review:

  - gnmi_server/gnoi.go
      * Drop the locally-introduced defaultStartupConfigPath constant; no
        such constant exists elsewhere in sonic-buildimage and the rest
        of sonic-gnmi (server.go SaveOnSetEnabled, mixed_db_client.go)
        uses the literal "/etc/sonic/config_db.json". Use the same
        literal for consistency.
      * Trim the multi-line doc comments on ConfigSave / ConfigReload to
        the 1-2 line style used by sibling RPCs in this file.
      * Drop the filename from the ConfigSave log line; sibling
        SonicService RPCs log only "gNOI: Sonic <Name>".

  - gnmi_server/gnoi_config_test.go (new)
      * Move tests out of clear_neighbor_dummy_test.go (which is marked
        for removal) into a dedicated gnoi_config_test.go.
      * Replace the dummy reachability tests with proper unit tests
        modeled on gnoi_reset_test.go: gomonkey-patch ssc.NewDbusClient
        and ssc.DbusApi to cover success, DBus-client-creation failure,
        DBus-call failure, and (for ConfigReload) the empty-payload,
        inline-JSON, and InvalidArgument paths.

  - gnmi_server/clear_neighbor_dummy_test.go
      * Reverted to the upstream baseline (the ConfigSave/ConfigReload
        dummy tests have moved to gnoi_config_test.go).

The error-code conventions, no-defer-Close, and SonicOutput response
shape continue to follow the closest analog (factory_reset.Start in
gnoi_reset.go) which is the only other gNOI RPC in this codebase that
calls a host-service D-Bus method directly rather than going through
translib.

* MIGSOFTWAR-41331: Extract defaultConfigDBPath const and rename test file

  - gnmi_server/gnoi.go
      * Add defaultConfigDBPath const ("/etc/sonic/config_db.json") to the
        existing const block (alongside stateDB, mirroring its style).
      * Use the const in ConfigSave instead of repeating the literal.

  - gnmi_server/{gnoi_config_test.go => sonic_config_test.go}
      * Rename via git mv (content unchanged). The old name suggested a
        standard gNOI service test (sibling to gnoi_reset_test.go,
        gnoi_os_test.go, gnoi_file_test.go, ...), but ConfigSave/
        ConfigReload are extensions on the SONiC-specific SonicService.
        The new name follows the existing SonicService test convention
        (cf. clear_neighbor_dummy_test.go for SonicService.ClearNeighbors)
        of using a feature-based name without the gnoi_ prefix.

* MIGSOFTWAR-41331: Rename test file to sonic_config_service_test.go

The previous name (sonic_config_test.go) was ambiguous and could be
misread as testing SONiC configuration in general. The new name makes
it explicit that the file tests RPCs on the gnoi.sonic SonicService
(currently ConfigSave and ConfigReload).

Signed-off-by: Verma-Anukul <anukulverma2013@gmail.com>
@mssonicbld

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@Verma-Anukul Verma-Anukul changed the title Add gNOI ConfigSave and ConfigReload RPCs gNOI: Add ConfigSave and ConfigReload RPCs on SonicService Aug 4, 2026
@Verma-Anukul

Copy link
Copy Markdown
Contributor Author

@hdwhdw
Please review this PR

@mssonicbld

Copy link
Copy Markdown
Contributor

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

@Verma-Anukul

Copy link
Copy Markdown
Contributor Author

@hdwhdw
Please review this PR

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.

2 participants