Skip to content

Commit

Permalink
Fix issue: ERR healthd: Get unit status determine-reboot-cause-'LoadS…
Browse files Browse the repository at this point in the history
…tate' (sonic-net#13697)

- Why I did it
Fix issue: ERR healthd: Get unit status determine-reboot-cause-'LoadState'. The error log is only seen on shutdown flow such as fast-reboot/warm-reboot.

In shutdown flow, 'LoadState' might not be available in systemctl status output, using [] might cause a KeyError.

- How I did it
Use dict.get instead of []

- How to verify it
Manual test
  • Loading branch information
Junchao-Mellanox authored Feb 7, 2023
1 parent e3ff088 commit 5e6e2c8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/system-health/health_checker/sysmonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def get_unit_status(self, event):

sysctl_show = self.run_systemctl_show(event)

load_state = sysctl_show['LoadState']
load_state = sysctl_show.get('LoadState')
if load_state == "loaded":
status = sysctl_show['UnitFileState']
fail_reason = sysctl_show['Result']
Expand Down

0 comments on commit 5e6e2c8

Please sign in to comment.