|
4 | 4 |
|
5 | 5 | from .helper import gnoi_request |
6 | 6 | from tests.common.helpers.assertions import pytest_assert |
| 7 | +from tests.common.reboot import wait_for_startup |
7 | 8 | import re |
8 | 9 |
|
9 | 10 | pytestmark = [ |
@@ -84,6 +85,35 @@ def test_gnoi_system_reboot_status_immediately(duthosts, rand_one_dut_hostname, |
84 | 85 | pytest_assert(msg_json["active"] is True, "System.RebootStatus API did not return active = true") |
85 | 86 |
|
86 | 87 |
|
| 88 | +def gnoi_system_reboot_status_after_startup(duthosts, rand_one_dut_hostname, localhost): |
| 89 | + """ |
| 90 | + Verify the gNOI System RebootStatus API returns the correct status after the device has started up. |
| 91 | + """ |
| 92 | + duthost = duthosts[rand_one_dut_hostname] |
| 93 | + |
| 94 | + # Trigger reboot |
| 95 | + ret, msg = gnoi_request(duthost, localhost, "Reboot", '{"method": 1, "message": "test"}') |
| 96 | + pytest_assert(ret == 0, "System.Reboot API reported failure (rc = {}) with message: {}".format(ret, msg)) |
| 97 | + logging.info("System.Reboot API returned msg: {}".format(msg)) |
| 98 | + |
| 99 | + # Wait for device to come back online |
| 100 | + wait_for_startup(duthost) |
| 101 | + |
| 102 | + # Get reboot status |
| 103 | + ret, msg = gnoi_request(duthost, localhost, "RebootStatus", "") |
| 104 | + pytest_assert(ret == 0, "System.RebootStatus API reported failure (rc = {}) with message: {}".format(ret, msg)) |
| 105 | + logging.info("System.RebootStatus API returned msg: {}".format(msg)) |
| 106 | + # Message should contain a json substring like this |
| 107 | + # {"active":false,"wait":0,"when":0,"reason":"test","count":1,"method":1,"status":1} |
| 108 | + # Extract JSON part from the message |
| 109 | + msg_json = extract_first_json_substring(msg) |
| 110 | + if not msg_json: |
| 111 | + pytest.fail("Failed to extract JSON from System.RebootStatus API response") |
| 112 | + logging.info("Extracted JSON: {}".format(msg_json)) |
| 113 | + pytest_assert("active" in msg_json, "System.RebootStatus API did not return active") |
| 114 | + pytest_assert(msg_json["active"] is False, "System.RebootStatus API did not return active = false") |
| 115 | + |
| 116 | + |
87 | 117 | def extract_first_json_substring(s): |
88 | 118 | """ |
89 | 119 | Extract the first JSON substring from a given string. |
|
0 commit comments