Skip to content

Adding support for copying socat to the DUTs.#24525

Open
rraghav-cisco wants to merge 4 commits into
sonic-net:masterfrom
rraghav-cisco:copy-socat-2
Open

Adding support for copying socat to the DUTs.#24525
rraghav-cisco wants to merge 4 commits into
sonic-net:masterfrom
rraghav-cisco:copy-socat-2

Conversation

@rraghav-cisco
Copy link
Copy Markdown
Contributor

Copy of #23595 since it is messed up.

Description of PR

Sometimes the console script execute the "socat" command in dut or console-fanout. But the socat executable is not copied to the hosts. This fixture is to copy the socat from tests/console/socat to the DUTs and console-fanouts.

Summary:
Fixes issues where socat is needed, but not yet available in the fanouts.

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • New Test case
    • Skipped for non-supported platforms
  • Test case improvement

Back port request

  • 202205
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511

Approach

What is the motivation for this PR?

The tests execute socat without copyting the required executable.

How did you do it?

Added a new fixture to the console/conftest.py folder.

How did you verify/test it?

Ran a couple of tests:

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
====================================================================================================================== PASSES =======================================================================================================================
________________________________________________________________________________________________________ test_console_link_wiring[115200-40] ________________________________________________________________________________________________________
----------------------------------------- generated xml file: /run_logs/tb3/copy-socat/2026-04-03-02-41-42/console/test_console_link_wiring.py::test_console_link_wiring[115200-40]_2026-04-03-02-41-42.xml -----------------------------------------
INFO:root:Can not get Allure report URL. Please check logs
============================================================================================================== short test summary info ==============================================================================================================
PASSED console/test_console_link_wiring.py::test_console_link_wiring[115200-40]
===================================================================================================== 1 passed, 1 warning in 215.98s (0:03:35) ======================================================================================================
sonic@arctos_cicd_TB3_double_console_202511:/data/tests$ 

Signed-off-by: Raghavendran Ramanathan <rraghav@cisco.com>
Comment thread tests/console/conftest.py Fixed
Signed-off-by: Raghavendran Ramanathan <rraghav@cisco.com>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld mssonicbld added the Request for 202511 branch Request to backport a change to 202511 branch label May 12, 2026
@mssonicbld
Copy link
Copy Markdown
Collaborator

This PR has backport request for branch(es): 202511.
Added label(s) for branch(es) 202511.

---Powered by SONiC BuildBot

Copy link
Copy Markdown
Contributor

@Xichen96 Xichen96 left a comment

Choose a reason for hiding this comment

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

Naming nit on the new fixture — see inline.

Comment thread tests/console/conftest.py Outdated


@pytest.fixture(scope="module", autouse=True)
def prepare_hosts(duthost, fanouthosts, tbinfo):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixture name prepare_hosts is too generic — at a glance it reads like a topology fixture, not a binary-install one. Could you rename so the name carries the side-effect, and include the c0 scope (consistent with setup_c0 in this file)?

Suggested change
def prepare_hosts(duthost, fanouthosts, tbinfo):
def install_socat_on_c0_hosts(duthost, fanouthosts, tbinfo):

This will surface in pytest's setup/teardown logs; being explicit there helps when triaging.

Copy link
Copy Markdown
Contributor

@Xichen96 Xichen96 left a comment

Choose a reason for hiding this comment

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

A few more nits while you're touching this - low priority, but cheap wins.

Comment thread tests/console/conftest.py Outdated
Comment on lines +65 to +67
f"Couldnot find the console fanout for the DUT:{duthost}. "
"Pls fix the ansible files, there should be atleast one "
"console fanout.")
Copy link
Copy Markdown
Contributor

@Xichen96 Xichen96 May 13, 2026

Choose a reason for hiding this comment

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

Few typos that'd be worth cleaning up since this message lands verbatim in lab triage tickets and pytest failure output:

  • Couldnot -> Could not
  • Pls -> Please
  • atleast -> at least
Suggested change
f"Couldnot find the console fanout for the DUT:{duthost}. "
"Pls fix the ansible files, there should be atleast one "
"console fanout.")
f"Could not find the console fanout for the DUT:{duthost}. "
"Please fix the ansible files, there should be at least one "
"console fanout.")

Comment thread tests/console/conftest.py Outdated
.format(len(console_facts["lines"])))

return duthost, console_fanout
if console_fanout is None:
Copy link
Copy Markdown
Contributor

@Xichen96 Xichen96 May 13, 2026

Choose a reason for hiding this comment

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

Optional, low-priority structural cleanup: the trailing if console_fanout is None: pytest.fail(...) block (lines 63-67) is dead code. The if/elif/else above already exhausts every case - each branch either assigns console_fanout or calls pytest.fail(). The check exists only to silence the CodeQL false positive on line 52 (console_fanout = None).

An early-return shape lets the analyzer see exhaustion naturally - no console_fanout = None init and no defensive trailing block needed:

def get_console_fanout(duthost, fanouthosts, tbinfo):
    if tbinfo["topo"]["name"] == "c0":
        console_fanouts = list(filter(
            lambda fh: fh.get_fanout_os() == 'sonic' and fh.is_console_switch(),
            fanouthosts.values()))
        if len(console_fanouts) != 1:
            pytest.fail(...)   # keep existing message
        return console_fanouts[0]
    if tbinfo["topo"]["name"] == "c0-lo":
        return duthost
    pytest.fail("Test requires c0 or c0-lo topology")

Leaving as a discussion point - pushing back is reasonable since CodeQL is already satisfied with the current shape.

Comment thread tests/console/conftest.py Outdated
Comment on lines +111 to +112
assert host.shell("socat -V", module_ignore_errors=True)["rc"] == 0, \
f"socat installation failed on DUT host:{host}"
Copy link
Copy Markdown
Contributor

@Xichen96 Xichen96 May 13, 2026

Choose a reason for hiding this comment

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

sonic-mgmt convention in fixtures/tests is pytest_assert (from tests.common.helpers.assertions) rather than the built-in assert - it formats failures more consistently with the rest of the suite:

Suggested change
assert host.shell("socat -V", module_ignore_errors=True)["rc"] == 0, \
f"socat installation failed on DUT host:{host}"
pytest_assert(
host.shell("socat -V", module_ignore_errors=True)["rc"] == 0,
f"socat installation failed on DUT host:{host}")

Will also need from tests.common.helpers.assertions import pytest_assert at the top of the file (doesn't look like it's imported yet).

Signed-off-by: Raghavendran Ramanathan <rraghav@cisco.com>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@github-actions github-actions Bot requested a review from Xichen96 May 13, 2026 16:22
Signed-off-by: Raghavendran Ramanathan <rraghav@cisco.com>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@lizhijianrd
Copy link
Copy Markdown
Contributor

I'm considering we no longer need to copy socat to DUT after this PR is backport to 202603: sonic-net/sonic-buildimage#25525

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Request for 202511 branch Request to backport a change to 202511 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants