Skip to content

Commit a2724b7

Browse files
committed
gnoi_system_reboot_status_after_startup
1 parent 1a96104 commit a2724b7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/gnmi/test_gnoi_system.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from .helper import gnoi_request
66
from tests.common.helpers.assertions import pytest_assert
7+
from tests.common.reboot import wait_for_startup
78
import re
89

910
pytestmark = [
@@ -84,6 +85,35 @@ def test_gnoi_system_reboot_status_immediately(duthosts, rand_one_dut_hostname,
8485
pytest_assert(msg_json["active"] is True, "System.RebootStatus API did not return active = true")
8586

8687

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+
87117
def extract_first_json_substring(s):
88118
"""
89119
Extract the first JSON substring from a given string.

0 commit comments

Comments
 (0)