Adding support for copying socat to the DUTs.#24525
Conversation
Signed-off-by: Raghavendran Ramanathan <rraghav@cisco.com>
Signed-off-by: Raghavendran Ramanathan <rraghav@cisco.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
This PR has backport request for branch(es): 202511. ---Powered by SONiC BuildBot
|
Xichen96
left a comment
There was a problem hiding this comment.
Naming nit on the new fixture — see inline.
|
|
||
|
|
||
| @pytest.fixture(scope="module", autouse=True) | ||
| def prepare_hosts(duthost, fanouthosts, tbinfo): |
There was a problem hiding this comment.
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)?
| 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.
| f"Couldnot find the console fanout for the DUT:{duthost}. " | ||
| "Pls fix the ansible files, there should be atleast one " | ||
| "console fanout.") |
There was a problem hiding this comment.
Few typos that'd be worth cleaning up since this message lands verbatim in lab triage tickets and pytest failure output:
Couldnot->Could notPls->Pleaseatleast->at least
| 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.") |
| .format(len(console_facts["lines"]))) | ||
|
|
||
| return duthost, console_fanout | ||
| if console_fanout is None: |
There was a problem hiding this comment.
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.
| assert host.shell("socat -V", module_ignore_errors=True)["rc"] == 0, \ | ||
| f"socat installation failed on DUT host:{host}" |
There was a problem hiding this comment.
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:
| 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>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Raghavendran Ramanathan <rraghav@cisco.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
I'm considering we no longer need to copy socat to DUT after this PR is backport to 202603: sonic-net/sonic-buildimage#25525 |
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
Back port request
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: