From 796fb35305aa47465db1de34013f33490b27abec Mon Sep 17 00:00:00 2001 From: Mridul Bajpai Date: Mon, 19 Jun 2023 11:57:03 -0700 Subject: [PATCH 1/8] Voltage sensor monitoring platform common changes. --- sonic_platform_base/__init__.py | 1 + sonic_platform_base/chassis_base.py | 45 ++++++++++ sonic_platform_base/module_base.py | 44 ++++++++++ sonic_platform_base/vsensor_base.py | 128 ++++++++++++++++++++++++++++ 4 files changed, 218 insertions(+) create mode 100644 sonic_platform_base/vsensor_base.py diff --git a/sonic_platform_base/__init__.py b/sonic_platform_base/__init__.py index 3d7f64b24..2918576af 100644 --- a/sonic_platform_base/__init__.py +++ b/sonic_platform_base/__init__.py @@ -8,4 +8,5 @@ from . import psu_base from . import sfp_base from . import thermal_base +from . import vsensor_base from . import watchdog_base diff --git a/sonic_platform_base/chassis_base.py b/sonic_platform_base/chassis_base.py index 877d9c849..7ffd1d170 100644 --- a/sonic_platform_base/chassis_base.py +++ b/sonic_platform_base/chassis_base.py @@ -54,6 +54,7 @@ def __init__(self): # List of ThermalBase-derived objects representing all thermals # available on the chassis self._thermal_list = [] + self._vsensor_list = [] # List of SfpBase-derived objects representing all sfps # available on the chassis @@ -451,6 +452,50 @@ def get_thermal_manager(self): """ raise NotImplementedError + ############################################## + # Voltage Sensor Methods + ############################################## + + def get_num_vsensors(self): + """ + Retrieves the number of voltage sensors available on this chassis + + Returns: + An integer, the number of voltage sensors available on this chassis + """ + return len(self._vsensor_list) + + def get_all_vsensors(self): + """ + Retrieves all voltage sensors available on this chassis + + Returns: + A list of objects derived from VsensorBase representing all voltage + sensors available on this chassis + """ + return self._vsensor_list + + def get_vsensor(self, index): + """ + Retrieves voltage sensors unit represented by (0-based) index + + Args: + index: An integer, the index (0-based) of the voltage sensor to + retrieve + + Returns: + An object dervied from VsensorBase representing the specified voltage sensor + """ + vsensor = None + + try: + vsensor = self._vsensor_list[index] + except IndexError: + sys.stderr.write("Voltage sensor index {} out of range (0-{})\n".format( + index, len(self._vsensor_list)-1)) + + return vsensor + ############################################## # SFP methods ############################################## diff --git a/sonic_platform_base/module_base.py b/sonic_platform_base/module_base.py index 3e96f8b24..8542dd4e8 100644 --- a/sonic_platform_base/module_base.py +++ b/sonic_platform_base/module_base.py @@ -66,6 +66,7 @@ def __init__(self): # List of ThermalBase-derived objects representing all thermals # available on the module self._thermal_list = [] + self._vsensor_list = [] # List of SfpBase-derived objects representing all sfps # available on the module @@ -373,6 +374,49 @@ def get_thermal(self, index): return thermal ############################################## + # Voltage sensor methods + ############################################## + + def get_num_vsensors(self): + """ + Retrieves the number of voltage sensors available on this module + + Returns: + An integer, the number of voltage sensors available on this module + """ + return len(self._vsensor_list) + + def get_all_vsensors(self): + """ + Retrieves all voltage sensors available on this module + + Returns: + A list of objects derived from VsensorBase representing all voltage sensors + available on this module + """ + return self._vsensor_list + + def get_vsensor(self, index): + """ + Retrieves voltage sensor unit represented by (0-based) index + + Args: + index: An integer, the index (0-based) of the vsensor to + retrieve + + Returns: + An object dervied from VsensorBase representing the specified vsensor + """ + vsensor = None + + try: + vsensor = self._vsensor_list[index] + except IndexError: + sys.stderr.write("Voltage sensor index {} out of range (0-{})\n".format( + index, len(self._vsensor_list)-1)) + + return vsensor + ############################################## # SFP methods ############################################## diff --git a/sonic_platform_base/vsensor_base.py b/sonic_platform_base/vsensor_base.py new file mode 100644 index 000000000..1ab64c530 --- /dev/null +++ b/sonic_platform_base/vsensor_base.py @@ -0,0 +1,128 @@ +""" + vsensor_base.py + + Abstract base class for implementing a platform-specific class with which + to interact with a voltage sensor module in SONiC +""" + +from . import device_base + + +class VsensorBase(device_base.DeviceBase): + """ + Abstract base class for interfacing with a voltage sensor module + """ + # Device type definition. Note, this is a constant. + DEVICE_TYPE = "vsensor" + + def get_voltage(self): + """ + Retrieves current voltage reading from voltage sensor + + Returns: + Current voltage in Millivolts. + """ + raise NotImplementedError + + + def get_high_threshold(self): + """ + Retrieves the high threshold voltage of voltage sensor + + Returns: + High voltage threshold in Millivolts. + """ + raise NotImplementedError + + def get_low_threshold(self): + """ + Retrieves the low threshold voltage of voltage sensor + + Returns: + Low voltage threshold in Millivolts + """ + raise NotImplementedError + + def set_high_threshold(self, voltage): + """ + Sets the high threshold voltage of voltage sensor + + Args : + voltage: Value in Millivolts + + Returns: + A boolean, True if threshold is set successfully, False if not + """ + raise NotImplementedError + + def set_low_threshold(self, voltage): + """ + Sets the low threshold voltage of voltage sensor + + Args : + voltage: Value in Millivolts + + Returns: + A boolean, True if threshold is set successfully, False if not + """ + raise NotImplementedError + + def get_high_critical_threshold(self): + """ + Retrieves the high critical threshold voltage of voltage sensor + + Returns: + The high critical threshold voltage of sensor in Millivolts + """ + raise NotImplementedError + + def get_low_critical_threshold(self): + """ + Retrieves the low critical threshold voltage of voltage sensor + + Returns: + The low critical threshold voltage of voltage sensor in Millivolts + """ + raise NotImplementedError + + def set_high_critical_threshold(self, voltage): + """ + Sets the critical high threshold voltage of voltage sensor + + Args : + voltage: Value in Millivolts + + Returns: + A boolean, True if threshold is set successfully, False if not + """ + raise NotImplementedError + + def set_low_critical_threshold(self, voltage): + """ + Sets the critical low threshold voltage of voltage sensor + + Args : + voltage: Value in Millivolts + + Returns: + A boolean, True if threshold is set successfully, False if not + """ + raise NotImplementedError + + def get_minimum_recorded(self): + """ + Retrieves the minimum recorded voltage of voltage sensor + + Returns: + The minimum recorded voltage of voltage sensor in Millivolts + """ + raise NotImplementedError + + def get_maximum_recorded(self): + """ + Retrieves the maximum recorded voltage of voltage sensor + + Returns: + The maximum recorded voltage of voltage sensor in Millivolts + """ + raise NotImplementedError From d1b44980aeca85c9d4a4376b7cde3aca6a69064d Mon Sep 17 00:00:00 2001 From: Mridul Bajpai Date: Wed, 28 Jun 2023 09:29:27 -0700 Subject: [PATCH 2/8] Added current sensor support --- sonic_platform_base/__init__.py | 1 + sonic_platform_base/chassis_base.py | 45 ++++++++++ sonic_platform_base/isensor_base.py | 128 ++++++++++++++++++++++++++++ sonic_platform_base/module_base.py | 62 ++++++++++++-- 4 files changed, 228 insertions(+), 8 deletions(-) create mode 100644 sonic_platform_base/isensor_base.py diff --git a/sonic_platform_base/__init__.py b/sonic_platform_base/__init__.py index 2918576af..0bc8c86ac 100644 --- a/sonic_platform_base/__init__.py +++ b/sonic_platform_base/__init__.py @@ -9,4 +9,5 @@ from . import sfp_base from . import thermal_base from . import vsensor_base +from . import isensor_base from . import watchdog_base diff --git a/sonic_platform_base/chassis_base.py b/sonic_platform_base/chassis_base.py index 7ffd1d170..d7b2139d4 100644 --- a/sonic_platform_base/chassis_base.py +++ b/sonic_platform_base/chassis_base.py @@ -55,6 +55,7 @@ def __init__(self): # available on the chassis self._thermal_list = [] self._vsensor_list = [] + self._isensor_list = [] # List of SfpBase-derived objects representing all sfps # available on the chassis @@ -496,6 +497,50 @@ def get_vsensor(self, index): return vsensor + ############################################## + # Current Sensor Methods + ############################################## + + def get_num_isensors(self): + """ + Retrieves the number of current sensors available on this chassis + + Returns: + An integer, the number of current sensors available on this chassis + """ + return len(self._isensor_list) + + def get_all_isensors(self): + """ + Retrieves all isensors available on this chassis + + Returns: + A list of objects derived from ThermalBase representing all isensors + available on this chassis + """ + return self._isensor_list + + def get_isensor(self, index): + """ + Retrieves isensor unit represented by (0-based) index + + Args: + index: An integer, the index (0-based) of the isensor to + retrieve + + Returns: + An object dervied from ThermalBase representing the specified isensor + """ + isensor = None + + try: + isensor = self._isensor_list[index] + except IndexError: + sys.stderr.write("isensor index {} out of range (0-{})\n".format( + index, len(self._isensor_list)-1)) + + return isensor + ############################################## # SFP methods ############################################## diff --git a/sonic_platform_base/isensor_base.py b/sonic_platform_base/isensor_base.py new file mode 100644 index 000000000..3994622e7 --- /dev/null +++ b/sonic_platform_base/isensor_base.py @@ -0,0 +1,128 @@ +""" + isensor_base.py + + Abstract base class for implementing a platform-specific class with which + to interact with a isensor module in SONiC +""" + +from . import device_base + + +class IsensorBase(device_base.DeviceBase): + """ + Abstract base class for interfacing with a isensor module + """ + # Device type definition. Note, this is a constant. + DEVICE_TYPE = "isensor" + + def get_current(self): + """ + Retrieves current current reading from isensor + + Returns: + Current current in Milliamps. + """ + raise NotImplementedError + + + def get_high_threshold(self): + """ + Retrieves the high threshold current of isensor + + Returns: + High current threshold in Milliamps. + """ + raise NotImplementedError + + def get_low_threshold(self): + """ + Retrieves the low threshold current of isensor + + Returns: + Low current threshold in Milliamps + """ + raise NotImplementedError + + def set_high_threshold(self, current): + """ + Sets the high threshold current of isensor + + Args : + current: Value in Milliamps + + Returns: + A boolean, True if threshold is set successfully, False if not + """ + raise NotImplementedError + + def set_low_threshold(self, current): + """ + Sets the low threshold current of isensor + + Args : + current: Value in Milliamps + + Returns: + A boolean, True if threshold is set successfully, False if not + """ + raise NotImplementedError + + def get_high_critical_threshold(self): + """ + Retrieves the high critical threshold current of isensor + + Returns: + The high critical threshold current of sensor in Milliamps + """ + raise NotImplementedError + + def get_low_critical_threshold(self): + """ + Retrieves the low critical threshold current of isensor + + Returns: + The low critical threshold current of isensor in Milliamps + """ + raise NotImplementedError + + def set_high_critical_threshold(self, current): + """ + Sets the critical high threshold current of isensor + + Args : + current: Value in Milliamps + + Returns: + A boolean, True if threshold is set successfully, False if not + """ + raise NotImplementedError + + def set_low_critical_threshold(self, current): + """ + Sets the critical low threshold current of isensor + + Args : + current: Value in Milliamps + + Returns: + A boolean, True if threshold is set successfully, False if not + """ + raise NotImplementedError + + def get_minimum_recorded(self): + """ + Retrieves the minimum recorded current of isensor + + Returns: + The minimum recorded current of isensor in Milliamps + """ + raise NotImplementedError + + def get_maximum_recorded(self): + """ + Retrieves the maximum recorded current of isensor + + Returns: + The maximum recorded current of isensor in Milliamps + """ + raise NotImplementedError diff --git a/sonic_platform_base/module_base.py b/sonic_platform_base/module_base.py index 8542dd4e8..9e7824867 100644 --- a/sonic_platform_base/module_base.py +++ b/sonic_platform_base/module_base.py @@ -67,6 +67,7 @@ def __init__(self): # available on the module self._thermal_list = [] self._vsensor_list = [] + self._isensor_list = [] # List of SfpBase-derived objects representing all sfps # available on the module @@ -374,48 +375,93 @@ def get_thermal(self, index): return thermal ############################################## - # Voltage sensor methods + # Vsensor methods ############################################## def get_num_vsensors(self): """ - Retrieves the number of voltage sensors available on this module + Retrieves the number of vsensors available on this module Returns: - An integer, the number of voltage sensors available on this module + An integer, the number of vsensors available on this module """ return len(self._vsensor_list) def get_all_vsensors(self): """ - Retrieves all voltage sensors available on this module + Retrieves all vsensors available on this module Returns: - A list of objects derived from VsensorBase representing all voltage sensors + A list of objects derived from ThermalBase representing all vsensors available on this module """ return self._vsensor_list def get_vsensor(self, index): """ - Retrieves voltage sensor unit represented by (0-based) index + Retrieves vsensor unit represented by (0-based) index Args: index: An integer, the index (0-based) of the vsensor to retrieve Returns: - An object dervied from VsensorBase representing the specified vsensor + An object dervied from ThermalBase representing the specified vsensor """ vsensor = None try: vsensor = self._vsensor_list[index] except IndexError: - sys.stderr.write("Voltage sensor index {} out of range (0-{})\n".format( + sys.stderr.write("VSENSOR index {} out of range (0-{})\n".format( index, len(self._vsensor_list)-1)) return vsensor + + ############################################## + # Isensor methods + ############################################## + + def get_num_Isensors(self): + """ + Retrieves the number of Isensors available on this module + + Returns: + An integer, the number of Isensors available on this module + """ + return len(self._Isensor_list) + + def get_all_isensors(self): + """ + Retrieves all isensors available on this module + + Returns: + A list of objects derived from ThermalBase representing all isensors + available on this module + """ + return self._isensor_list + + def get_isensor(self, index): + """ + Retrieves isensor unit represented by (0-based) index + + Args: + index: An integer, the index (0-based) of the isensor to + retrieve + + Returns: + An object dervied from ThermalBase representing the specified isensor + """ + isensor = None + + try: + isensor = self._isensor_list[index] + except IndexError: + sys.stderr.write("ISENSOR index {} out of range (0-{})\n".format( + index, len(self._isensor_list)-1)) + + return isensor + ############################################## # SFP methods ############################################## From d269261f73e8ea90aad8bdb738903a46aa22f324 Mon Sep 17 00:00:00 2001 From: Mridul Bajpai Date: Wed, 19 Jul 2023 18:10:17 -0700 Subject: [PATCH 3/8] Consolidated sensor changes. --- sonic_platform_base/__init__.py | 3 +- sonic_platform_base/chassis_base.py | 17 +-- sonic_platform_base/isensor_base.py | 128 --------------------- sonic_platform_base/module_base.py | 41 +++---- sonic_platform_base/sensor_base.py | 172 ++++++++++++++++++++++++++++ sonic_platform_base/vsensor_base.py | 128 --------------------- 6 files changed, 203 insertions(+), 286 deletions(-) delete mode 100644 sonic_platform_base/isensor_base.py create mode 100644 sonic_platform_base/sensor_base.py delete mode 100644 sonic_platform_base/vsensor_base.py diff --git a/sonic_platform_base/__init__.py b/sonic_platform_base/__init__.py index 0bc8c86ac..45ece3cfe 100644 --- a/sonic_platform_base/__init__.py +++ b/sonic_platform_base/__init__.py @@ -8,6 +8,5 @@ from . import psu_base from . import sfp_base from . import thermal_base -from . import vsensor_base -from . import isensor_base +from . import sensor_base from . import watchdog_base diff --git a/sonic_platform_base/chassis_base.py b/sonic_platform_base/chassis_base.py index d7b2139d4..285322a74 100644 --- a/sonic_platform_base/chassis_base.py +++ b/sonic_platform_base/chassis_base.py @@ -478,7 +478,7 @@ def get_all_vsensors(self): def get_vsensor(self, index): """ - Retrieves voltage sensors unit represented by (0-based) index + Retrieves voltage sensor unit represented by (0-based) index Args: index: An integer, the index (0-based) of the voltage sensor to @@ -512,31 +512,32 @@ def get_num_isensors(self): def get_all_isensors(self): """ - Retrieves all isensors available on this chassis + Retrieves all Current sensors available on this chassis Returns: - A list of objects derived from ThermalBase representing all isensors - available on this chassis + A list of objects derived from IsensorBase representing all current + sensors available on this chassis """ return self._isensor_list def get_isensor(self, index): """ - Retrieves isensor unit represented by (0-based) index + Retrieves current sensor object represented by (0-based) index Args: - index: An integer, the index (0-based) of the isensor to + index: An integer, the index (0-based) of the current sensor to retrieve Returns: - An object dervied from ThermalBase representing the specified isensor + An object dervied from IsensorBase representing the specified Current + sensor """ isensor = None try: isensor = self._isensor_list[index] except IndexError: - sys.stderr.write("isensor index {} out of range (0-{})\n".format( + sys.stderr.write("Current sensor index {} out of range (0-{})\n".format( index, len(self._isensor_list)-1)) return isensor diff --git a/sonic_platform_base/isensor_base.py b/sonic_platform_base/isensor_base.py deleted file mode 100644 index 3994622e7..000000000 --- a/sonic_platform_base/isensor_base.py +++ /dev/null @@ -1,128 +0,0 @@ -""" - isensor_base.py - - Abstract base class for implementing a platform-specific class with which - to interact with a isensor module in SONiC -""" - -from . import device_base - - -class IsensorBase(device_base.DeviceBase): - """ - Abstract base class for interfacing with a isensor module - """ - # Device type definition. Note, this is a constant. - DEVICE_TYPE = "isensor" - - def get_current(self): - """ - Retrieves current current reading from isensor - - Returns: - Current current in Milliamps. - """ - raise NotImplementedError - - - def get_high_threshold(self): - """ - Retrieves the high threshold current of isensor - - Returns: - High current threshold in Milliamps. - """ - raise NotImplementedError - - def get_low_threshold(self): - """ - Retrieves the low threshold current of isensor - - Returns: - Low current threshold in Milliamps - """ - raise NotImplementedError - - def set_high_threshold(self, current): - """ - Sets the high threshold current of isensor - - Args : - current: Value in Milliamps - - Returns: - A boolean, True if threshold is set successfully, False if not - """ - raise NotImplementedError - - def set_low_threshold(self, current): - """ - Sets the low threshold current of isensor - - Args : - current: Value in Milliamps - - Returns: - A boolean, True if threshold is set successfully, False if not - """ - raise NotImplementedError - - def get_high_critical_threshold(self): - """ - Retrieves the high critical threshold current of isensor - - Returns: - The high critical threshold current of sensor in Milliamps - """ - raise NotImplementedError - - def get_low_critical_threshold(self): - """ - Retrieves the low critical threshold current of isensor - - Returns: - The low critical threshold current of isensor in Milliamps - """ - raise NotImplementedError - - def set_high_critical_threshold(self, current): - """ - Sets the critical high threshold current of isensor - - Args : - current: Value in Milliamps - - Returns: - A boolean, True if threshold is set successfully, False if not - """ - raise NotImplementedError - - def set_low_critical_threshold(self, current): - """ - Sets the critical low threshold current of isensor - - Args : - current: Value in Milliamps - - Returns: - A boolean, True if threshold is set successfully, False if not - """ - raise NotImplementedError - - def get_minimum_recorded(self): - """ - Retrieves the minimum recorded current of isensor - - Returns: - The minimum recorded current of isensor in Milliamps - """ - raise NotImplementedError - - def get_maximum_recorded(self): - """ - Retrieves the maximum recorded current of isensor - - Returns: - The maximum recorded current of isensor in Milliamps - """ - raise NotImplementedError diff --git a/sonic_platform_base/module_base.py b/sonic_platform_base/module_base.py index 9e7824867..f0a1fdd00 100644 --- a/sonic_platform_base/module_base.py +++ b/sonic_platform_base/module_base.py @@ -375,89 +375,90 @@ def get_thermal(self, index): return thermal ############################################## - # Vsensor methods + # Voltage Sensor methods ############################################## def get_num_vsensors(self): """ - Retrieves the number of vsensors available on this module + Retrieves the number of voltage sensors available on this module Returns: - An integer, the number of vsensors available on this module + An integer, the number of voltage sensors available on this module """ return len(self._vsensor_list) def get_all_vsensors(self): """ - Retrieves all vsensors available on this module + Retrieves all voltage sensors available on this module Returns: - A list of objects derived from ThermalBase representing all vsensors - available on this module + A list of objects derived from VsensorBase representing all voltage + sensors available on this module """ return self._vsensor_list def get_vsensor(self, index): """ - Retrieves vsensor unit represented by (0-based) index + Retrieves voltage sensor unit represented by (0-based) index Args: - index: An integer, the index (0-based) of the vsensor to + index: An integer, the index (0-based) of the voltage sensor to retrieve Returns: - An object dervied from ThermalBase representing the specified vsensor + An object dervied from VsensorBase representing the specified voltage + sensor """ vsensor = None try: vsensor = self._vsensor_list[index] except IndexError: - sys.stderr.write("VSENSOR index {} out of range (0-{})\n".format( + sys.stderr.write("Voltage sensor index {} out of range (0-{})\n".format( index, len(self._vsensor_list)-1)) return vsensor ############################################## - # Isensor methods + # Current sensor methods ############################################## def get_num_Isensors(self): """ - Retrieves the number of Isensors available on this module + Retrieves the number of Current sensors available on this module Returns: - An integer, the number of Isensors available on this module + An integer, the number of Current sensors available on this module """ return len(self._Isensor_list) def get_all_isensors(self): """ - Retrieves all isensors available on this module + Retrieves all current sensors available on this module Returns: - A list of objects derived from ThermalBase representing all isensors - available on this module + A list of objects derived from IsensorBase representing all current + sensors available on this module """ return self._isensor_list def get_isensor(self, index): """ - Retrieves isensor unit represented by (0-based) index + Retrieves Current sensor object represented by (0-based) index Args: - index: An integer, the index (0-based) of the isensor to + index: An integer, the index (0-based) of the current sensor to retrieve Returns: - An object dervied from ThermalBase representing the specified isensor + An object dervied from IsensorBase representing the specified isensor """ isensor = None try: isensor = self._isensor_list[index] except IndexError: - sys.stderr.write("ISENSOR index {} out of range (0-{})\n".format( + sys.stderr.write("Current sensor index {} out of range (0-{})\n".format( index, len(self._isensor_list)-1)) return isensor diff --git a/sonic_platform_base/sensor_base.py b/sonic_platform_base/sensor_base.py new file mode 100644 index 000000000..9dc3b8427 --- /dev/null +++ b/sonic_platform_base/sensor_base.py @@ -0,0 +1,172 @@ +""" + sensor_base.py + + Abstract base class for implementing a platform-specific class with which + to interact with a sensor module in SONiC +""" + +from . import device_base + +SENSOR_TYPE_VOLTAGE = 1 +SENSOR_TYPE_CURRENT = 2 + +class SensorBase(device_base.DeviceBase): + """ + Abstract base class for interfacing with a sensor module + """ + + def get_type(self): + """ + Specifies the type of the sensor. + + Returns: + Sensor type + """ + raise NotImplementedError + + def get_value(self): + """ + Retrieves measurement reported by sensor + + Returns: + Sensor measurement + """ + raise NotImplementedError + + def get_unit(self): + """ + Retrieves unit of measurement reported by sensor + + Returns: + Sensor measurement unit + """ + raise NotImplementedError + + def get_high_threshold(self): + """ + Retrieves the high threshold of sensor + + Returns: + High threshold + """ + raise NotImplementedError + + def get_low_threshold(self): + """ + Retrieves the low threshold + + Returns: + Low threshold + """ + raise NotImplementedError + + def set_high_threshold(self, value): + """ + Sets the high threshold value of sensor + + Args : + value: High threshold value to set + + Returns: + A boolean, True if threshold is set successfully, False if not + """ + raise NotImplementedError + + def set_low_threshold(self, value): + """ + Sets the low threshold value of sensor + + Args : + value: Value + + Returns: + A boolean, True if threshold is set successfully, False if not + """ + raise NotImplementedError + + def get_high_critical_threshold(self): + """ + Retrieves the high critical threshold value of sensor + + Returns: + The high critical threshold value of sensor + """ + raise NotImplementedError + + def get_low_critical_threshold(self): + """ + Retrieves the low critical threshold value of sensor + + Returns: + The low critical threshold value of sensor + """ + raise NotImplementedError + + def set_high_critical_threshold(self, value): + """ + Sets the critical high threshold value of sensor + + Args : + value: Critical high threshold Value + + Returns: + A boolean, True if threshold is set successfully, False if not + """ + raise NotImplementedError + + def set_low_critical_threshold(self, value): + """ + Sets the critical low threshold value of sensor + + Args : + value: Critial low threshold Value + + Returns: + A boolean, True if threshold is set successfully, False if not + """ + raise NotImplementedError + + def get_minimum_recorded(self): + """ + Retrieves the minimum recorded value of sensor + + Returns: + The minimum recorded value of sensor + """ + raise NotImplementedError + + def get_maximum_recorded(self): + """ + Retrieves the maximum recorded value of sensor + + Returns: + The maximum recorded value of sensor + """ + raise NotImplementedError + + + +class VsensorBase(SensorBase): + """ + Abstract base class for interfacing with a voltage sensor module + """ + MILLI_VOLTS = "mV" + + def get_type(self): + return SENSOR_TYPE_VOLTAGE + + def get_unit(self): + return MILLI_VOLTS + + +class IsensorBase(SensorBase): + """ + Abstract base class for interfacing with a current sensor module + """ + MILLI_AMPS = "mA" + + def get_type(self): + return SENSOR_TYPE_CURRENT + + def get_unit(self): + return MILLI_AMPS diff --git a/sonic_platform_base/vsensor_base.py b/sonic_platform_base/vsensor_base.py deleted file mode 100644 index 1ab64c530..000000000 --- a/sonic_platform_base/vsensor_base.py +++ /dev/null @@ -1,128 +0,0 @@ -""" - vsensor_base.py - - Abstract base class for implementing a platform-specific class with which - to interact with a voltage sensor module in SONiC -""" - -from . import device_base - - -class VsensorBase(device_base.DeviceBase): - """ - Abstract base class for interfacing with a voltage sensor module - """ - # Device type definition. Note, this is a constant. - DEVICE_TYPE = "vsensor" - - def get_voltage(self): - """ - Retrieves current voltage reading from voltage sensor - - Returns: - Current voltage in Millivolts. - """ - raise NotImplementedError - - - def get_high_threshold(self): - """ - Retrieves the high threshold voltage of voltage sensor - - Returns: - High voltage threshold in Millivolts. - """ - raise NotImplementedError - - def get_low_threshold(self): - """ - Retrieves the low threshold voltage of voltage sensor - - Returns: - Low voltage threshold in Millivolts - """ - raise NotImplementedError - - def set_high_threshold(self, voltage): - """ - Sets the high threshold voltage of voltage sensor - - Args : - voltage: Value in Millivolts - - Returns: - A boolean, True if threshold is set successfully, False if not - """ - raise NotImplementedError - - def set_low_threshold(self, voltage): - """ - Sets the low threshold voltage of voltage sensor - - Args : - voltage: Value in Millivolts - - Returns: - A boolean, True if threshold is set successfully, False if not - """ - raise NotImplementedError - - def get_high_critical_threshold(self): - """ - Retrieves the high critical threshold voltage of voltage sensor - - Returns: - The high critical threshold voltage of sensor in Millivolts - """ - raise NotImplementedError - - def get_low_critical_threshold(self): - """ - Retrieves the low critical threshold voltage of voltage sensor - - Returns: - The low critical threshold voltage of voltage sensor in Millivolts - """ - raise NotImplementedError - - def set_high_critical_threshold(self, voltage): - """ - Sets the critical high threshold voltage of voltage sensor - - Args : - voltage: Value in Millivolts - - Returns: - A boolean, True if threshold is set successfully, False if not - """ - raise NotImplementedError - - def set_low_critical_threshold(self, voltage): - """ - Sets the critical low threshold voltage of voltage sensor - - Args : - voltage: Value in Millivolts - - Returns: - A boolean, True if threshold is set successfully, False if not - """ - raise NotImplementedError - - def get_minimum_recorded(self): - """ - Retrieves the minimum recorded voltage of voltage sensor - - Returns: - The minimum recorded voltage of voltage sensor in Millivolts - """ - raise NotImplementedError - - def get_maximum_recorded(self): - """ - Retrieves the maximum recorded voltage of voltage sensor - - Returns: - The maximum recorded voltage of voltage sensor in Millivolts - """ - raise NotImplementedError From f9cb0a082c8c88f103b0aeb1bbbf4dd3af4d17c4 Mon Sep 17 00:00:00 2001 From: Mridul Bajpai Date: Tue, 8 Aug 2023 22:45:09 -0700 Subject: [PATCH 4/8] Addressed review comments --- sonic_platform_base/chassis_base.py | 50 +++++++++++++------------- sonic_platform_base/module_base.py | 54 ++++++++++++++--------------- sonic_platform_base/sensor_base.py | 12 +++---- 3 files changed, 58 insertions(+), 58 deletions(-) diff --git a/sonic_platform_base/chassis_base.py b/sonic_platform_base/chassis_base.py index 285322a74..6cd4403c6 100644 --- a/sonic_platform_base/chassis_base.py +++ b/sonic_platform_base/chassis_base.py @@ -54,8 +54,8 @@ def __init__(self): # List of ThermalBase-derived objects representing all thermals # available on the chassis self._thermal_list = [] - self._vsensor_list = [] - self._isensor_list = [] + self._voltage_sensor_list = [] + self._current_sensor_list = [] # List of SfpBase-derived objects representing all sfps # available on the chassis @@ -457,26 +457,26 @@ def get_thermal_manager(self): # Voltage Sensor Methods ############################################## - def get_num_vsensors(self): + def get_num_voltage_sensors(self): """ Retrieves the number of voltage sensors available on this chassis Returns: An integer, the number of voltage sensors available on this chassis """ - return len(self._vsensor_list) + return len(self._voltage_sensor_list) - def get_all_vsensors(self): + def get_all_voltage_sensors(self): """ Retrieves all voltage sensors available on this chassis Returns: - A list of objects derived from VsensorBase representing all voltage + A list of objects derived from VoltageSensorBase representing all voltage sensors available on this chassis """ - return self._vsensor_list + return self._voltage_sensor_list - def get_vsensor(self, index): + def get_voltage_sensor(self, index): """ Retrieves voltage sensor unit represented by (0-based) index @@ -485,42 +485,42 @@ def get_vsensor(self, index): retrieve Returns: - An object dervied from VsensorBase representing the specified voltage sensor + An object derived from VoltageSensorBase representing the specified voltage sensor """ - vsensor = None + voltage_sensor = None try: - vsensor = self._vsensor_list[index] + voltage_sensor = self._voltage_sensor_list[index] except IndexError: sys.stderr.write("Voltage sensor index {} out of range (0-{})\n".format( - index, len(self._vsensor_list)-1)) + index, len(self._voltage_sensor_list)-1)) - return vsensor + return voltage_sensor ############################################## # Current Sensor Methods ############################################## - def get_num_isensors(self): + def get_num_current_sensors(self): """ Retrieves the number of current sensors available on this chassis Returns: An integer, the number of current sensors available on this chassis """ - return len(self._isensor_list) + return len(self._current_sensor_list) - def get_all_isensors(self): + def get_all_current_sensors(self): """ - Retrieves all Current sensors available on this chassis + Retrieves all current sensors available on this chassis Returns: - A list of objects derived from IsensorBase representing all current + A list of objects derived from CurrentSensorBase representing all current sensors available on this chassis """ - return self._isensor_list + return self._current_sensor_list - def get_isensor(self, index): + def get_current_sensor(self, index): """ Retrieves current sensor object represented by (0-based) index @@ -529,18 +529,18 @@ def get_isensor(self, index): retrieve Returns: - An object dervied from IsensorBase representing the specified Current + An object derived from CurrentSensorBase representing the specified current sensor """ - isensor = None + current_sensor = None try: - isensor = self._isensor_list[index] + current_sensor = self._current_sensor_list[index] except IndexError: sys.stderr.write("Current sensor index {} out of range (0-{})\n".format( - index, len(self._isensor_list)-1)) + index, len(self._current_sensor_list)-1)) - return isensor + return current_sensor ############################################## # SFP methods diff --git a/sonic_platform_base/module_base.py b/sonic_platform_base/module_base.py index f0a1fdd00..48e718184 100644 --- a/sonic_platform_base/module_base.py +++ b/sonic_platform_base/module_base.py @@ -66,8 +66,8 @@ def __init__(self): # List of ThermalBase-derived objects representing all thermals # available on the module self._thermal_list = [] - self._vsensor_list = [] - self._isensor_list = [] + self._voltage_sensor_list = [] + self._current_sensor_list = [] # List of SfpBase-derived objects representing all sfps # available on the module @@ -378,26 +378,26 @@ def get_thermal(self, index): # Voltage Sensor methods ############################################## - def get_num_vsensors(self): + def get_num_voltage_sensors(self): """ Retrieves the number of voltage sensors available on this module Returns: An integer, the number of voltage sensors available on this module """ - return len(self._vsensor_list) + return len(self._voltage_sensor_list) - def get_all_vsensors(self): + def get_all_voltage_sensors(self): """ Retrieves all voltage sensors available on this module Returns: - A list of objects derived from VsensorBase representing all voltage + A list of objects derived from VoltageSensorBase representing all voltage sensors available on this module """ - return self._vsensor_list + return self._voltage_sensor_list - def get_vsensor(self, index): + def get_voltage_sensor(self, index): """ Retrieves voltage sensor unit represented by (0-based) index @@ -406,62 +406,62 @@ def get_vsensor(self, index): retrieve Returns: - An object dervied from VsensorBase representing the specified voltage + An object derived from VoltageSensorBase representing the specified voltage sensor """ - vsensor = None + voltage_sensor = None try: - vsensor = self._vsensor_list[index] + voltage_sensor = self._voltage_sensor_list[index] except IndexError: sys.stderr.write("Voltage sensor index {} out of range (0-{})\n".format( - index, len(self._vsensor_list)-1)) + index, len(self._voltage_sensor_list)-1)) - return vsensor + return voltage_sensor ############################################## # Current sensor methods ############################################## - def get_num_Isensors(self): + def get_num_CurrentSensors(self): """ - Retrieves the number of Current sensors available on this module + Retrieves the number of current sensors available on this module Returns: - An integer, the number of Current sensors available on this module + An integer, the number of current sensors available on this module """ - return len(self._Isensor_list) + return len(self._current_sensor_list) - def get_all_isensors(self): + def get_all_current_sensors(self): """ Retrieves all current sensors available on this module Returns: - A list of objects derived from IsensorBase representing all current + A list of objects derived from CurrentSensorBase representing all current sensors available on this module """ - return self._isensor_list + return self._current_sensor_list - def get_isensor(self, index): + def get_current_sensor(self, index): """ - Retrieves Current sensor object represented by (0-based) index + Retrieves current sensor object represented by (0-based) index Args: index: An integer, the index (0-based) of the current sensor to retrieve Returns: - An object dervied from IsensorBase representing the specified isensor + An object derived from CurrentSensorBase representing the specified current_sensor """ - isensor = None + current_sensor = None try: - isensor = self._isensor_list[index] + current_sensor = self._current_sensor_list[index] except IndexError: sys.stderr.write("Current sensor index {} out of range (0-{})\n".format( - index, len(self._isensor_list)-1)) + index, len(self._current_sensor_list)-1)) - return isensor + return current_sensor ############################################## # SFP methods diff --git a/sonic_platform_base/sensor_base.py b/sonic_platform_base/sensor_base.py index 9dc3b8427..742a20f43 100644 --- a/sonic_platform_base/sensor_base.py +++ b/sonic_platform_base/sensor_base.py @@ -64,7 +64,7 @@ def set_high_threshold(self, value): """ Sets the high threshold value of sensor - Args : + Args: value: High threshold value to set Returns: @@ -76,7 +76,7 @@ def set_low_threshold(self, value): """ Sets the low threshold value of sensor - Args : + Args: value: Value Returns: @@ -106,7 +106,7 @@ def set_high_critical_threshold(self, value): """ Sets the critical high threshold value of sensor - Args : + Args: value: Critical high threshold Value Returns: @@ -118,7 +118,7 @@ def set_low_critical_threshold(self, value): """ Sets the critical low threshold value of sensor - Args : + Args: value: Critial low threshold Value Returns: @@ -146,7 +146,7 @@ def get_maximum_recorded(self): -class VsensorBase(SensorBase): +class VoltageSensorBase(SensorBase): """ Abstract base class for interfacing with a voltage sensor module """ @@ -159,7 +159,7 @@ def get_unit(self): return MILLI_VOLTS -class IsensorBase(SensorBase): +class CurrentSensorBase(SensorBase): """ Abstract base class for interfacing with a current sensor module """ From 0d61b98ae3ba15fd604993ed93fd9dad214d3e3d Mon Sep 17 00:00:00 2001 From: Mridul Bajpai Date: Thu, 17 Aug 2023 22:59:09 -0700 Subject: [PATCH 5/8] Addressed review comments --- sonic_platform_base/module_base.py | 2 +- sonic_platform_base/sensor_base.py | 33 +++++++++---------- tests/sensor_base_test.py | 51 ++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 17 deletions(-) create mode 100644 tests/sensor_base_test.py diff --git a/sonic_platform_base/module_base.py b/sonic_platform_base/module_base.py index 48e718184..ccd507b44 100644 --- a/sonic_platform_base/module_base.py +++ b/sonic_platform_base/module_base.py @@ -423,7 +423,7 @@ def get_voltage_sensor(self, index): # Current sensor methods ############################################## - def get_num_CurrentSensors(self): + def get_num_current_sensors(self): """ Retrieves the number of current sensors available on this module diff --git a/sonic_platform_base/sensor_base.py b/sonic_platform_base/sensor_base.py index 742a20f43..9e2c20a71 100644 --- a/sonic_platform_base/sensor_base.py +++ b/sonic_platform_base/sensor_base.py @@ -7,17 +7,15 @@ from . import device_base -SENSOR_TYPE_VOLTAGE = 1 -SENSOR_TYPE_CURRENT = 2 - class SensorBase(device_base.DeviceBase): """ Abstract base class for interfacing with a sensor module """ - def get_type(self): + @classmethod + def get_type(cls): """ - Specifies the type of the sensor. + Specifies the type of the sensor such as current/voltage etc. Returns: Sensor type @@ -33,7 +31,8 @@ def get_value(self): """ raise NotImplementedError - def get_unit(self): + @classmethod + def get_unit(cls): """ Retrieves unit of measurement reported by sensor @@ -150,23 +149,25 @@ class VoltageSensorBase(SensorBase): """ Abstract base class for interfacing with a voltage sensor module """ - MILLI_VOLTS = "mV" - def get_type(self): - return SENSOR_TYPE_VOLTAGE + @classmethod + def get_type(cls): + return "SENSOR_TYPE_VOLTAGE" - def get_unit(self): - return MILLI_VOLTS + @classmethod + def get_unit(cls): + return "mV" class CurrentSensorBase(SensorBase): """ Abstract base class for interfacing with a current sensor module """ - MILLI_AMPS = "mA" - def get_type(self): - return SENSOR_TYPE_CURRENT + @classmethod + def get_type(cls): + return "SENSOR_TYPE_CURRENT" - def get_unit(self): - return MILLI_AMPS + @classmethod + def get_unit(cls): + return "mA" diff --git a/tests/sensor_base_test.py b/tests/sensor_base_test.py new file mode 100644 index 000000000..bba0d4fd4 --- /dev/null +++ b/tests/sensor_base_test.py @@ -0,0 +1,51 @@ +''' +Test sensor module base classes +''' + +from unittest import mock +from sonic_platform_base.sensor_base import SensorBase +from sonic_platform_base.sensor_base import VoltageSensorBase +from sonic_platform_base.sensor_base import CurrentSensorBase + +class TestSensorBase: + ''' + Collection of SensorBase test methods + ''' + @staticmethod + def test_sensor_base(): + ''' + Verify unimplemented methods + ''' + sensor = SensorBase() + not_implemented_methods = [ + (sensor.get_value,), + (sensor.get_high_threshold,), + (sensor.get_low_threshold,), + (sensor.set_high_threshold,0), + (sensor.set_low_threshold,0), + (sensor.get_high_critical_threshold,), + (sensor.set_high_critical_threshold,0), + (sensor.get_low_critical_threshold,), + (sensor.set_low_critical_threshold,0), + (sensor.get_minimum_recorded,), + (sensor.get_maximum_recorded,)] + + for method in not_implemented_methods: + expected_exception = False + try: + func = method[0] + args = method[1:] + func(*args) + except Exception as exc: + expected_exception = isinstance(exc, NotImplementedError) + assert expected_exception + + @staticmethod + def test_voltage_sensor_base(): + assert(VoltageSensorBase.get_type() == "SENSOR_TYPE_VOLTAGE") + assert(VoltageSensorBase.get_unit() == "mV") + + @staticmethod + def test_current_sensor_base(): + assert(CurrentSensorBase.get_type() == "SENSOR_TYPE_CURRENT") + assert(CurrentSensorBase.get_unit() == "mA") From 458fef226d87c78b6d4c58b40c51bc4ba74a0481 Mon Sep 17 00:00:00 2001 From: Mridul Bajpai Date: Fri, 18 Aug 2023 10:11:27 -0700 Subject: [PATCH 6/8] Added code coverage tests --- tests/chassis_base_test.py | 28 +++++++++++++--------------- tests/module_base_test.py | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 tests/module_base_test.py diff --git a/tests/chassis_base_test.py b/tests/chassis_base_test.py index d410ff4ae..1b94f38fd 100644 --- a/tests/chassis_base_test.py +++ b/tests/chassis_base_test.py @@ -17,20 +17,18 @@ def test_reboot_cause(self): assert(chassis.REBOOT_CAUSE_HARDWARE_RESET_FROM_ASIC == "Reset from ASIC") assert(chassis.REBOOT_CAUSE_NON_HARDWARE == "Non-Hardware") - def test_chassis_base(self): + def test_sensors(self): chassis = ChassisBase() - not_implemented_methods = [ - [chassis.get_uid_led], - [chassis.set_uid_led, "COLOR"], - ] + assert(chassis.get_num_voltage_sensors() == 0) + assert(chassis.get_all_voltage_sensors() == []) + assert(chassis.get_voltage_sensor(0) == None) + chassis._voltage_sensor_list = ["s1"] + assert(chassis.get_all_voltage_sensors() == ["s1"]) + assert(chassis.get_voltage_sensor(0) == "s1") + assert(chassis.get_num_current_sensors() == 0) + assert(chassis.get_all_current_sensors() == []) + assert(chassis.get_current_sensor(0) == None) + chassis._current_sensor_list = ["s1"] + assert(chassis.get_all_current_sensors() == ["s1"]) + assert(chassis.get_current_sensor(0) == "s1") - for method in not_implemented_methods: - exception_raised = False - try: - func = method[0] - args = method[1:] - func(*args) - except NotImplementedError: - exception_raised = True - - assert exception_raised \ No newline at end of file diff --git a/tests/module_base_test.py b/tests/module_base_test.py new file mode 100644 index 000000000..20d0ef05a --- /dev/null +++ b/tests/module_base_test.py @@ -0,0 +1,19 @@ +from sonic_platform_base.module_base import ModuleBase + +class TestModuleBase: + + def test_sensors(self): + module = ModuleBase() + assert(module.get_num_voltage_sensors() == 0) + assert(module.get_all_voltage_sensors() == []) + assert(module.get_voltage_sensor(0) == None) + module._voltage_sensor_list = ["s1"] + assert(module.get_all_voltage_sensors() == ["s1"]) + assert(module.get_voltage_sensor(0) == "s1") + assert(module.get_num_current_sensors() == 0) + assert(module.get_all_current_sensors() == []) + assert(module.get_current_sensor(0) == None) + module._current_sensor_list = ["s1"] + assert(module.get_all_current_sensors() == ["s1"]) + assert(module.get_current_sensor(0) == "s1") + From b48f4bccd7598b54b71ac04a3675a317363ef3c6 Mon Sep 17 00:00:00 2001 From: Mridul Bajpai Date: Fri, 18 Aug 2023 10:13:43 -0700 Subject: [PATCH 7/8] Revert "Added code coverage tests" This reverts commit 458fef226d87c78b6d4c58b40c51bc4ba74a0481. --- tests/chassis_base_test.py | 28 +++++++++++++++------------- tests/module_base_test.py | 19 ------------------- 2 files changed, 15 insertions(+), 32 deletions(-) delete mode 100644 tests/module_base_test.py diff --git a/tests/chassis_base_test.py b/tests/chassis_base_test.py index 1b94f38fd..d410ff4ae 100644 --- a/tests/chassis_base_test.py +++ b/tests/chassis_base_test.py @@ -17,18 +17,20 @@ def test_reboot_cause(self): assert(chassis.REBOOT_CAUSE_HARDWARE_RESET_FROM_ASIC == "Reset from ASIC") assert(chassis.REBOOT_CAUSE_NON_HARDWARE == "Non-Hardware") - def test_sensors(self): + def test_chassis_base(self): chassis = ChassisBase() - assert(chassis.get_num_voltage_sensors() == 0) - assert(chassis.get_all_voltage_sensors() == []) - assert(chassis.get_voltage_sensor(0) == None) - chassis._voltage_sensor_list = ["s1"] - assert(chassis.get_all_voltage_sensors() == ["s1"]) - assert(chassis.get_voltage_sensor(0) == "s1") - assert(chassis.get_num_current_sensors() == 0) - assert(chassis.get_all_current_sensors() == []) - assert(chassis.get_current_sensor(0) == None) - chassis._current_sensor_list = ["s1"] - assert(chassis.get_all_current_sensors() == ["s1"]) - assert(chassis.get_current_sensor(0) == "s1") + not_implemented_methods = [ + [chassis.get_uid_led], + [chassis.set_uid_led, "COLOR"], + ] + for method in not_implemented_methods: + exception_raised = False + try: + func = method[0] + args = method[1:] + func(*args) + except NotImplementedError: + exception_raised = True + + assert exception_raised \ No newline at end of file diff --git a/tests/module_base_test.py b/tests/module_base_test.py deleted file mode 100644 index 20d0ef05a..000000000 --- a/tests/module_base_test.py +++ /dev/null @@ -1,19 +0,0 @@ -from sonic_platform_base.module_base import ModuleBase - -class TestModuleBase: - - def test_sensors(self): - module = ModuleBase() - assert(module.get_num_voltage_sensors() == 0) - assert(module.get_all_voltage_sensors() == []) - assert(module.get_voltage_sensor(0) == None) - module._voltage_sensor_list = ["s1"] - assert(module.get_all_voltage_sensors() == ["s1"]) - assert(module.get_voltage_sensor(0) == "s1") - assert(module.get_num_current_sensors() == 0) - assert(module.get_all_current_sensors() == []) - assert(module.get_current_sensor(0) == None) - module._current_sensor_list = ["s1"] - assert(module.get_all_current_sensors() == ["s1"]) - assert(module.get_current_sensor(0) == "s1") - From 442887ad3704d9c859bd5aa791f26b364d0b167b Mon Sep 17 00:00:00 2001 From: Mridul Bajpai Date: Fri, 18 Aug 2023 10:20:38 -0700 Subject: [PATCH 8/8] Added unit tests --- tests/chassis_base_test.py | 17 ++++++++++++++++- tests/module_base_test.py | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/module_base_test.py diff --git a/tests/chassis_base_test.py b/tests/chassis_base_test.py index d410ff4ae..e550ce5f8 100644 --- a/tests/chassis_base_test.py +++ b/tests/chassis_base_test.py @@ -33,4 +33,19 @@ def test_chassis_base(self): except NotImplementedError: exception_raised = True - assert exception_raised \ No newline at end of file + assert exception_raised + + def test_sensors(self): + chassis = ChassisBase() + assert(chassis.get_num_voltage_sensors() == 0) + assert(chassis.get_all_voltage_sensors() == []) + assert(chassis.get_voltage_sensor(0) == None) + chassis._voltage_sensor_list = ["s1"] + assert(chassis.get_all_voltage_sensors() == ["s1"]) + assert(chassis.get_voltage_sensor(0) == "s1") + assert(chassis.get_num_current_sensors() == 0) + assert(chassis.get_all_current_sensors() == []) + assert(chassis.get_current_sensor(0) == None) + chassis._current_sensor_list = ["s1"] + assert(chassis.get_all_current_sensors() == ["s1"]) + assert(chassis.get_current_sensor(0) == "s1") diff --git a/tests/module_base_test.py b/tests/module_base_test.py new file mode 100644 index 000000000..20d0ef05a --- /dev/null +++ b/tests/module_base_test.py @@ -0,0 +1,19 @@ +from sonic_platform_base.module_base import ModuleBase + +class TestModuleBase: + + def test_sensors(self): + module = ModuleBase() + assert(module.get_num_voltage_sensors() == 0) + assert(module.get_all_voltage_sensors() == []) + assert(module.get_voltage_sensor(0) == None) + module._voltage_sensor_list = ["s1"] + assert(module.get_all_voltage_sensors() == ["s1"]) + assert(module.get_voltage_sensor(0) == "s1") + assert(module.get_num_current_sensors() == 0) + assert(module.get_all_current_sensors() == []) + assert(module.get_current_sensor(0) == None) + module._current_sensor_list = ["s1"] + assert(module.get_all_current_sensors() == ["s1"]) + assert(module.get_current_sensor(0) == "s1") +