Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an error of checking reboot type. #14155

Merged

Conversation

yutongzhang-microsoft
Copy link
Contributor

Description of PR

There is another reboot cause Unknown (First boot of SONiC version xxx) on kvm besides User issued xxx' command, which will cause error 'NoneType' object has no attribute 'groups' based on the current code. To address this, this PR suggests a conditional check to ensure that the match object is not None before attempting to access its 'groups' attribute, thereby preventing such issue.

Summary:
Fixes # (13979
)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • Test case(new/improvement)

Back port request

  • 202012
  • 202205
  • 202305
  • 202311
  • 202405

Approach

What is the motivation for this PR?

There is another reboot cause Unknown (First boot of SONiC version xxx) on kvm besides User issued xxx' command, which will cause error 'NoneType' object has no attribute 'groups' based on the current code. To address this, this PR suggests a conditional check to ensure that the match object is not None before attempting to access its 'groups' attribute, thereby preventing such issue.

How did you do it?

This PR suggests a conditional check to ensure that the match object is not None before attempting to access its 'groups' attribute, thereby preventing such issue.

How did you verify/test it?

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

@@ -344,7 +344,9 @@ def get_reboot_cause(dut):
# is such like "User issued 'xxx' command [User: admin, Time: Sun Aug 4 06:43:19 PM UTC 2024]"
# So, use the above pattern to get real reboot cause
if dut.facts["asic_type"] == "vs":
cause = re.search("User issued '(.*)' command", cause).groups()[0]
match = re.search("User issued '(.*)' command", cause)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yutongzhang-microsoft since KVM prints something like this for "show reboot-cause" on the first boot -

Unknown (First boot of SONiC version master.597250-dc3c0451b)

The above regex User issued ... won't match the above string. Won't you need one more regex Unknown (\(.*\)) to match the above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because, the pattern User issued '(.*)' command will get the real reboot reason in the position of (.*), such as warm-reboot, fast-reboot. But if we get the string Unknown (First boot of SONiC version master.597250-dc3c0451b), we can't match the cause of dict reboot_ctrl_dict in this file. So I think just return REBOOT_TYPE_UNKNOWN makes sence.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you I see what you mean. LGTM

Copy link
Contributor

@opcoder0 opcoder0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wangxin wangxin merged commit 48d0274 into sonic-net:master Aug 19, 2024
16 checks passed
@yutongzhang-microsoft yutongzhang-microsoft deleted the yutongzhang/fix_reboot_error branch August 19, 2024 08:40
arista-hpandya pushed a commit to arista-hpandya/sonic-mgmt that referenced this pull request Oct 2, 2024
What is the motivation for this PR?
There is another reboot cause Unknown (First boot of SONiC version xxx) on kvm besides User issued xxx' command, which will cause error 'NoneType' object has no attribute 'groups' based on the current code. To address this, this PR suggests a conditional check to ensure that the match object is not None before attempting to access its 'groups' attribute, thereby preventing such issue.

How did you do it?
This PR suggests a conditional check to ensure that the match object is not None before attempting to access its 'groups' attribute, thereby preventing such issue.

How did you verify/test it?
vikshaw-Nokia pushed a commit to vikshaw-Nokia/sonic-mgmt that referenced this pull request Oct 23, 2024
What is the motivation for this PR?
There is another reboot cause Unknown (First boot of SONiC version xxx) on kvm besides User issued xxx' command, which will cause error 'NoneType' object has no attribute 'groups' based on the current code. To address this, this PR suggests a conditional check to ensure that the match object is not None before attempting to access its 'groups' attribute, thereby preventing such issue.

How did you do it?
This PR suggests a conditional check to ensure that the match object is not None before attempting to access its 'groups' attribute, thereby preventing such issue.

How did you verify/test it?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants