Skip to content

Commit b30b97a

Browse files
Fix an error of checking reboot type (sonic-net#14155)
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?
1 parent bc389e4 commit b30b97a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tests/common/reboot.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,9 @@ def get_reboot_cause(dut):
344344
# is such like "User issued 'xxx' command [User: admin, Time: Sun Aug 4 06:43:19 PM UTC 2024]"
345345
# So, use the above pattern to get real reboot cause
346346
if dut.facts["asic_type"] == "vs":
347-
cause = re.search("User issued '(.*)' command", cause).groups()[0]
347+
match = re.search("User issued '(.*)' command", cause)
348+
if match:
349+
cause = match.groups()[0]
348350

349351
for type, ctrl in list(reboot_ctrl_dict.items()):
350352
if re.search(ctrl['cause'], cause):

0 commit comments

Comments
 (0)