@@ -47,6 +47,43 @@ def test_gnoi_system_reboot(duthosts, rand_one_dut_hostname, localhost):
4747 logging .info ("System.Reboot API returned msg: {}" .format (msg ))
4848
4949
50+ def test_gnoi_system_reboot_fail_invalid_method (duthosts , rand_one_dut_hostname , localhost ):
51+ """
52+ Verify the gNOI System Reboot API fails with invalid method.
53+ """
54+ duthost = duthosts [rand_one_dut_hostname ]
55+
56+ # Trigger reboot with invalid method
57+ ret , msg = gnoi_request (duthost , localhost , "Reboot" , '{"method": 2}' )
58+ pytest_assert (ret != 0 , "System.Reboot API did not report failure with invalid method" )
59+
60+
61+ def test_gnoi_system_reboot_status_immediately (duthosts , rand_one_dut_hostname , localhost ):
62+ """
63+ Verify the gNOI System RebootStatus API returns the correct status immediately after reboot.
64+ """
65+ duthost = duthosts [rand_one_dut_hostname ]
66+
67+ # Trigger reboot
68+ ret , msg = gnoi_request (duthost , localhost , "Reboot" , '{"method": 1, "message": "test"}' )
69+ pytest_assert (ret == 0 , "System.Reboot API reported failure (rc = {}) with message: {}" .format (ret , msg ))
70+ logging .info ("System.Reboot API returned msg: {}" .format (msg ))
71+
72+ # Get reboot status
73+ ret , msg = gnoi_request (duthost , localhost , "RebootStatus" , "" )
74+ pytest_assert (ret == 0 , "System.RebootStatus API reported failure (rc = {}) with message: {}" .format (ret , msg ))
75+ logging .info ("System.RebootStatus API returned msg: {}" .format (msg ))
76+ # Message should contain a json substring like this
77+ # {"active":true,"wait":0,"when":0,"reason":"test","count":1,"method":1,"status":1}
78+ # Extract JSON part from the message
79+ msg_json = extract_first_json_substring (msg )
80+ if not msg_json :
81+ pytest .fail ("Failed to extract JSON from System.RebootStatus API response" )
82+ logging .info ("Extracted JSON: {}" .format (msg_json ))
83+ pytest_assert ("active" in msg_json , "System.RebootStatus API did not return active" )
84+ pytest_assert (msg_json ["active" ] is True , "System.RebootStatus API did not return active = true" )
85+
86+
5087def extract_first_json_substring (s ):
5188 """
5289 Extract the first JSON substring from a given string.
0 commit comments