From f6e5e5902e4b4a40fc18e8d638d580962bd004be Mon Sep 17 00:00:00 2001 From: Petro Bratash <68950226+bratashX@users.noreply.github.com> Date: Fri, 20 Nov 2020 03:57:44 +0200 Subject: [PATCH] Fix test_updater_thermal_check_min_max() (#121) Fixes the following crash introduced by https://github.com/Azure/sonic-platform-daemons/pull/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 Signed-off-by: Petro Bratash --- sonic-thermalctld/tests/mock_platform.py | 5 +++-- sonic-thermalctld/tests/test_thermalctld.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sonic-thermalctld/tests/mock_platform.py b/sonic-thermalctld/tests/mock_platform.py index 8954cddb626a..223d0c64ebae 100644 --- a/sonic-thermalctld/tests/mock_platform.py +++ b/sonic-thermalctld/tests/mock_platform.py @@ -112,9 +112,10 @@ 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 @@ -122,7 +123,7 @@ def __init__(self): self.low_threshold = 1 self.high_critical_threshold = 4 self.low_critical_threshold = 0 - + def get_name(self): return self.name diff --git a/sonic-thermalctld/tests/test_thermalctld.py b/sonic-thermalctld/tests/test_thermalctld.py index d327bf8b9864..d3779fb09796 100644 --- a/sonic-thermalctld/tests/test_thermalctld.py +++ b/sonic-thermalctld/tests/test_thermalctld.py @@ -329,7 +329,7 @@ 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) @@ -337,6 +337,6 @@ def test_updater_thermal_check_min_max(): 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())