1111 pytest .mark .topology ('any' )
1212]
1313
14+ MAX_TIME_TO_REBOOT = 300
1415
1516"""
1617This module contains tests for the gNOI System API.
@@ -42,45 +43,58 @@ def test_gnoi_system_reboot(duthosts, rand_one_dut_hostname, localhost):
4243 """
4344 duthost = duthosts [rand_one_dut_hostname ]
4445
46+ # Set flag to indicate that this test involves reboot
47+ duthost .host .options ['skip_gnmi_check' ] = True
48+
4549 # Trigger reboot
46- ret , msg = gnoi_request (duthost , localhost , "Reboot" , '{"method": 1}' )
50+ ret , msg = gnoi_request (duthost , localhost , "Reboot" , '{"method": 1,"delay":0,"message":"Cold Reboot" }' )
4751 pytest_assert (ret == 0 , "System.Reboot API reported failure (rc = {}) with message: {}" .format (ret , msg ))
4852 logging .info ("System.Reboot API returned msg: {}" .format (msg ))
4953
50-
54+ @ pytest . mark . disable_loganalyzer
5155def test_gnoi_system_reboot_fail_invalid_method (duthosts , rand_one_dut_hostname , localhost ):
5256 """
5357 Verify the gNOI System Reboot API fails with invalid method.
5458 """
5559 duthost = duthosts [rand_one_dut_hostname ]
5660
61+ # Set flag to indicate that this test involves reboot
62+ duthost .host .options ['skip_gnmi_check' ] = True
63+
5764 # Trigger reboot with invalid method
5865 ret , msg = gnoi_request (duthost , localhost , "Reboot" , '{"method": 99}' )
5966 pytest_assert (ret != 0 , "System.Reboot API did not report failure with invalid method" )
6067
61-
68+ @ pytest . mark . disable_loganalyzer
6269def test_gnoi_system_reboot_when_reboot_active (duthosts , rand_one_dut_hostname , localhost ):
6370 """
6471 Verify the gNOI System Reboot API fails if a reboot is already active.
6572 """
6673 duthost = duthosts [rand_one_dut_hostname ]
6774
75+ # Set flag to indicate that this test involves reboot
76+ duthost .host .options ['skip_gnmi_check' ] = True
77+
6878 # Trigger first reboot
69- ret , msg = gnoi_request (duthost , localhost , "Reboot" , '{"method": 1}' )
79+ ret , msg = gnoi_request (duthost , localhost , "Reboot" , '{"method": 1,"delay":0,"message":"Cold Reboot" }' )
7080 pytest_assert (ret == 0 , "System.Reboot API reported failure (rc = {}) with message: {}" .format (ret , msg ))
7181 logging .info ("System.Reboot API returned msg: {}" .format (msg ))
7282
7383 # Trigger second reboot while the first one is still active
74- ret , msg = gnoi_request (duthost , localhost , "Reboot" , '{"method": 1}' )
84+ ret , msg = gnoi_request (duthost , localhost , "Reboot" , '{"method": 1,"delay":0,"message":"Cold Reboot" }' )
7585 pytest_assert (ret != 0 , "System.Reboot API did not report failure when reboot is already active" )
7686
7787
88+ @pytest .mark .disable_loganalyzer
7889def test_gnoi_system_reboot_status_immediately (duthosts , rand_one_dut_hostname , localhost ):
7990 """
8091 Verify the gNOI System RebootStatus API returns the correct status immediately after reboot.
8192 """
8293 duthost = duthosts [rand_one_dut_hostname ]
8394
95+ # Set flag to indicate that this test involves reboot
96+ duthost .host .options ['skip_gnmi_check' ] = True
97+
8498 # Trigger reboot
8599 ret , msg = gnoi_request (duthost , localhost , "Reboot" , '{"method": 1, "message": "test"}' )
86100 pytest_assert (ret == 0 , "System.Reboot API reported failure (rc = {}) with message: {}" .format (ret , msg ))
@@ -107,6 +121,9 @@ def gnoi_system_reboot_status_after_startup(duthosts, rand_one_dut_hostname, loc
107121 """
108122 duthost = duthosts [rand_one_dut_hostname ]
109123
124+ # Set flag to indicate that this test involves reboot
125+ duthost .host .options ['skip_gnmi_check' ] = True
126+
110127 # Trigger reboot
111128 ret , msg = gnoi_request (duthost , localhost , "Reboot" , '{"method": 1, "message": "test"}' )
112129 pytest_assert (ret == 0 , "System.Reboot API reported failure (rc = {}) with message: {}" .format (ret , msg ))
@@ -138,12 +155,18 @@ def extract_first_json_substring(s):
138155 :return: The first JSON substring if found, otherwise None.
139156 """
140157
141- json_pattern = re .compile (r'\{.*?\}' )
142- match = json_pattern .search (s )
143- if match :
144- try :
145- return json .loads (match .group ())
146- except json .JSONDecodeError :
147- logging .error ("Failed to parse JSON: {}" .format (match .group ()))
148- return None
149- return None
158+ start_index = s .find ('{' ) # Find the first '{' in the string
159+ if start_index == - 1 :
160+ logging .error ("No JSON found in response: {}" .format (s ))
161+ return None
162+ json_str = s [start_index :] # Extract substring starting from '{'
163+ try :
164+ parsed_json = json .loads (json_str ) # Attempt to parse the JSON
165+ # Handle cases where "status": {} is empty
166+ if "status" in parsed_json and parsed_json ["status" ] == {}:
167+ logging .warning ("Replacing empty 'status' field with a default value." )
168+ parsed_json ["status" ] = {"unknown" : "empty_status" }
169+ return parsed_json
170+ except json .JSONDecodeError as e :
171+ logging .error ("Failed to parse JSON: {} | Error: {}" .format (json_str , e ))
172+ return None
0 commit comments