Skip to content

Commit b323337

Browse files
Fix issue '<' not supported between instances of 'NoneType' and 'int' (sonic-net#371)
1 parent d2b4021 commit b323337

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

sonic_platform_base/sonic_xcvr/api/public/cmis.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,12 @@ def get_tx_bias(self):
501501
if not tx_bias_support:
502502
return ["N/A" for _ in range(self.NUM_CHANNELS)]
503503
scale_raw = self.xcvr_eeprom.read(consts.TX_BIAS_SCALE)
504+
if scale_raw is None:
505+
return ["N/A" for _ in range(self.NUM_CHANNELS)]
504506
scale = 2**scale_raw if scale_raw < 3 else 1
505507
tx_bias = self.xcvr_eeprom.read(consts.TX_BIAS_FIELD)
508+
if tx_bias is None:
509+
return ["N/A" for _ in range(self.NUM_CHANNELS)]
506510
for key, value in tx_bias.items():
507511
tx_bias[key] *= scale
508512
return [tx_bias['LaserBiasTx%dField' % i] for i in range(1, self.NUM_CHANNELS + 1)]
@@ -874,7 +878,7 @@ def get_laser_temperature(self):
874878
'high warn': laser_temp_high_warn,
875879
'low warn': laser_temp_low_warn}
876880
return laser_temp_dict
877-
881+
878882
def _get_laser_temp_threshold(self, field):
879883
LASER_TEMP_SCALE = 256.0
880884
value = self.xcvr_eeprom.read(field)

tests/sonic_xcvr/test_cmis.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,16 @@ def test_get_tx_bias(self, mock_response, expected):
377377
result = self.api.get_tx_bias()
378378
assert result == expected
379379

380+
def test_get_tx_bias_neg(self):
381+
self.api.get_tx_bias_support = MagicMock(return_value=True)
382+
self.api.xcvr_eeprom.read = MagicMock()
383+
# scale_raw is None, verify no crash
384+
self.api.xcvr_eeprom.read.return_value = None
385+
self.api.get_tx_bias()
386+
# scale_raw is 1, tx_bias is None, verify no crash
387+
self.api.xcvr_eeprom.read.side_effect = [1, None]
388+
self.api.get_tx_bias()
389+
380390
@pytest.mark.parametrize("mock_response, expected", [
381391
([False, True], True)
382392
])

0 commit comments

Comments
 (0)