Skip to content

Commit

Permalink
Fix test_updater_thermal_check_min_max() (sonic-net#121)
Browse files Browse the repository at this point in the history
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 <[email protected]>

Signed-off-by: Petro Bratash <[email protected]>
  • Loading branch information
bratashX authored Nov 20, 2020
1 parent 14e586d commit f6e5e59
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions sonic-thermalctld/tests/mock_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,18 @@ def set_status_led(self, value):


class MockThermal(MockDevice):
def __init__(self):
def __init__(self, index = None):
MockDevice.__init__(self)
self.name = None
self.name = 'Thermal {}'.format(index) if index != None else None
self.temperature = 2
self.minimum_temperature = 1
self.maximum_temperature = 5
self.high_threshold = 3
self.low_threshold = 1
self.high_critical_threshold = 4
self.low_critical_threshold = 0

def get_name(self):
return self.name

Expand Down
4 changes: 2 additions & 2 deletions sonic-thermalctld/tests/test_thermalctld.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,14 @@ def test_updater_thermal_check_chassis_table():
def test_updater_thermal_check_min_max():
chassis = MockChassis()

thermal = MockThermal()
thermal = MockThermal(1)
chassis.get_all_thermals().append(thermal)

chassis.set_modular_chassis(True)
chassis.set_my_slot(1)
temperature_updater = TemperatureUpdater(SYSLOG_IDENTIFIER, chassis)

temperature_updater.update()
slot_dict = temperature_updater.chassis_table.get('Thermal 1')
slot_dict = temperature_updater.chassis_table.get(thermal.get_name())
assert slot_dict['minimum_temperature'] == str(thermal.get_minimum_recorded())
assert slot_dict['maximum_temperature'] == str(thermal.get_maximum_recorded())

0 comments on commit f6e5e59

Please sign in to comment.