From 3441d48dfc161373a6b9c66a63a9addcfcdb05dd Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Thu, 18 Mar 2021 01:52:08 +0000 Subject: [PATCH] Switch back to printing 'repr(e)' --- sonic-thermalctld/scripts/thermalctld | 16 +++++----- sonic-thermalctld/tests/test_thermalctld.py | 35 ++++++++++++++++----- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/sonic-thermalctld/scripts/thermalctld b/sonic-thermalctld/scripts/thermalctld index ea0cbc807..1da7d4328 100644 --- a/sonic-thermalctld/scripts/thermalctld +++ b/sonic-thermalctld/scripts/thermalctld @@ -241,14 +241,14 @@ class FanUpdater(logger.Logger): try: self._refresh_fan_status(drawer, drawer_index, fan, fan_index) except Exception as e: - self.log_warning('Failed to update fan status - {}'.format(e)) + self.log_warning('Failed to update fan status - {}'.format(repr(e))) for psu_index, psu in enumerate(self.chassis.get_all_psus()): for fan_index, fan in enumerate(psu.get_all_fans()): try: self._refresh_fan_status(psu, psu_index, fan, fan_index, True) except Exception as e: - self.log_warning('Failed to update PSU fan status - {}'.format(e)) + self.log_warning('Failed to update PSU fan status - {}'.format(repr(e))) self._update_led_color() @@ -565,7 +565,7 @@ class TemperatureUpdater(logger.Logger): try: self._refresh_temperature_status(CHASSIS_INFO_KEY, thermal, index) except Exception as e: - self.log_warning('Failed to update thermal status - {}'.format(e)) + self.log_warning('Failed to update thermal status - {}'.format(repr(e))) for psu_index, psu in enumerate(self.chassis.get_all_psus()): parent_name = 'PSU {}'.format(psu_index + 1) @@ -573,7 +573,7 @@ class TemperatureUpdater(logger.Logger): try: self._refresh_temperature_status(parent_name, thermal, thermal_index) except Exception as e: - self.log_warning('Failed to update thermal status - {}'.format(e)) + self.log_warning('Failed to update thermal status - {}'.format(repr(e))) for sfp_index, sfp in enumerate(self.chassis.get_all_sfps()): parent_name = 'SFP {}'.format(sfp_index + 1) @@ -581,7 +581,7 @@ class TemperatureUpdater(logger.Logger): try: self._refresh_temperature_status(parent_name, thermal, thermal_index) except Exception as e: - self.log_warning('Failed to update thermal status - {}'.format(e)) + self.log_warning('Failed to update thermal status - {}'.format(repr(e))) self.log_debug("End temperature updating") @@ -759,7 +759,7 @@ class ThermalControlDaemon(daemon_base.DaemonBase): except NotImplementedError: self.log_warning('Thermal manager is not supported on this platform') except Exception as e: - self.log_error('Caught exception while initializing thermal manager - {}'.format(e)) + self.log_error('Caught exception while initializing thermal manager - {}'.format(repr(e))) sys.exit(ERR_INIT_FAILED) def deinit(self): @@ -770,7 +770,7 @@ class ThermalControlDaemon(daemon_base.DaemonBase): if self.thermal_manager: self.thermal_manager.deinitialize() except Exception as e: - self.log_error('Caught exception while destroying thermal manager - {}'.format(e)) + self.log_error('Caught exception while destroying thermal manager - {}'.format(repr(e))) self.thermal_monitor.task_stop() @@ -811,7 +811,7 @@ class ThermalControlDaemon(daemon_base.DaemonBase): if self.thermal_manager: self.thermal_manager.run_policy(chassis) except Exception as e: - self.log_error('Caught exception while running thermal policy - {}'.format(e)) + self.log_error('Caught exception while running thermal policy - {}'.format(repr(e))) elapsed = time.time() - begin if elapsed < self.INTERVAL: diff --git a/sonic-thermalctld/tests/test_thermalctld.py b/sonic-thermalctld/tests/test_thermalctld.py index bdde3e385..11da5976a 100644 --- a/sonic-thermalctld/tests/test_thermalctld.py +++ b/sonic-thermalctld/tests/test_thermalctld.py @@ -180,7 +180,11 @@ def test_update_fan_with_exception(self): assert fan.get_status_led() == MockFan.STATUS_LED_COLOR_RED assert fan_updater.log_warning.call_count == 1 - fan_updater.log_warning.assert_called_with("Failed to update fan status - Failed to get speed") + # TODO: Clean this up once we no longer need to support Python 2 + if sys.version_info.major == 3: + fan_updater.log_warning.assert_called_with("Failed to update fan status - Exception(Failed to get speed)") + else: + fan_updater.log_warning.assert_called_with("Failed to update fan status - Exception(Failed to get speed),") def test_set_fan_led_exception(self): fan_status = thermalctld.FanStatus() @@ -456,7 +460,12 @@ def test_update_psu_thermals(self): temperature_updater._refresh_temperature_status = mock.MagicMock(side_effect=Exception("Test message")) temperature_updater.update() assert temperature_updater.log_warning.call_count == 1 - temperature_updater.log_warning.assert_called_with("Failed to update thermal status - Test message") + + # TODO: Clean this up once we no longer need to support Python 2 + if sys.version_info.major == 3: + temperature_updater.log_warning.assert_called_with("Failed to update thermal status - Exception(Test message)") + else: + temperature_updater.log_warning.assert_called_with("Failed to update thermal status - Exception(Test message)") def test_update_sfp_thermals(self): chassis = MockChassis() @@ -471,7 +480,12 @@ def test_update_sfp_thermals(self): temperature_updater._refresh_temperature_status = mock.MagicMock(side_effect=Exception("Test message")) temperature_updater.update() assert temperature_updater.log_warning.call_count == 1 - temperature_updater.log_warning.assert_called_with("Failed to update thermal status - Test message") + + # TODO: Clean this up once we no longer need to support Python 2 + if sys.version_info.major == 3: + temperature_updater.log_warning.assert_called_with("Failed to update thermal status - Exception(Test message)") + else: + temperature_updater.log_warning.assert_called_with("Failed to update thermal status - Exception(Test message)") def test_update_thermal_with_exception(self): chassis = MockChassis() @@ -484,10 +498,17 @@ def test_update_thermal_with_exception(self): temperature_updater.update() assert temperature_updater.log_warning.call_count == 2 - expected_calls = [ - mock.call("Failed to update thermal status - Failed to get temperature"), - mock.call('High temperature warning: chassis 1 Thermal 2 current temperature 3C, high threshold 2C') - ] + # TODO: Clean this up once we no longer need to support Python 2 + if sys.version_info.major == 3: + expected_calls = [ + mock.call("Failed to update thermal status - Exception(Failed to get temperature)"), + mock.call('High temperature warning: chassis 1 Thermal 2 current temperature 3C, high threshold 2C') + ] + else: + expected_calls = [ + mock.call("Failed to update thermal status - Exception(Failed to get temperature),"), + mock.call('High temperature warning: chassis 1 Thermal 2 current temperature 3C, high threshold 2C') + ] assert temperature_updater.log_warning.mock_calls == expected_calls