From 00178187d003370ef655c315a3fd04c99fb2009e Mon Sep 17 00:00:00 2001 From: Andriy Kokhan Date: Mon, 7 Nov 2022 16:06:52 +0200 Subject: [PATCH] [BFN] Fixed FANs indexing for multi-drawer case (#12491) Why I did it In case the device contains more then one FAN drawer, the FANs name was incorrect. How I did it Passed max fan value to FAN object. Fixed get_name() FAN API How to verify it show platform fan --- .../sonic_platform/fan.py | 10 +++++----- .../sonic_platform/fan_drawer.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/fan.py b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/fan.py index c13382fddb..371bb86371 100644 --- a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/fan.py +++ b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/fan.py @@ -17,15 +17,15 @@ def _fan_info_get(fan_num, cb, default=None): # Fan -> FanBase -> DeviceBase class Fan(FanBase): - def __init__(self, index, fantrayindex): + def __init__(self, index, max_index, fantrayindex): self.__index = index - self.__fantrayindex = fantrayindex + self.__glob_index = (fantrayindex - 1) * max_index + self.__index # FanBase interface methods: # returns speed in percents def get_speed(self): def cb(info): return info.percent - return _fan_info_get(self.__index, cb, 0) + return _fan_info_get(self.__glob_index, cb, 0) def set_speed(self, percent): # Fan tray speed controlled by BMC @@ -33,10 +33,10 @@ class Fan(FanBase): # DeviceBase interface methods: def get_name(self): - return "counter-rotating-fan-{}".format((self.__fantrayindex - 1) * self.__index + self.__index) + return "counter-rotating-fan-{}".format(self.__glob_index) def get_presence(self): - return _fan_info_get(self.__index, lambda _: True, False) + return _fan_info_get(self.__glob_index, lambda _: True, False) def get_position_in_parent(self): return self.__index diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/fan_drawer.py b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/fan_drawer.py index 269d3d43b0..0711d1755d 100644 --- a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/fan_drawer.py +++ b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/fan_drawer.py @@ -10,7 +10,7 @@ class FanDrawer(FanDrawerBase): def __init__(self, fantray_index, max_fan): # For now we return only present fans self.fantrayindex = fantray_index - self._fan_list = [Fan(i, self.fantrayindex) for i in range(1, max_fan + 1)] + self._fan_list = [Fan(i, max_fan, self.fantrayindex) for i in range(1, max_fan + 1)] # DeviceBase interface methods: def get_name(self):