Skip to content

Add CsonicHost for docker-exec based neighbor access in cSONiC testbeds#22705

Open
securely1g wants to merge 1 commit intosonic-net:masterfrom
securely1g:add-csonic-host
Open

Add CsonicHost for docker-exec based neighbor access in cSONiC testbeds#22705
securely1g wants to merge 1 commit intosonic-net:masterfrom
securely1g:add-csonic-host

Conversation

@securely1g
Copy link

Description

cSONiC (docker-sonic-vs) neighbor containers run as Docker containers on the VM host — they have no SSH daemon, no admin user, and no management IP. This makes the existing SonicHost class (which requires Ansible/SSH connectivity) unusable for cSONiC neighbors.

This PR adds CsonicHost, a lightweight host class that executes commands via docker exec (subprocess) instead of SSH, providing the same command()/shell() interface that tests expect from neighbor hosts.

Motivation

When running sonic-mgmt tests with --neighbor_type sonic on a cSONiC testbed, the nbrhosts fixture fails at setup because SonicHost.__init__() tries to SSH into each neighbor and gather facts. With --neighbor_type csonic, tests can now access cSONiC neighbors without SSH infrastructure.

Changes

  • tests/common/devices/csonic.py (new): CsonicHost class with:

    • command() / shell() — run commands via docker exec, returns Ansible-compatible dict (stdout, stdout_lines, rc, etc.)
    • shutdown() / no_shutdown() — interface up/down via ip link set
    • get_route() — query FRR routing table via vtysh
    • get_port_channel_status() — query teamd state
    • config() — configure FRR via vtysh
    • Supports both local and remote (SSH-tunneled) Docker hosts
  • tests/conftest.py:

    • Add csonic to --neighbor_type choices
    • Create CsonicHost instances in nbrhosts fixture using container naming convention csonic_{group-name}_{vm_name}
    • Include csonic in techsupport collection check
  • tests/vlan/test_vlan_ping.py:

    • Handle cSONiC interface naming (PortChannel1 instead of po1, Ethernet0 instead of eth1) when --neighbor_type csonic

Usage

# Run tests against cSONiC testbed
pytest --neighbor_type csonic --testbed vms-kvm-t0-csonic ...

Test Results

Tested on cSONiC KVM testbed (T0 topology, 4 docker-sonic-vs neighbors with PortChannels):

Test Result
vlan/test_vlan_ping ✅ PASSED
bgp/test_bgp_fact ✅ PASSED
bgp/test_frr_config_check ✅ PASSED
crm/test_crm_next_hop_group ✅ PASSED
lldp/test_lldp ✅ PASSED

Related PRs

cSONiC (docker-sonic-vs) neighbor containers don't have SSH access,
admin users, or management IPs — they are Docker containers on the
VM host, not full VMs. This makes the existing SonicHost class
(which requires SSH/Ansible connectivity) unusable for cSONiC neighbors.

Add CsonicHost, a lightweight host class that executes commands via
'docker exec' instead of SSH. This provides the same command/shell
interface that tests expect from neighbor hosts.

Changes:
- tests/common/devices/csonic.py: New CsonicHost class with command(),
  shell(), shutdown(), no_shutdown(), get_route(), get_port_channel_status(),
  and config() methods, all backed by 'docker exec' via subprocess
- tests/conftest.py: Add 'csonic' to --neighbor_type choices; create
  CsonicHost instances in nbrhosts fixture using container naming
  convention 'csonic_{group-name}_{vm_name}'
- tests/vlan/test_vlan_ping.py: Handle cSONiC interface naming
  (PortChannel1 instead of po1, Ethernet0 instead of eth1)

Tested on cSONiC KVM testbed (T0, 4 docker-sonic-vs neighbors):
  pytest --neighbor_type csonic
  - vlan/test_vlan_ping: PASSED
  - bgp/test_bgp_fact: PASSED (with --neighbor_type sonic)
  - lldp/test_lldp: PASSED (with --neighbor_type sonic)

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

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@securely1g
Copy link
Author

Hi @wangxin @hdwhdw — would appreciate your review on this PR.

@wangxin A few questions for you:

  1. Reuse SonicHost vs separate CsonicHost: Do you think it would be better to extend SonicHost to support cSONiC containers (e.g., with a docker_exec transport mode) rather than introducing a new CsonicHost class? The reason I went with a separate class is that SonicHost.__init__() does heavy lifting at init time (SSH connection, _gather_facts(), _get_os_version(), get_running_config_facts(), etc.) that all assumes Ansible/SSH connectivity. cSONiC containers have no SSH daemon, no admin user, and no management IP — they're Docker containers accessed via docker exec. That said, if you prefer consolidating into SonicHost with a transport abstraction, I'm happy to refactor.

  2. Scope: CsonicHost is intended only for neighbor devices in cSONiC testbeds, not as a DUT host. The DUT is still a full SONiC VS VM managed by SonicHost. The cSONiC neighbors are lightweight docker-sonic-vs containers that only need basic command execution (get MAC, check interfaces, etc.).

  3. Unit tests: Is there a unit test framework for the tests/common/ folder (especially tests/common/devices/)? I'd like to add tests for CsonicHost if there's an existing pattern to follow.

@hdwhdw — since you've been working on the cSONiC testbed infrastructure, would love your thoughts on this approach as well.

@hdwhdw hdwhdw self-requested a review March 3, 2026 22:13
kazinator-arista pushed a commit to kazinator-arista/sonic-mgmt that referenced this pull request Mar 4, 2026
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