Skip to content

Update _strip_str to remove null characters#703

Open
wenyiz2021 wants to merge 2 commits into
masterfrom
wenyiz/fix_strip_method
Open

Update _strip_str to remove null characters#703
wenyiz2021 wants to merge 2 commits into
masterfrom
wenyiz/fix_strip_method

Conversation

@wenyiz2021

@wenyiz2021 wenyiz2021 commented Jul 1, 2026

Copy link
Copy Markdown

Modify _strip_str method to remove null characters.
e.g.sudo redis-cli -n 6 HGET 'TRANSCEIVER_INFO|Ethernet0' manufacturer | xxd | head -5;

The redis value stored is:
41 00 00 00 00 00 4e 65 74 77 6f 72 6b 73
A \0 \0 \0 \0 \0 N e t w o r k s

this is causing test_snmp_phy_entity to fail because of failing to parse the \0 above.

>           assert transceiver_snmp_fact['entPhysMfgName'] == transceiver_info['manufacturer'], (
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                'Transceiver manufacturer name mismatch. Expected "entPhysMfgName" to be {}, '
                'but got {}. '
            ).format(
                transceiver_info['manufacturer'],
                transceiver_snmp_fact['entPhysMfgName']
            )
E           AssertionError: Transceiver manufacturer name mismatch. Expected "entPhysMfgName" to be ANetworks, but got A.

the failure was only seen on one of the DUT

which had

docker exec snmp redis-cli -n 6 HGET 'TRANSCEIVER_INFO|Ethernet0' manufacturer | xxd | head -5
00000000: 4100 0000 0000 4e65 7477 6f72 6b73 0a    A.....Networks.

so failing to strip the \0 is causing ssnmp agent returns just A

on another DUT it is fine because of not having \0:

admin@str5-7280r4-ut2-3:~$ docker exec snmp redis-cli -n 6 HGET 'TRANSCEIVER_INFO|Ethernet0' manufacturer | xxd | head -5
00000000: 4172 6973 7461 204e 6574 776f 726b 730a  Arista Networks.

Description

Motivation and Context

How Has This Been Tested?

applied the fix on dut directly and restarted xcvrd:
in /usr/local/lib/python3.11/dist-packages/sonic_platform_base/sonic_xcvr/api/public/cmis.py

Before: 41 00 00 00 00 00 4e 65 74 77 6f 72 6b 73 → A\x00\x00\x00\x00\x00Networks
After: 41 4e 65 74 77 6f 72 6b 73 → ANetworks

Additional Information (Optional)

Modify _strip_str method to remove null characters.
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

Copilot AI left a comment

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.

Pull request overview

This PR updates the CMIS transceiver API string sanitization so that EEPROM-decoded strings containing embedded NUL (\x00) characters are cleaned up before being returned, addressing cases where downstream consumers (e.g., SNMP-related tests) only see a truncated prefix.

Changes:

  • Extend CmisApi._strip_str() to remove embedded \x00 characters before trimming trailing whitespace.

Comment thread sonic_platform_base/sonic_xcvr/api/public/cmis.py
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@mihirpat1

Copy link
Copy Markdown
Contributor

@wenyiz2021 Isn't this a module issue wherein the vendor has not padded spaces and has instead used null character?

image

@wenyiz2021

Copy link
Copy Markdown
Author

@wenyiz2021 Isn't this a module issue wherein the vendor has not padded spaces and has instead used null character?

image

thanks @mihirpat1 for bringing up, not sure, I've also asked vendor to check thihs PR but they havn't replied. looks like just that string issue on dut.

@wenyiz2021

Copy link
Copy Markdown
Author

looks like wrong cable transceiver info

@arista-nwolfe

Copy link
Copy Markdown

We believe this is a 1-off issue with a XCVR, we shouldn't try to handle this in S/W

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

6 participants