Skip to content

Commit

Permalink
[reboot-cause] Porting PR to fix a broken symlink of previous-reboot-…
Browse files Browse the repository at this point in the history
…cause file removal issue (sonic-host-services #46) (sonic-net#14106)

Why I did it
Porting/cherry-pick PR sonic-net/sonic-host-services#46
"show reboot-cause history" shows empty history. When the previous-reboot-cause has a broken symlink, And rebooting the system will not be able to generate a new symlink of the new previous-reboot-cause.

admin@sonic:~$ show reboot-cause history 
Name    Cause    Time    User    Comment
------  -------  ------  ------  ---------
How I did it
Somehow, when the symlink file /host/reboot-cause/previous-reboot-cause is broken (which its destination files doesn't exist in this case), the current condition check "if os.path,exists(PREVIOUS_REBOOT_CAUSE_FILE)" will return False in determine-reboot-cause script. Hence, the current previous-reboot-cause is not been removed and the recreation of the new previous-reboot-cause failed. In case of previous-reboot-cause is a broken synlink file, add condition os.path.islink(PREVIOUS_REBOOT_CAUSE) to check and allow the remove operation happens.

How to verify it
Manually make the /host/reboot-cause/previous-reboot-cause to be a broken symlink file by removing its destination file
reboot the system. "show reboot-cause history" should show the correct info

Signed-off-by: mlok <marty.lok@nokia.com>
  • Loading branch information
mlok-nokia authored Mar 8, 2023
1 parent 75ad7b0 commit 37b31c5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/sonic-host-services/scripts/determine-reboot-cause
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def main():
os.makedirs(REBOOT_CAUSE_DIR)

# Remove stale PREVIOUS_REBOOT_CAUSE_FILE if it exists
if os.path.exists(PREVIOUS_REBOOT_CAUSE_FILE):
if os.path.exists(PREVIOUS_REBOOT_CAUSE_FILE) or os.path.islink(PREVIOUS_REBOOT_CAUSE_FILE):
os.remove(PREVIOUS_REBOOT_CAUSE_FILE)

previous_reboot_cause, additional_reboot_info = determine_reboot_cause()
Expand Down

0 comments on commit 37b31c5

Please sign in to comment.