From d6a4635fb9f8c84d671179a438c2807c0f34bb75 Mon Sep 17 00:00:00 2001 From: Vivek Date: Tue, 23 Jul 2024 10:57:40 -0700 Subject: [PATCH] [xcvrd] Fix xcvrd crash for RJ45 cable type (#513) Signed-off-by: Vivek Reddy --- sonic-xcvrd/tests/test_xcvrd.py | 9 +++++++++ sonic-xcvrd/xcvrd/xcvrd.py | 2 ++ 2 files changed, 11 insertions(+) diff --git a/sonic-xcvrd/tests/test_xcvrd.py b/sonic-xcvrd/tests/test_xcvrd.py index 400b72fdc..4275eaf59 100644 --- a/sonic-xcvrd/tests/test_xcvrd.py +++ b/sonic-xcvrd/tests/test_xcvrd.py @@ -2908,6 +2908,15 @@ def test_wrapper_is_flat_memory(self, mock_chassis): mock_chassis.get_sfp = MagicMock(side_effect=NotImplementedError) assert not _wrapper_is_flat_memory(1) + @patch('xcvrd.xcvrd.platform_chassis') + def test_wrapper_is_flat_memory_no_xcvr_api(self, mock_chassis): + mock_object = MagicMock() + mock_object.get_xcvr_api = MagicMock(return_value=None) + mock_chassis.get_sfp = MagicMock(return_value=mock_object) + + from xcvrd.xcvrd import _wrapper_is_flat_memory + assert _wrapper_is_flat_memory(1) == True + def test_check_port_in_range(self): range_str = '1 - 32' physical_port = 1 diff --git a/sonic-xcvrd/xcvrd/xcvrd.py b/sonic-xcvrd/xcvrd/xcvrd.py index d69e5ce30..ff147422a 100644 --- a/sonic-xcvrd/xcvrd/xcvrd.py +++ b/sonic-xcvrd/xcvrd/xcvrd.py @@ -318,6 +318,8 @@ def _wrapper_is_flat_memory(physical_port): try: sfp = platform_chassis.get_sfp(physical_port) api = sfp.get_xcvr_api() + if not api: + return True return api.is_flat_memory() except NotImplementedError: pass