From a8620d7985f7cc2e6a6ee4e9e6e6adb758fc9899 Mon Sep 17 00:00:00 2001 From: Longyin Huang Date: Tue, 4 Apr 2023 17:05:50 -0700 Subject: [PATCH 1/5] Add tx_disable in get_transceiver_status API --- .../sonic_xcvr/api/public/cmis.py | 7 +++++++ tests/sonic_xcvr/test_cmis.py | 21 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/sonic_platform_base/sonic_xcvr/api/public/cmis.py b/sonic_platform_base/sonic_xcvr/api/public/cmis.py index f50b0d43b..dfcc182c9 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/cmis.py @@ -1620,6 +1620,8 @@ def get_transceiver_status(self): rxoutput_status_hostlane6 = BOOLEAN ; rx output status on host lane 6 rxoutput_status_hostlane7 = BOOLEAN ; rx output status on host lane 7 rxoutput_status_hostlane8 = BOOLEAN ; rx output status on host lane 8 + tx_disable = BOOLEAN ; tx disable status + tx_disabled_channel = INTEGER ; disabled TX channels txfault = BOOLEAN ; tx fault flag on media lane txlos_hostlane1 = BOOLEAN ; tx loss of signal flag on host lane 1 txlos_hostlane2 = BOOLEAN ; tx loss of signal flag on host lane 2 @@ -1738,6 +1740,11 @@ def get_transceiver_status(self): if rx_output_status_dict: for lane in range(1, self.NUM_CHANNELS+1): trans_status['rxoutput_status_hostlane%d' % lane] = rx_output_status_dict.get('RxOutputStatus%d' % lane) + if self.get_tx_disable_support(): + trans_status['tx_disabled_channel'] = self.get_tx_disable_channel() + tx_disable = self.get_tx_disable() + for lane in range(1, self.NUM_CHANNELS+1): + trans_status['tx%ddisable' % lane] = tx_disable[lane - 1] tx_fault = self.get_tx_fault() if tx_fault: for lane in range(1, self.NUM_CHANNELS+1): diff --git a/tests/sonic_xcvr/test_cmis.py b/tests/sonic_xcvr/test_cmis.py index 1f106197c..125ee71ed 100644 --- a/tests/sonic_xcvr/test_cmis.py +++ b/tests/sonic_xcvr/test_cmis.py @@ -1601,7 +1601,8 @@ def test_get_transceiver_threshold_info(self, mock_response, expected): { 'Pre-FEC BER Average Media Input':{1:[0.001, 0.0125, 0, 0.01, 0, False, False, False, False]}, 'Errored Frames Average Media Input':{1:[0, 1, 0, 1, 0, False, False, False, False]}, - } + }, + True, 0, [False, False, False, False, False, False, False, False] ], { 'module_state': 'ModuleReady', @@ -1633,6 +1634,15 @@ def test_get_transceiver_threshold_info(self, mock_response, expected): 'rxoutput_status_hostlane6': True, 'rxoutput_status_hostlane7': True, 'rxoutput_status_hostlane8': True, + "tx_disabled_channel": 0, + "tx1disable": False, + "tx2disable": False, + "tx3disable": False, + "tx4disable": False, + "tx5disable": False, + "tx6disable": False, + "tx7disable": False, + "tx8disable": False, 'txfault1': False, 'txfault2': False, 'txfault3': False, @@ -1835,7 +1845,8 @@ def test_get_transceiver_threshold_info(self, mock_response, expected): { 'Pre-FEC BER Average Media Input':{1:[0.001, 0.0125, 0, 0.01, 0, False, False, False, False]}, 'Errored Frames Average Media Input':{1:[0, 1, 0, 1, 0, False, False, False, False]}, - } + }, + False, 0, [False, False, False, False, False, False, False, False] ], { 'module_state': 'ModuleReady', @@ -1894,6 +1905,12 @@ def test_get_transceiver_status(self, mock_response, expected): self.api.get_tx_bias_flag.return_value = mock_response[18] self.api.get_vdm = MagicMock() self.api.get_vdm.return_value = mock_response[19] + self.api.get_tx_disable_support = MagicMock() + self.api.get_tx_disable_support.return_value = mock_response[20] + self.api.get_tx_disable_channel = MagicMock() + self.api.get_tx_disable_channel.return_value = mock_response[21] + self.api.get_tx_disable = MagicMock() + self.api.get_tx_disable.return_value = mock_response[22] result = self.api.get_transceiver_status() assert result == expected From 23ba7deed1800903d50f79beb69f0e14cbca1408 Mon Sep 17 00:00:00 2001 From: Longyin Huang Date: Tue, 4 Apr 2023 17:57:28 -0700 Subject: [PATCH 2/5] Remove tx_disable from bulk_status API --- sonic_platform_base/sfp_base.py | 3 --- sonic_platform_base/sonic_xcvr/api/public/sff8436.py | 6 ------ sonic_platform_base/sonic_xcvr/api/public/sff8472.py | 6 ------ sonic_platform_base/sonic_xcvr/api/public/sff8636.py | 6 ------ sonic_platform_base/sonic_xcvr/api/xcvr_api.py | 3 --- 5 files changed, 24 deletions(-) diff --git a/sonic_platform_base/sfp_base.py b/sonic_platform_base/sfp_base.py index 0d98caa29..804b51ab8 100644 --- a/sonic_platform_base/sfp_base.py +++ b/sonic_platform_base/sfp_base.py @@ -161,9 +161,6 @@ def get_transceiver_bulk_status(self): tx_fault |BOOLEAN |TX fault status, True if has TX fault, False if not. reset_status |BOOLEAN |reset status, True if SFP in reset, False if not. lp_mode |BOOLEAN |low power mode status, True in lp mode, False if not. - tx_disable |BOOLEAN |TX disable status, True TX disabled, False if not. - tx_disabled_channel |HEX |disabled TX channels in hex, bits 0 to 3 represent channel 0 - | |to channel 3. temperature |INT |module temperature in Celsius voltage |INT |supply voltage in mV txbias |INT |TX Bias Current in mA, n is the channel number, diff --git a/sonic_platform_base/sonic_xcvr/api/public/sff8436.py b/sonic_platform_base/sonic_xcvr/api/public/sff8436.py index 4cf2aacce..a04251a1a 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/sff8436.py +++ b/sonic_platform_base/sonic_xcvr/api/public/sff8436.py @@ -71,8 +71,6 @@ def get_transceiver_info(self): def get_transceiver_bulk_status(self): rx_los = self.get_rx_los() tx_fault = self.get_tx_fault() - tx_disable = self.get_tx_disable() - tx_disabled_channel = self.get_tx_disable_channel() temp = self.get_module_temperature() voltage = self.get_voltage() tx_bias = self.get_tx_bias() @@ -80,8 +78,6 @@ def get_transceiver_bulk_status(self): tx_power = self.get_tx_power() read_failed = rx_los is None or \ tx_fault is None or \ - tx_disable is None or \ - tx_disabled_channel is None or \ temp is None or \ voltage is None or \ tx_bias is None or \ @@ -93,8 +89,6 @@ def get_transceiver_bulk_status(self): bulk_status = { "rx_los": all(rx_los) if self.get_rx_los_support() else 'N/A', "tx_fault": all(tx_fault) if self.get_tx_fault_support() else 'N/A', - "tx_disable": all(tx_disable), - "tx_disabled_channel": tx_disabled_channel, "temperature": temp, "voltage": voltage } diff --git a/sonic_platform_base/sonic_xcvr/api/public/sff8472.py b/sonic_platform_base/sonic_xcvr/api/public/sff8472.py index 3ccfcfb0e..a544ea089 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/sff8472.py +++ b/sonic_platform_base/sonic_xcvr/api/public/sff8472.py @@ -63,8 +63,6 @@ def get_transceiver_info(self): def get_transceiver_bulk_status(self): rx_los = self.get_rx_los() tx_fault = self.get_tx_fault() - tx_disable = self.get_tx_disable() - tx_disabled_channel = self.get_tx_disable_channel() temp = self.get_module_temperature() voltage = self.get_voltage() tx_bias = self.get_tx_bias() @@ -72,8 +70,6 @@ def get_transceiver_bulk_status(self): tx_power = self.get_tx_power() read_failed = rx_los is None or \ tx_fault is None or \ - tx_disable is None or \ - tx_disabled_channel is None or \ temp is None or \ voltage is None or \ tx_bias is None or \ @@ -85,8 +81,6 @@ def get_transceiver_bulk_status(self): bulk_status = { "rx_los": all(rx_los) if self.get_rx_los_support() else 'N/A', "tx_fault": all(tx_fault) if self.get_tx_fault_support() else 'N/A', - "tx_disable": all(tx_disable), - "tx_disabled_channel": tx_disabled_channel, "temperature": temp, "voltage": voltage } diff --git a/sonic_platform_base/sonic_xcvr/api/public/sff8636.py b/sonic_platform_base/sonic_xcvr/api/public/sff8636.py index e14c07da5..c1b95a928 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/sff8636.py +++ b/sonic_platform_base/sonic_xcvr/api/public/sff8636.py @@ -78,8 +78,6 @@ def get_transceiver_info(self): def get_transceiver_bulk_status(self): rx_los = self.get_rx_los() tx_fault = self.get_tx_fault() - tx_disable = self.get_tx_disable() - tx_disabled_channel = self.get_tx_disable_channel() temp = self.get_module_temperature() voltage = self.get_voltage() tx_bias = self.get_tx_bias() @@ -87,8 +85,6 @@ def get_transceiver_bulk_status(self): tx_power = self.get_tx_power() read_failed = rx_los is None or \ tx_fault is None or \ - tx_disable is None or \ - tx_disabled_channel is None or \ temp is None or \ voltage is None or \ tx_bias is None or \ @@ -100,8 +96,6 @@ def get_transceiver_bulk_status(self): bulk_status = { "rx_los": all(rx_los) if self.get_rx_los_support() else 'N/A', "tx_fault": all(tx_fault) if self.get_tx_fault_support() else 'N/A', - "tx_disable": all(tx_disable), - "tx_disabled_channel": tx_disabled_channel, "temperature": temp, "voltage": voltage } diff --git a/sonic_platform_base/sonic_xcvr/api/xcvr_api.py b/sonic_platform_base/sonic_xcvr/api/xcvr_api.py index e759f794e..ce9bac8d9 100644 --- a/sonic_platform_base/sonic_xcvr/api/xcvr_api.py +++ b/sonic_platform_base/sonic_xcvr/api/xcvr_api.py @@ -81,9 +81,6 @@ def get_transceiver_bulk_status(self): ---------------------------|---------------|---------------------------- rx_los |bool |RX loss-of-signal status, True if has RX los, False if not. tx_fault |bool |TX fault status, True if has TX fault, False if not. - tx_disable |bool |TX disable status, True TX disabled, False if not. - tx_disabled_channel |int |disabled TX channels in hex, bits 0 to 3 represent channel 0 - | |to channel 3 (for example). temperature |float |module temperature in Celsius voltage |float |supply voltage in mV txbias |float |TX Bias Current in mA, n is the channel number, From ce671f1b04cccbfbe3a5f4d6f26dd4bd26511a7c Mon Sep 17 00:00:00 2001 From: Longyin Huang Date: Wed, 10 May 2023 14:57:16 -0700 Subject: [PATCH 3/5] Add status API for non-cmis --- .../sonic_xcvr/api/public/c_cmis.py | 2 +- .../sonic_xcvr/api/public/cmis.py | 14 +---- .../sonic_xcvr/api/public/sff8436.py | 27 +++++++-- .../sonic_xcvr/api/public/sff8472.py | 27 +++++++-- .../sonic_xcvr/api/public/sff8636.py | 27 +++++++-- .../sonic_xcvr/api/xcvr_api.py | 4 +- tests/sonic_xcvr/test_cmis.py | 56 +++++-------------- tests/sonic_xcvr/test_sff8436.py | 1 + tests/sonic_xcvr/test_sff8472.py | 1 + tests/sonic_xcvr/test_sff8636.py | 1 + 10 files changed, 82 insertions(+), 78 deletions(-) diff --git a/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py b/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py index 6929d2614..3136c03aa 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py @@ -644,7 +644,7 @@ def get_transceiver_status(self): tuning_in_progress = BOOLEAN ; tuning in progress status wavelength_unlock_status = BOOLEAN ; laser unlocked status target_output_power_oor = BOOLEAN ; target output power out of range flag - fine_tuning_oor = BOOLEAN ; fine tuning out of range flag + fine_tuning_oor = BOOLEAN ; fine tuning out of range flag tuning_not_accepted = BOOLEAN ; tuning not accepted flag invalid_channel_num = BOOLEAN ; invalid channel number flag tuning_complete = BOOLEAN ; tuning complete flag diff --git a/sonic_platform_base/sonic_xcvr/api/public/cmis.py b/sonic_platform_base/sonic_xcvr/api/public/cmis.py index dfcc182c9..961ebcbd9 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/cmis.py @@ -176,20 +176,12 @@ def get_transceiver_info(self): return xcvr_info def get_transceiver_bulk_status(self): - rx_los = self.get_rx_los() - tx_fault = self.get_tx_fault() - tx_disable = self.get_tx_disable() - tx_disabled_channel = self.get_tx_disable_channel() temp = self.get_module_temperature() voltage = self.get_voltage() tx_bias = self.get_tx_bias() rx_power = self.get_rx_power() tx_power = self.get_tx_power() - read_failed = rx_los is None or \ - tx_fault is None or \ - tx_disable is None or \ - tx_disabled_channel is None or \ - temp is None or \ + read_failed = temp is None or \ voltage is None or \ tx_bias is None or \ rx_power is None or \ @@ -198,15 +190,11 @@ def get_transceiver_bulk_status(self): return None bulk_status = { - "rx_los": all(rx_los) if self.get_rx_los_support() else 'N/A', - "tx_fault": all(tx_fault) if self.get_tx_fault_support() else 'N/A', - "tx_disabled_channel": tx_disabled_channel, "temperature": temp, "voltage": voltage } for i in range(1, self.NUM_CHANNELS + 1): - bulk_status["tx%ddisable" % i] = tx_disable[i-1] if self.get_tx_disable_support() else 'N/A' bulk_status["tx%dbias" % i] = tx_bias[i - 1] bulk_status["rx%dpower" % i] = float("{:.3f}".format(self.mw_to_dbm(rx_power[i - 1]))) if rx_power[i - 1] != 'N/A' else 'N/A' bulk_status["tx%dpower" % i] = float("{:.3f}".format(self.mw_to_dbm(tx_power[i - 1]))) if tx_power[i - 1] != 'N/A' else 'N/A' diff --git a/sonic_platform_base/sonic_xcvr/api/public/sff8436.py b/sonic_platform_base/sonic_xcvr/api/public/sff8436.py index a04251a1a..73421e421 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/sff8436.py +++ b/sonic_platform_base/sonic_xcvr/api/public/sff8436.py @@ -68,17 +68,34 @@ def get_transceiver_info(self): return xcvr_info - def get_transceiver_bulk_status(self): + def get_transceiver_status(self): rx_los = self.get_rx_los() tx_fault = self.get_tx_fault() + tx_disable = self.get_tx_disable() + tx_disabled_channel = self.get_tx_disable_channel() + read_failed = rx_los is None or \ + tx_fault is None or \ + tx_disable is None or \ + tx_disabled_channel is None + if read_failed: + return None + + trans_status = { + "rx_los": all(rx_los) if self.get_rx_los_support() else 'N/A', + "tx_fault": all(tx_fault) if self.get_tx_fault_support() else 'N/A', + "tx_disable": all(tx_disable), + "tx_disabled_channel": tx_disabled_channel + } + + return trans_status + + def get_transceiver_bulk_status(self): temp = self.get_module_temperature() voltage = self.get_voltage() tx_bias = self.get_tx_bias() rx_power = self.get_rx_power() tx_power = self.get_tx_power() - read_failed = rx_los is None or \ - tx_fault is None or \ - temp is None or \ + read_failed = temp is None or \ voltage is None or \ tx_bias is None or \ rx_power is None or \ @@ -87,8 +104,6 @@ def get_transceiver_bulk_status(self): return None bulk_status = { - "rx_los": all(rx_los) if self.get_rx_los_support() else 'N/A', - "tx_fault": all(tx_fault) if self.get_tx_fault_support() else 'N/A', "temperature": temp, "voltage": voltage } diff --git a/sonic_platform_base/sonic_xcvr/api/public/sff8472.py b/sonic_platform_base/sonic_xcvr/api/public/sff8472.py index a544ea089..eadfa5426 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/sff8472.py +++ b/sonic_platform_base/sonic_xcvr/api/public/sff8472.py @@ -60,17 +60,34 @@ def get_transceiver_info(self): return xcvr_info - def get_transceiver_bulk_status(self): + def get_transceiver_status(self): rx_los = self.get_rx_los() tx_fault = self.get_tx_fault() + tx_disable = self.get_tx_disable() + tx_disabled_channel = self.get_tx_disable_channel() + read_failed = rx_los is None or \ + tx_fault is None or \ + tx_disable is None or \ + tx_disabled_channel is None + if read_failed: + return None + + trans_status = { + "rx_los": all(rx_los) if self.get_rx_los_support() else 'N/A', + "tx_fault": all(tx_fault) if self.get_tx_fault_support() else 'N/A', + "tx_disable": all(tx_disable), + "tx_disabled_channel": tx_disabled_channel + } + + return trans_status + + def get_transceiver_bulk_status(self): temp = self.get_module_temperature() voltage = self.get_voltage() tx_bias = self.get_tx_bias() rx_power = self.get_rx_power() tx_power = self.get_tx_power() - read_failed = rx_los is None or \ - tx_fault is None or \ - temp is None or \ + read_failed = temp is None or \ voltage is None or \ tx_bias is None or \ rx_power is None or \ @@ -79,8 +96,6 @@ def get_transceiver_bulk_status(self): return None bulk_status = { - "rx_los": all(rx_los) if self.get_rx_los_support() else 'N/A', - "tx_fault": all(tx_fault) if self.get_tx_fault_support() else 'N/A', "temperature": temp, "voltage": voltage } diff --git a/sonic_platform_base/sonic_xcvr/api/public/sff8636.py b/sonic_platform_base/sonic_xcvr/api/public/sff8636.py index c1b95a928..2c26cc1f4 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/sff8636.py +++ b/sonic_platform_base/sonic_xcvr/api/public/sff8636.py @@ -75,17 +75,34 @@ def get_transceiver_info(self): return xcvr_info - def get_transceiver_bulk_status(self): + def get_transceiver_status(self): rx_los = self.get_rx_los() tx_fault = self.get_tx_fault() + tx_disable = self.get_tx_disable() + tx_disabled_channel = self.get_tx_disable_channel() + read_failed = rx_los is None or \ + tx_fault is None or \ + tx_disable is None or \ + tx_disabled_channel is None + if read_failed: + return None + + trans_status = { + "rx_los": all(rx_los) if self.get_rx_los_support() else 'N/A', + "tx_fault": all(tx_fault) if self.get_tx_fault_support() else 'N/A', + "tx_disable": all(tx_disable), + "tx_disabled_channel": tx_disabled_channel + } + + return trans_status + + def get_transceiver_bulk_status(self): temp = self.get_module_temperature() voltage = self.get_voltage() tx_bias = self.get_tx_bias() rx_power = self.get_rx_power() tx_power = self.get_tx_power() - read_failed = rx_los is None or \ - tx_fault is None or \ - temp is None or \ + read_failed = temp is None or \ voltage is None or \ tx_bias is None or \ rx_power is None or \ @@ -94,8 +111,6 @@ def get_transceiver_bulk_status(self): return None bulk_status = { - "rx_los": all(rx_los) if self.get_rx_los_support() else 'N/A', - "tx_fault": all(tx_fault) if self.get_tx_fault_support() else 'N/A', "temperature": temp, "voltage": voltage } diff --git a/sonic_platform_base/sonic_xcvr/api/xcvr_api.py b/sonic_platform_base/sonic_xcvr/api/xcvr_api.py index ce9bac8d9..2a1cec421 100644 --- a/sonic_platform_base/sonic_xcvr/api/xcvr_api.py +++ b/sonic_platform_base/sonic_xcvr/api/xcvr_api.py @@ -79,8 +79,6 @@ def get_transceiver_bulk_status(self): ======================================================================== keys |Value Format |Information ---------------------------|---------------|---------------------------- - rx_los |bool |RX loss-of-signal status, True if has RX los, False if not. - tx_fault |bool |TX fault status, True if has TX fault, False if not. temperature |float |module temperature in Celsius voltage |float |supply voltage in mV txbias |float |TX Bias Current in mA, n is the channel number, @@ -132,7 +130,7 @@ def get_transceiver_threshold_info(self): def get_transceiver_status(self): """ - Retrieves transceiver status of this SFP (applicable for CMIS/C-CMIS) + Retrieves transceiver status of this SFP Returns: A dict which may contain following keys/values (there could be more for C-CMIS) : diff --git a/tests/sonic_xcvr/test_cmis.py b/tests/sonic_xcvr/test_cmis.py index 125ee71ed..75cf7f086 100644 --- a/tests/sonic_xcvr/test_cmis.py +++ b/tests/sonic_xcvr/test_cmis.py @@ -1268,10 +1268,6 @@ def test_get_transceiver_info(self, mock_response, expected): @pytest.mark.parametrize("mock_response, expected",[ ( [ - [False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False], - [False, False, False, False, False, False, False, False], - 0, 50, 3.3, [70, 70, 70, 70, 70, 70, 70, 70], @@ -1296,11 +1292,6 @@ def test_get_transceiver_info(self, mock_response, expected): 'rx5power': -10.0, 'rx6power': -10.0, 'rx7power': -10.0, 'rx8power': -10.0, 'tx1bias': 70, 'tx2bias': 70, 'tx3bias': 70, 'tx4bias': 70, 'tx5bias': 70, 'tx6bias': 70, 'tx7bias': 70, 'tx8bias': 70, - 'rx_los': False, - 'tx_fault': False, - 'tx1disable': False, 'tx2disable': False, 'tx3disable': False, 'tx4disable': False, - 'tx5disable': False, 'tx6disable': False, 'tx7disable': False, 'tx8disable': False, - 'tx_disabled_channel': 0, 'laser_temperature': 40, 'prefec_ber': 0.001, 'postfec_ber_min': 0, @@ -1311,10 +1302,6 @@ def test_get_transceiver_info(self, mock_response, expected): ), ( [ - ['N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A'], - ['N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A'], - ['N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A'], - 'N/A', 50, 3.3, ['N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A'], None, @@ -1327,10 +1314,6 @@ def test_get_transceiver_info(self, mock_response, expected): ), ( [ - ['N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A'], - ['N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A'], - ['N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A'], - 'N/A', 50, 3.3, ['N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A'], ['N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A'], @@ -1348,50 +1331,37 @@ def test_get_transceiver_info(self, mock_response, expected): 'rx5power': 'N/A', 'rx6power': 'N/A', 'rx7power': 'N/A', 'rx8power': 'N/A', 'tx1bias': 'N/A', 'tx2bias': 'N/A', 'tx3bias': 'N/A', 'tx4bias': 'N/A', 'tx5bias': 'N/A', 'tx6bias': 'N/A', 'tx7bias': 'N/A', 'tx8bias': 'N/A', - 'rx_los': 'N/A', - 'tx_fault': 'N/A', - 'tx1disable': 'N/A', 'tx2disable': 'N/A', 'tx3disable': 'N/A', 'tx4disable': 'N/A', - 'tx5disable': 'N/A', 'tx6disable': 'N/A', 'tx7disable': 'N/A', 'tx8disable': 'N/A', - 'tx_disabled_channel': 'N/A', 'laser_temperature': 40 } ) ]) def test_get_transceiver_bulk_status(self, mock_response, expected): - self.api.get_rx_los = MagicMock() - self.api.get_rx_los.return_value = mock_response[0] - self.api.get_tx_fault = MagicMock() - self.api.get_tx_fault.return_value = mock_response[1] - self.api.get_tx_disable = MagicMock() - self.api.get_tx_disable.return_value = mock_response[2] - self.api.get_tx_disable_channel = MagicMock() - self.api.get_tx_disable_channel.return_value = mock_response[3] self.api.get_module_temperature = MagicMock() - self.api.get_module_temperature.return_value = mock_response[4] + self.api.get_module_temperature.return_value = mock_response[0] self.api.get_voltage = MagicMock() - self.api.get_voltage.return_value = mock_response[5] + self.api.get_voltage.return_value = mock_response[1] self.api.get_tx_bias = MagicMock() - self.api.get_tx_bias.return_value = mock_response[6] + self.api.get_tx_bias.return_value = mock_response[2] self.api.get_rx_power = MagicMock() - self.api.get_rx_power.return_value = mock_response[7] + self.api.get_rx_power.return_value = mock_response[3] self.api.get_tx_power = MagicMock() - self.api.get_tx_power.return_value = mock_response[8] + self.api.get_tx_power.return_value = mock_response[4] self.api.get_rx_los_support = MagicMock() - self.api.get_rx_los_support.return_value = mock_response[9] + self.api.get_rx_los_support.return_value = mock_response[5] self.api.get_tx_fault_support = MagicMock() - self.api.get_tx_fault_support.return_value = mock_response[10] + self.api.get_tx_fault_support.return_value = mock_response[6] self.api.get_tx_disable_support = MagicMock() - self.api.get_tx_disable_support.return_value = mock_response[11] + self.api.get_tx_disable_support.return_value = mock_response[7] self.api.get_tx_bias_support = MagicMock() - self.api.get_tx_bias_support.return_value = mock_response[12] + self.api.get_tx_bias_support.return_value = mock_response[8] self.api.get_tx_power_support = MagicMock() - self.api.get_tx_power_support.return_value = mock_response[13] + self.api.get_tx_power_support.return_value = mock_response[9] self.api.get_rx_power_support = MagicMock() - self.api.get_rx_power_support.return_value = mock_response[14] + self.api.get_rx_power_support.return_value = mock_response[10] self.api.get_laser_temperature = MagicMock() - self.api.get_laser_temperature.return_value = mock_response[15] + self.api.get_laser_temperature.return_value = mock_response[11] self.api.get_vdm = MagicMock() - self.api.get_vdm.return_value = mock_response[16] + self.api.get_vdm.return_value = mock_response[12] result = self.api.get_transceiver_bulk_status() assert result == expected diff --git a/tests/sonic_xcvr/test_sff8436.py b/tests/sonic_xcvr/test_sff8436.py index 053175efd..8567f5f27 100644 --- a/tests/sonic_xcvr/test_sff8436.py +++ b/tests/sonic_xcvr/test_sff8436.py @@ -27,6 +27,7 @@ def test_api(self): self.api.get_transceiver_info() self.api.get_transceiver_bulk_status() self.api.get_transceiver_threshold_info() + self.api.get_transceiver_status() self.api.get_rx_los() self.api.get_tx_fault() self.api.get_tx_disable() diff --git a/tests/sonic_xcvr/test_sff8472.py b/tests/sonic_xcvr/test_sff8472.py index 7831fcf06..438e2fa75 100644 --- a/tests/sonic_xcvr/test_sff8472.py +++ b/tests/sonic_xcvr/test_sff8472.py @@ -29,6 +29,7 @@ def test_api(self): self.api.get_transceiver_info() self.api.get_transceiver_bulk_status() self.api.get_transceiver_threshold_info() + self.api.get_transceiver_status() self.api.get_rx_los() self.api.get_tx_fault() self.api.get_tx_disable() diff --git a/tests/sonic_xcvr/test_sff8636.py b/tests/sonic_xcvr/test_sff8636.py index a347e8fa2..3ae40a3b7 100644 --- a/tests/sonic_xcvr/test_sff8636.py +++ b/tests/sonic_xcvr/test_sff8636.py @@ -26,6 +26,7 @@ def test_api(self): self.api.get_transceiver_info() self.api.get_transceiver_bulk_status() self.api.get_transceiver_threshold_info() + self.api.get_transceiver_status() self.api.get_rx_los() self.api.get_tx_fault() self.api.get_tx_disable() From 6d6285a162563dffc1f8669fdce7a112680d0219 Mon Sep 17 00:00:00 2001 From: Longyin Huang Date: Wed, 24 May 2023 03:18:53 -0700 Subject: [PATCH 4/5] Unify display format --- sonic_platform_base/sonic_xcvr/api/public/cmis.py | 8 +++++--- .../sonic_xcvr/api/public/sff8436.py | 14 ++++++++------ .../sonic_xcvr/api/public/sff8472.py | 14 ++++++++------ .../sonic_xcvr/api/public/sff8636.py | 14 ++++++++------ tests/sonic_xcvr/test_cmis.py | 10 ++++------ 5 files changed, 33 insertions(+), 27 deletions(-) diff --git a/sonic_platform_base/sonic_xcvr/api/public/cmis.py b/sonic_platform_base/sonic_xcvr/api/public/cmis.py index 961ebcbd9..74ca45d25 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/cmis.py @@ -1728,9 +1728,11 @@ def get_transceiver_status(self): if rx_output_status_dict: for lane in range(1, self.NUM_CHANNELS+1): trans_status['rxoutput_status_hostlane%d' % lane] = rx_output_status_dict.get('RxOutputStatus%d' % lane) - if self.get_tx_disable_support(): - trans_status['tx_disabled_channel'] = self.get_tx_disable_channel() - tx_disable = self.get_tx_disable() + tx_disabled_channel = self.get_tx_disable_channel() + if tx_disabled_channel is not None: + trans_status['tx_disabled_channel'] = tx_disabled_channel + tx_disable = self.get_tx_disable() + if tx_disable is not None: for lane in range(1, self.NUM_CHANNELS+1): trans_status['tx%ddisable' % lane] = tx_disable[lane - 1] tx_fault = self.get_tx_fault() diff --git a/sonic_platform_base/sonic_xcvr/api/public/sff8436.py b/sonic_platform_base/sonic_xcvr/api/public/sff8436.py index 73421e421..152b1281e 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/sff8436.py +++ b/sonic_platform_base/sonic_xcvr/api/public/sff8436.py @@ -80,12 +80,14 @@ def get_transceiver_status(self): if read_failed: return None - trans_status = { - "rx_los": all(rx_los) if self.get_rx_los_support() else 'N/A', - "tx_fault": all(tx_fault) if self.get_tx_fault_support() else 'N/A', - "tx_disable": all(tx_disable), - "tx_disabled_channel": tx_disabled_channel - } + trans_status = dict() + for lane in range(1, len(rx_los) + 1): + trans_status['rxlos%d' % lane] = rx_los[lane - 1] + for lane in range(1, len(tx_fault) + 1): + trans_status['txfault%d' % lane] = tx_fault[lane - 1] + for lane in range(1, len(tx_disable) + 1): + trans_status['tx%ddisable' % lane] = tx_disable[lane - 1] + trans_status['tx_disabled_channel'] = tx_disabled_channel return trans_status diff --git a/sonic_platform_base/sonic_xcvr/api/public/sff8472.py b/sonic_platform_base/sonic_xcvr/api/public/sff8472.py index eadfa5426..096f0cfc5 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/sff8472.py +++ b/sonic_platform_base/sonic_xcvr/api/public/sff8472.py @@ -72,12 +72,14 @@ def get_transceiver_status(self): if read_failed: return None - trans_status = { - "rx_los": all(rx_los) if self.get_rx_los_support() else 'N/A', - "tx_fault": all(tx_fault) if self.get_tx_fault_support() else 'N/A', - "tx_disable": all(tx_disable), - "tx_disabled_channel": tx_disabled_channel - } + trans_status = dict() + for lane in range(1, len(rx_los) + 1): + trans_status['rxlos%d' % lane] = rx_los[lane - 1] + for lane in range(1, len(tx_fault) + 1): + trans_status['txfault%d' % lane] = tx_fault[lane - 1] + for lane in range(1, len(tx_disable) + 1): + trans_status['tx%ddisable' % lane] = tx_disable[lane - 1] + trans_status['tx_disabled_channel'] = tx_disabled_channel return trans_status diff --git a/sonic_platform_base/sonic_xcvr/api/public/sff8636.py b/sonic_platform_base/sonic_xcvr/api/public/sff8636.py index 2c26cc1f4..9c4d34214 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/sff8636.py +++ b/sonic_platform_base/sonic_xcvr/api/public/sff8636.py @@ -87,12 +87,14 @@ def get_transceiver_status(self): if read_failed: return None - trans_status = { - "rx_los": all(rx_los) if self.get_rx_los_support() else 'N/A', - "tx_fault": all(tx_fault) if self.get_tx_fault_support() else 'N/A', - "tx_disable": all(tx_disable), - "tx_disabled_channel": tx_disabled_channel - } + trans_status = dict() + for lane in range(1, len(rx_los) + 1): + trans_status['rxlos%d' % lane] = rx_los[lane - 1] + for lane in range(1, len(tx_fault) + 1): + trans_status['txfault%d' % lane] = tx_fault[lane - 1] + for lane in range(1, len(tx_disable) + 1): + trans_status['tx%ddisable' % lane] = tx_disable[lane - 1] + trans_status['tx_disabled_channel'] = tx_disabled_channel return trans_status diff --git a/tests/sonic_xcvr/test_cmis.py b/tests/sonic_xcvr/test_cmis.py index 75cf7f086..09e8aff98 100644 --- a/tests/sonic_xcvr/test_cmis.py +++ b/tests/sonic_xcvr/test_cmis.py @@ -1572,7 +1572,7 @@ def test_get_transceiver_threshold_info(self, mock_response, expected): 'Pre-FEC BER Average Media Input':{1:[0.001, 0.0125, 0, 0.01, 0, False, False, False, False]}, 'Errored Frames Average Media Input':{1:[0, 1, 0, 1, 0, False, False, False, False]}, }, - True, 0, [False, False, False, False, False, False, False, False] + 0, [False, False, False, False, False, False, False, False] ], { 'module_state': 'ModuleReady', @@ -1816,7 +1816,7 @@ def test_get_transceiver_threshold_info(self, mock_response, expected): 'Pre-FEC BER Average Media Input':{1:[0.001, 0.0125, 0, 0.01, 0, False, False, False, False]}, 'Errored Frames Average Media Input':{1:[0, 1, 0, 1, 0, False, False, False, False]}, }, - False, 0, [False, False, False, False, False, False, False, False] + None, None ], { 'module_state': 'ModuleReady', @@ -1875,12 +1875,10 @@ def test_get_transceiver_status(self, mock_response, expected): self.api.get_tx_bias_flag.return_value = mock_response[18] self.api.get_vdm = MagicMock() self.api.get_vdm.return_value = mock_response[19] - self.api.get_tx_disable_support = MagicMock() - self.api.get_tx_disable_support.return_value = mock_response[20] self.api.get_tx_disable_channel = MagicMock() - self.api.get_tx_disable_channel.return_value = mock_response[21] + self.api.get_tx_disable_channel.return_value = mock_response[20] self.api.get_tx_disable = MagicMock() - self.api.get_tx_disable.return_value = mock_response[22] + self.api.get_tx_disable.return_value = mock_response[21] result = self.api.get_transceiver_status() assert result == expected From 1accb8f7c47495d64d15cba293b805464c6e1f59 Mon Sep 17 00:00:00 2001 From: Longyin Huang Date: Wed, 24 May 2023 03:57:49 -0700 Subject: [PATCH 5/5] Add testcases non-CMIS --- tests/sonic_xcvr/test_sff8436.py | 45 +++++++++++++++++++++++++++++++ tests/sonic_xcvr/test_sff8472.py | 37 +++++++++++++++++++++++++ tests/sonic_xcvr/test_sff8636.py | 46 ++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) diff --git a/tests/sonic_xcvr/test_sff8436.py b/tests/sonic_xcvr/test_sff8436.py index 8567f5f27..1c192e7d0 100644 --- a/tests/sonic_xcvr/test_sff8436.py +++ b/tests/sonic_xcvr/test_sff8436.py @@ -156,3 +156,48 @@ def test_set_lpmode(self): self.api.get_power_override_support.return_value = False assert not self.api.set_lpmode(True) + @pytest.mark.parametrize("mock_response, expected",[ + ( + [ + [False, False, False, False], + [False, False, False, False], + 0, + [False, False, False, False] + ], + { + "tx_disabled_channel": 0, + "tx1disable": False, + "tx2disable": False, + "tx3disable": False, + "tx4disable": False, + 'txfault1': False, + 'txfault2': False, + 'txfault3': False, + 'txfault4': False, + 'rxlos1': False, + 'rxlos2': False, + 'rxlos3': False, + 'rxlos4': False, + } + ), + ( + [ + None, + None, + None, + None + ], + None + ) + ]) + def test_get_transceiver_status(self, mock_response, expected): + self.api.get_rx_los = MagicMock() + self.api.get_rx_los.return_value = mock_response[0] + self.api.get_tx_fault = MagicMock() + self.api.get_tx_fault.return_value = mock_response[1] + self.api.get_tx_disable_channel = MagicMock() + self.api.get_tx_disable_channel.return_value = mock_response[2] + self.api.get_tx_disable = MagicMock() + self.api.get_tx_disable.return_value = mock_response[3] + result = self.api.get_transceiver_status() + assert result == expected diff --git a/tests/sonic_xcvr/test_sff8472.py b/tests/sonic_xcvr/test_sff8472.py index 438e2fa75..f5e31ac3c 100644 --- a/tests/sonic_xcvr/test_sff8472.py +++ b/tests/sonic_xcvr/test_sff8472.py @@ -206,3 +206,40 @@ def mock_read_raw(offset, size): except: assert 0, traceback.format_exc() run_num -= 1 + + @pytest.mark.parametrize("mock_response, expected",[ + ( + [ + [False], + [False], + 0, + [False] + ], + { + "tx_disabled_channel": 0, + "tx1disable": False, + 'txfault1': False, + 'rxlos1': False, + } + ), + ( + [ + None, + None, + None, + None + ], + None + ) + ]) + def test_get_transceiver_status(self, mock_response, expected): + self.api.get_rx_los = MagicMock() + self.api.get_rx_los.return_value = mock_response[0] + self.api.get_tx_fault = MagicMock() + self.api.get_tx_fault.return_value = mock_response[1] + self.api.get_tx_disable_channel = MagicMock() + self.api.get_tx_disable_channel.return_value = mock_response[2] + self.api.get_tx_disable = MagicMock() + self.api.get_tx_disable.return_value = mock_response[3] + result = self.api.get_transceiver_status() + assert result == expected diff --git a/tests/sonic_xcvr/test_sff8636.py b/tests/sonic_xcvr/test_sff8636.py index 3ae40a3b7..7b337b9ae 100644 --- a/tests/sonic_xcvr/test_sff8636.py +++ b/tests/sonic_xcvr/test_sff8636.py @@ -155,3 +155,49 @@ def test_set_lpmode(self): self.api.get_lpmode_support.return_value = False self.api.get_power_override_support.return_value = False assert not self.api.set_lpmode(True) + + @pytest.mark.parametrize("mock_response, expected",[ + ( + [ + [False, False, False, False], + [False, False, False, False], + 0, + [False, False, False, False] + ], + { + "tx_disabled_channel": 0, + "tx1disable": False, + "tx2disable": False, + "tx3disable": False, + "tx4disable": False, + 'txfault1': False, + 'txfault2': False, + 'txfault3': False, + 'txfault4': False, + 'rxlos1': False, + 'rxlos2': False, + 'rxlos3': False, + 'rxlos4': False, + } + ), + ( + [ + None, + None, + None, + None + ], + None + ) + ]) + def test_get_transceiver_status(self, mock_response, expected): + self.api.get_rx_los = MagicMock() + self.api.get_rx_los.return_value = mock_response[0] + self.api.get_tx_fault = MagicMock() + self.api.get_tx_fault.return_value = mock_response[1] + self.api.get_tx_disable_channel = MagicMock() + self.api.get_tx_disable_channel.return_value = mock_response[2] + self.api.get_tx_disable = MagicMock() + self.api.get_tx_disable.return_value = mock_response[3] + result = self.api.get_transceiver_status() + assert result == expected