[Mellanox] Adopt single way to get fan direction for all ASIC types (#7386)

#### Why I did it
Adopt a single way to get fan direction for all ASIC types.
It depends on hw-mgmt V.7.0010.2000.2303. Depends on https://github.com/Azure/sonic-buildimage/pull/7419

#### How I did it
Originally, the get_direction was implemented by fetching and parsing `/var/run/hw-management/system/fan_dir` on the Spectrum-2 and the Spectrum-3 systems. It isn't supported on the Spectrum system.
Now, it is implemented by fetching `/var/run/hw-management/thermal/fanX_dir` for all the platforms.

Signed-off-by: Stephen Sun <stephens@nvidia.com>
This commit is contained in:
Stephen Sun 2021-05-04 08:10:18 +08:00 committed by GitHub
parent 853c214951
commit b2286a24dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 15 deletions

View File

@ -10,7 +10,7 @@ DEVICE_DATA = {
'drawer_num': 4,
'drawer_type': 'real',
'fan_num_per_drawer': 2,
'support_fan_direction': False,
'support_fan_direction': True,
'hot_swappable': True
},
'psus': {
@ -31,7 +31,7 @@ DEVICE_DATA = {
'drawer_num': 4,
'drawer_type': 'real',
'fan_num_per_drawer': 1,
'support_fan_direction': False,
'support_fan_direction': True,
'hot_swappable': True
},
'psus': {
@ -52,7 +52,7 @@ DEVICE_DATA = {
'drawer_num': 1,
'drawer_type': 'virtual',
'fan_num_per_drawer': 4,
'support_fan_direction': False,
'support_fan_direction': True,
'hot_swappable': False
},
'psus': {
@ -73,7 +73,7 @@ DEVICE_DATA = {
'drawer_num': 4,
'drawer_type': 'real',
'fan_num_per_drawer': 2,
'support_fan_direction': False,
'support_fan_direction': True,
'hot_swappable': True
},
'psus': {
@ -94,7 +94,7 @@ DEVICE_DATA = {
'drawer_num': 1,
'drawer_type': 'virtual',
'fan_num_per_drawer': 4,
'support_fan_direction': False,
'support_fan_direction': True,
'hot_swappable': False
},
'psus': {

View File

@ -22,8 +22,10 @@ PWM_MAX = 255
FAN_PATH = "/var/run/hw-management/thermal/"
CONFIG_PATH = "/var/run/hw-management/config"
# fan_dir isn't supported on Spectrum 1. It is supported on Spectrum 2 and later switches
FAN_DIR = "/var/run/hw-management/system/fan_dir"
FAN_DIR = "/var/run/hw-management/thermal/fan{}_dir"
FAN_DIR_VALUE_EXHAUST = 0
FAN_DIR_VALUE_INTAKE = 1
COOLING_STATE_PATH = "/var/run/hw-management/thermal/cooling_cur_state"
class Fan(FanBase):

View File

@ -14,6 +14,7 @@ try:
from sonic_platform_base.fan_drawer_base import FanDrawerBase
from sonic_platform_base.fan_base import FanBase
from .led import FanLed, SharedLed
from .utils import read_int_from_file
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
@ -51,14 +52,14 @@ class MellanoxFanDrawer(FanDrawerBase):
return FanBase.FAN_DIRECTION_NOT_APPLICABLE
try:
from .fan import FAN_DIR
with open(FAN_DIR, 'r') as fan_dir:
fan_dir_bits = int(fan_dir.read())
fan_mask = 1 << self._index - 1
if fan_dir_bits & fan_mask:
return FanBase.FAN_DIRECTION_INTAKE
else:
return FanBase.FAN_DIRECTION_EXHAUST
from .fan import FAN_DIR, FAN_DIR_VALUE_INTAKE, FAN_DIR_VALUE_EXHAUST
fan_dir = read_int_from_file(FAN_DIR.format(self._index), raise_exception=True)
if fan_dir == FAN_DIR_VALUE_INTAKE:
return FanBase.FAN_DIRECTION_INTAKE
elif fan_dir == FAN_DIR_VALUE_EXHAUST:
return FanBase.FAN_DIRECTION_EXHAUST
else:
raise RuntimeError("Got wrong value {} for fan direction {}".format(fan_dir, self._index))
except (ValueError, IOError) as e:
raise RuntimeError("Failed to read fan direction status to {}".format(repr(e)))