Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mellanox] clear fan from chassis._fan_list #78

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def initialize_fan(self):
fan = Fan(fan_index, drawer, index + 1)
fan_index += 1
drawer._fan_list.append(fan)
self._fan_list.append(fan)


def initialize_single_sfp(self, index):
Expand Down
41 changes: 21 additions & 20 deletions platform/mellanox/mlnx-platform-api/sonic_platform/thermal_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,27 @@ def collect(self, chassis):
:return:
"""
self._status_changed = False
for fan in chassis.get_all_fans():
presence = fan.get_presence()
status = fan.get_status()
if presence and fan not in self._presence_fans:
self._presence_fans.add(fan)
self._status_changed = True
if fan in self._absence_fans:
self._absence_fans.remove(fan)
elif not presence and fan not in self._absence_fans:
self._absence_fans.add(fan)
self._status_changed = True
if fan in self._presence_fans:
self._presence_fans.remove(fan)

if not status and fan not in self._fault_fans:
self._fault_fans.add(fan)
self._status_changed = True
elif status and fan in self._fault_fans:
self._fault_fans.remove(fan)
self._status_changed = True
for fan_drawer in chassis.get_all_fan_drawers():
for fan in fan_drawer.get_all_fans():
presence = fan.get_presence()
status = fan.get_status()
if presence and fan not in self._presence_fans:
self._presence_fans.add(fan)
self._status_changed = True
if fan in self._absence_fans:
self._absence_fans.remove(fan)
elif not presence and fan not in self._absence_fans:
self._absence_fans.add(fan)
self._status_changed = True
if fan in self._presence_fans:
self._presence_fans.remove(fan)

if not status and fan not in self._fault_fans:
self._fault_fans.add(fan)
self._status_changed = True
elif status and fan in self._fault_fans:
self._fault_fans.remove(fan)
self._status_changed = True


def get_absence_fans(self):
Expand Down
16 changes: 15 additions & 1 deletion platform/mellanox/mlnx-platform-api/tests/mock_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,39 @@ def get_all_fans(self):
return []


class MockFanDrawer:
def __init__(self):
self.fan_list = []

def get_all_fans(self):
return self.fan_list


class MockChassis:
def __init__(self):
self.fan_list = []
self.psu_list = []
self.fan_drawer_list = []

def get_all_psus(self):
return self.psu_list

def get_all_fans(self):
return self.fan_list

def get_all_fan_drawers(self):
return self.fan_drawer_list

def get_thermal_manager(self):
from sonic_platform.thermal_manager import ThermalManager
return ThermalManager

def make_fan_absence(self):
fan = MockFan()
fan.presence = False
self.fan_list.append(fan)
fan_drawer = MockFanDrawer()
self.fan_drawer_list.append(fan_drawer)
fan_drawer.fan_list.append(fan)

def make_psu_absence(self):
psu = MockPsu()
Expand Down
29 changes: 16 additions & 13 deletions platform/mellanox/mlnx-platform-api/tests/test_thermal_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
import json
from mock import MagicMock
from .mock_platform import MockChassis, MockFan, MockPsu
from .mock_platform import MockChassis, MockFan, MockFanDrawer, MockPsu

test_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(test_path)
Expand Down Expand Up @@ -49,15 +49,14 @@ def test_fan_info():
assert len(fan_info.get_fault_fans()) == 0
assert fan_info.is_status_changed()

fan_list = chassis.get_all_fans()
fan_list[0].presence = True
chassis.get_all_fan_drawers()[0].get_all_fans()[0].presence = True
fan_info.collect(chassis)
assert len(fan_info.get_absence_fans()) == 0
assert len(fan_info.get_presence_fans()) == 1
assert len(fan_info.get_fault_fans()) == 0
assert fan_info.is_status_changed()

fan_list[0].status = False
chassis.get_all_fan_drawers()[0].get_all_fans()[0].status = False
fan_info.collect(chassis)
assert len(fan_info.get_absence_fans()) == 0
assert len(fan_info.get_presence_fans()) == 1
Expand Down Expand Up @@ -90,10 +89,10 @@ def test_psu_info():
def test_fan_policy(thermal_manager):
chassis = MockChassis()
chassis.make_fan_absence()
chassis.fan_list.append(MockFan())
chassis.get_all_fan_drawers()[0].get_all_fans().append(MockFan())
thermal_manager.run_policy(chassis)

fan_list = chassis.get_all_fans()
fan_list = chassis.get_all_fan_drawers()[0].get_all_fans()
assert fan_list[1].speed == 100
Thermal.set_thermal_algorithm_status.assert_called_with(False, False)

Expand Down Expand Up @@ -144,7 +143,7 @@ def test_any_fan_absence_condition():
condition = AnyFanAbsenceCondition()
assert condition.is_match({'fan_info': fan_info})

fan = chassis.get_all_fans()[0]
fan = chassis.get_all_fan_drawers()[0].get_all_fans()[0]
fan.presence = True
fan_info.collect(chassis)
assert not condition.is_match({'fan_info': fan_info})
Expand All @@ -154,7 +153,7 @@ def test_all_fan_absence_condition():
chassis = MockChassis()
chassis.make_fan_absence()
fan = MockFan()
fan_list = chassis.get_all_fans()
fan_list = chassis.get_all_fan_drawers()[0].get_all_fans()
fan_list.append(fan)
fan_info = FanInfo()
fan_info.collect(chassis)
Expand All @@ -172,7 +171,7 @@ def test_all_fan_presence_condition():
chassis = MockChassis()
chassis.make_fan_absence()
fan = MockFan()
fan_list = chassis.get_all_fans()
fan_list = chassis.get_all_fan_drawers()[0].get_all_fans()
fan_list.append(fan)
fan_info = FanInfo()
fan_info.collect(chassis)
Expand All @@ -187,8 +186,9 @@ def test_all_fan_presence_condition():

def test_any_fan_fault_condition():
chassis = MockChassis()
chassis.get_all_fan_drawers().append(MockFanDrawer())
fan = MockFan()
fan_list = chassis.get_all_fans()
fan_list = chassis.get_all_fan_drawers()[0].get_all_fans()
fan_list.append(fan)
fault_fan = MockFan()
fault_fan.status = False
Expand All @@ -206,8 +206,9 @@ def test_any_fan_fault_condition():

def test_all_fan_good_condition():
chassis = MockChassis()
chassis.get_all_fan_drawers().append(MockFanDrawer())
fan = MockFan()
fan_list = chassis.get_all_fans()
fan_list = chassis.get_all_fan_drawers()[0].get_all_fans()
fan_list.append(fan)
fault_fan = MockFan()
fault_fan.status = False
Expand Down Expand Up @@ -302,7 +303,8 @@ def test_load_set_fan_speed_action():

def test_execute_set_fan_speed_action():
chassis = MockChassis()
fan_list = chassis.get_all_fans()
chassis.get_all_fan_drawers().append(MockFanDrawer())
fan_list = chassis.get_all_fan_drawers()[0].get_all_fans()
fan_list.append(MockFan())
fan_list.append(MockFan())
fan_info = FanInfo()
Expand Down Expand Up @@ -364,7 +366,8 @@ def test_load_check_and_set_speed_action():

def test_execute_check_and_set_fan_speed_action():
chassis = MockChassis()
fan_list = chassis.get_all_fans()
chassis.get_all_fan_drawers().append(MockFanDrawer())
fan_list = chassis.get_all_fan_drawers()[0].get_all_fans()
fan_list.append(MockFan())
fan_list.append(MockFan())
fan_info = FanInfo()
Expand Down