Skip to content

Conversation

@Junchao-Mellanox
Copy link
Contributor

Description

CdbFwHandler is created to handle CDB related command for cmis module. It should be created only CDB is supported by this module. However, the current implementation add an assertion in init function which will fail any cmis module which does not support CDB:

class CdbFwHandler(CdbCmdHandler):
    def __init__(self, reader, writer, mem_map):
        super(CdbFwHandler, self).__init__(reader, writer, mem_map)
        self.start_payload_size = 0
        self.is_lpl_only = False
        self.rw_length_ext = 0
        assert True == self.initFwHandler(), "Failed to initialize firmware handler"

The error logs:

2025 Nov 16 12:21:21.010105 sonic INFO pmon#supervisord: xcvrd Error creating API: Failed to initialize firmware handler
2025 Nov 16 12:21:21.010182 sonic INFO pmon#supervisord: xcvrd Failed to get firmware management features

Motivation and Context

Only create CdbFwHandler if module support CDB

How Has This Been Tested?

Manual test with modules that support and not support CDB
Unit test

Additional Information (Optional)

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

keboliu
keboliu previously approved these changes Nov 20, 2025
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

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 fixes a bug where CdbFwHandler was being instantiated for CMIS modules that don't support CDB (Command DataBlock), causing initialization failures due to an assertion error. The fix introduces lazy initialization of the CDB firmware handler, only creating it when explicitly requested and when CDB is actually supported by the module.

Key Changes:

  • Converted cdb_fw_hdlr from a constructor parameter to a lazily-initialized property
  • Added init_cdb_fw_handler flag to control whether the handler should be created
  • Removed premature CDB handler instantiation from the factory and test code

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
sonic_platform_base/sonic_xcvr/api/public/cmis.py Implements lazy initialization pattern for CDB firmware handler with property-based access
sonic_platform_base/sonic_xcvr/api/public/c_cmis.py Updates CCmisApi constructor to pass through the init_cdb_fw_handler flag
sonic_platform_base/sonic_xcvr/xcvr_api_factory.py Removes CDB imports and switches to lazy initialization via init_cdb_fw_handler=True
tests/sonic_xcvr/test_cmis.py Adds tests for the new lazy initialization behavior and CDB handler creation logic
tests/sonic_xcvr/test_ccmis.py Updates test setup to use init_cdb_fw_handler flag instead of passing CDB handler directly
tests/sonic_xcvr/test_sfp_optoe_base.py Updates test setup to disable CDB handler initialization for test cases
tests/sonic_xcvr/test_cdb_fw.py Fixes test assertions to expect False instead of True when initialization fails

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Junchao-Mellanox <[email protected]>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Junchao-Mellanox <[email protected]>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Junchao-Mellanox
Copy link
Contributor Author

Hi @judyjoseph , @prgeor , could you please review and sign-off?

@keboliu keboliu merged commit 6ac5692 into sonic-net:master Dec 24, 2025
6 checks passed
@Junchao-Mellanox Junchao-Mellanox deleted the master-cdb branch December 24, 2025 03:42
@mssonicbld
Copy link
Collaborator

Cherry-pick PR to 202511: #619

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants