Fix issue: ERR healthd: Get unit status determine-reboot-cause-'LoadState' (#13697) (#13751)

- 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

Co-authored-by: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com>
This commit is contained in:
mssonicbld 2023-02-11 06:38:48 +08:00 committed by GitHub
parent ff232d67bd
commit 8dc3a40685
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -273,7 +273,7 @@ class Sysmonitor(ProcessTaskBase):
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']