From 2dd5f997bcd8ed7b5f6bfc38175b768045ceacc3 Mon Sep 17 00:00:00 2001 From: Mihir Patel Date: Fri, 15 Sep 2023 22:37:27 +0000 Subject: [PATCH 1/2] Handle NotImplementedError exception while calling get_eeprom_path API --- sonic_platform_base/sonic_xcvr/sfp_optoe_base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py b/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py index 668389e14..cedc983b2 100644 --- a/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py +++ b/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py @@ -167,7 +167,10 @@ def set_lpmode(self, lpmode): return api.set_lpmode(lpmode) if api is not None else None def set_optoe_write_max(self, write_max): - sys_path = self.get_eeprom_path() + try: + sys_path = self.get_eeprom_path() + except NotImplementedError: + return sys_path = sys_path.replace("eeprom", "write_max") try: with open(sys_path, mode='w') as f: From 879690ad28dd92d84aa3f1c6c8604a72ee442a86 Mon Sep 17 00:00:00 2001 From: Mihir Patel Date: Sat, 16 Sep 2023 06:00:03 +0000 Subject: [PATCH 2/2] Added test file for sfp_optoe_base.py to improve code coverage --- tests/sonic_xcvr/test_sfp_optoe_base.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/sonic_xcvr/test_sfp_optoe_base.py diff --git a/tests/sonic_xcvr/test_sfp_optoe_base.py b/tests/sonic_xcvr/test_sfp_optoe_base.py new file mode 100644 index 000000000..4fb89255b --- /dev/null +++ b/tests/sonic_xcvr/test_sfp_optoe_base.py @@ -0,0 +1,10 @@ +from unittest.mock import patch +from mock import MagicMock +import pytest +from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase + +class TestSfpOptoeBase(object): + optoebase = SfpOptoeBase() + + def test_set_optoe_write_max_with_exception(self): + self.optoebase.set_optoe_write_max(1)