Skip to content

[cSONiC] Make show CLI work in docker-sonic-vs neighbors (no nested docker/rvtysh)#4633

Open
securely1g wants to merge 1 commit into
sonic-net:masterfrom
securely1g:fix/csonic-show-cli-docker-rvtysh
Open

[cSONiC] Make show CLI work in docker-sonic-vs neighbors (no nested docker/rvtysh)#4633
securely1g wants to merge 1 commit into
sonic-net:masterfrom
securely1g:fix/csonic-show-cli-docker-rvtysh

Conversation

@securely1g

Copy link
Copy Markdown
Contributor

Why I did it

In docker-sonic-vs containers used as cSONiC neighbors in the sonic-mgmt KVM testbed, FRR runs inside the same container — there is no nested bgp docker container and no rvtysh wrapper. Two sonic-utilities code paths assume the real-SONiC layout, so every relevant show command either leaks an error to stderr or fails outright:

  1. show/main.py::get_routing_stack() runs a sudo docker ps ... one-liner at module import time (routing_stack = get_routing_stack() global). It therefore executes on every show invocation — even show ... --help — printing:

    sudo: docker: command not found
    

    The try/except does default to 'frr', so the value is correct, but the stderr leak is unconditional. The function's own # To be enhanced comment already flags this one-liner as undesirable.

  2. utilities_common/bgp_util.py::run_bgp_show_command() uses RVTYSH_COMMAND = 'rvtysh', the routing-stack-aware wrapper that docker execs into the bgp container on real SONiC. In docker-sonic-vs the wrapper does not exist, so commands fail with:

    sudo: rvtysh: command not found
    

In a cSONiC neighbor only the plain vtysh binary exists (command -v rvtysh → not found; command -v vtysh/usr/bin/vtysh).

Resolves #4632. This is the sonic-utilities counterpart to the cSONiC neighbor-environment gaps tracked in sonic-mgmt (e.g. #22647, #22648).

How I did it

  • get_routing_stack(): short-circuit and return the default 'frr' when the docker binary is not present (shutil.which('docker') is None), so the bash one-liner never runs on single-container images and no stderr is leaked. Behavior on real SONiC (docker present) is unchanged.
  • run_bgp_show_command(): select the vtysh wrapper at runtime — use rvtysh when it is present in PATH (real SONiC), otherwise fall back to the plain vtysh binary (docker-sonic-vs). No change to the argv/return contract.
  • Added unit tests in tests/show_test.py (TestCsonicNeighborEnv) covering both docker-present/absent paths of get_routing_stack() and both rvtysh-present/absent paths of run_bgp_show_command().

How to verify it

Run the new unit tests:

pytest tests/show_test.py -k TestCsonicNeighborEnv

Manual verification on a live cSONiC neighbor (docker-sonic-vs) — before vs after this change:

Before:

# show ip --help        -> "sudo: docker: command not found" (leaked on stderr)
# show ip route         -> "sudo: rvtysh: command not found"
# show ip bgp summary   -> error / no output

After (verified):

# show ip --help        -> clean, no stderr leak
# show ip route         -> full FRR routing table
# show ip bgp summary   -> full IPv4 Unicast BGP summary (4 neighbors, real PfxRcd)

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

Description for the changelog

Make the show CLI work in docker-sonic-vs (cSONiC) neighbor containers: skip the docker ps routing-stack probe when docker is absent, and fall back from rvtysh to vtysh when the rvtysh wrapper is not present.

…ocker/rvtysh)

In docker-sonic-vs containers used as cSONiC neighbors in the sonic-mgmt
KVM testbed, FRR runs in the same container: there is no nested 'bgp'
docker container and no 'rvtysh' wrapper. Two code paths assumed the
real-SONiC layout and leaked errors / failed on every relevant 'show':

1. show/main.py::get_routing_stack() runs 'sudo docker ps ...' at module
   import time, so every 'show' invocation (even --help) printed
   'sudo: docker: command not found'. Skip the one-liner when the docker
   binary is absent and keep the default 'frr'.

2. utilities_common/bgp_util.py::run_bgp_show_command() uses the 'rvtysh'
   wrapper, which execs into the nested bgp container on real SONiC. When
   'rvtysh' is not in PATH, fall back to the plain 'vtysh' binary so
   commands like 'show ip route' / 'show ip bgp summary' work instead of
   failing with 'sudo: rvtysh: command not found'.

Added unit tests in tests/show_test.py covering both the docker-present
and docker-absent paths for get_routing_stack(), and the rvtysh-present
and rvtysh-absent fallback for run_bgp_show_command().

Verified live on a cSONiC neighbor (docker-sonic-vs): 'show ip route' and
'show ip bgp summary' now return full output with no stderr leaks.

Fixes sonic-net#4632

Signed-off-by: securely1g <securely1g@users.noreply.github.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
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

csonic Issues related to cSONiC (docker-sonic-vs) neighbors in KVM testbed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cSONiC] show CLI leaks 'docker'/'rvtysh' not-found errors in docker-sonic-vs neighbors (nested-Docker routing-stack assumption)

2 participants