Skip to content

Commit

Permalink
Switch back to printing 'repr(e)'
Browse files Browse the repository at this point in the history
  • Loading branch information
jleveque committed Mar 18, 2021
1 parent 8e28094 commit 3441d48
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
16 changes: 8 additions & 8 deletions sonic-thermalctld/scripts/thermalctld
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -565,23 +565,23 @@ 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)
for thermal_index, thermal in enumerate(psu.get_all_thermals()):
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)
for thermal_index, thermal in enumerate(sfp.get_all_thermals()):
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")

Expand Down Expand Up @@ -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):
Expand All @@ -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()

Expand Down Expand Up @@ -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:
Expand Down
35 changes: 28 additions & 7 deletions sonic-thermalctld/tests/test_thermalctld.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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


Expand Down

0 comments on commit 3441d48

Please sign in to comment.