Fix issue: ERR healthd: Get unit status determine-reboot-cause-'LoadState' (#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
This commit is contained in:
Junchao-Mellanox 2023-02-07 23:56:06 +08:00 committed by GitHub
parent e3ff08833e
commit 5e6e2c827d
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) sysctl_show = self.run_systemctl_show(event)
load_state = sysctl_show['LoadState'] load_state = sysctl_show.get('LoadState')
if load_state == "loaded": if load_state == "loaded":
status = sysctl_show['UnitFileState'] status = sysctl_show['UnitFileState']
fail_reason = sysctl_show['Result'] fail_reason = sysctl_show['Result']