Skip to content

Commit f6e5e59

Browse files
authored
Fix test_updater_thermal_check_min_max() (sonic-net#121)
Fixes the following crash introduced by sonic-net/sonic-platform-daemons#102: ``` 01:33:00 ______________________ test_updater_thermal_check_min_max ______________________ 01:33:00 01:33:00 def test_updater_thermal_check_min_max(): 01:33:00 chassis = MockChassis() 01:33:00 01:33:00 thermal = MockThermal() 01:33:00 chassis.get_all_thermals().append(thermal) 01:33:00 01:33:00 chassis.set_modular_chassis(True) 01:33:00 chassis.set_my_slot(1) 01:33:00 temperature_updater = TemperatureUpdater(SYSLOG_IDENTIFIER, chassis) 01:33:00 01:33:00 temperature_updater.update() 01:33:00 slot_dict = temperature_updater.chassis_table.get('Thermal 1') 01:33:00 > assert slot_dict['minimum_temperature'] == str(thermal.get_minimum_recorded()) 01:33:00 E TypeError: 'NoneType' object has no attribute '__getitem__' 01:33:00 01:33:00 tests/test_thermalctld.py:341: TypeError ``` Signed-off-by: Petro Bratash <petrox.bratash@intel.com> Signed-off-by: Petro Bratash <petrox.bratash@intel.com>
1 parent 14e586d commit f6e5e59

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

sonic-thermalctld/tests/mock_platform.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,18 @@ def set_status_led(self, value):
112112

113113

114114
class MockThermal(MockDevice):
115-
def __init__(self):
115+
def __init__(self, index = None):
116116
MockDevice.__init__(self)
117117
self.name = None
118+
self.name = 'Thermal {}'.format(index) if index != None else None
118119
self.temperature = 2
119120
self.minimum_temperature = 1
120121
self.maximum_temperature = 5
121122
self.high_threshold = 3
122123
self.low_threshold = 1
123124
self.high_critical_threshold = 4
124125
self.low_critical_threshold = 0
125-
126+
126127
def get_name(self):
127128
return self.name
128129

sonic-thermalctld/tests/test_thermalctld.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,14 @@ def test_updater_thermal_check_chassis_table():
329329
def test_updater_thermal_check_min_max():
330330
chassis = MockChassis()
331331

332-
thermal = MockThermal()
332+
thermal = MockThermal(1)
333333
chassis.get_all_thermals().append(thermal)
334334

335335
chassis.set_modular_chassis(True)
336336
chassis.set_my_slot(1)
337337
temperature_updater = TemperatureUpdater(SYSLOG_IDENTIFIER, chassis)
338338

339339
temperature_updater.update()
340-
slot_dict = temperature_updater.chassis_table.get('Thermal 1')
340+
slot_dict = temperature_updater.chassis_table.get(thermal.get_name())
341341
assert slot_dict['minimum_temperature'] == str(thermal.get_minimum_recorded())
342342
assert slot_dict['maximum_temperature'] == str(thermal.get_maximum_recorded())

0 commit comments

Comments
 (0)