-
Notifications
You must be signed in to change notification settings - Fork 902
Add testcases for Reboot #16576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Add testcases for Reboot #16576
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8ad8006
initial commit.
hdwhdw 8399c65
add a testcase that immediately request status after reboot.
hdwhdw 1a96104
update invalid method.
hdwhdw a2724b7
gnoi_system_reboot_status_after_startup
hdwhdw 9fcacf4
test_gnoi_system_reboot_when_reboot_active
hdwhdw f452482
Skip GNMI check during teardown and disable LogAnalyzer for reboot tests
84075f7
Skip GNMI check during teardown and disable LogAnalyzer for reboot tests
hdwhdw 70e6b02
Merge branch 'sonic-net:master' into reboot
hdwhdw ea4c6e7
address comments and format fix.
hdwhdw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,55 @@ def test_gnoi_system_time(duthosts, rand_one_dut_hostname, localhost): | |
| pytest_assert("time" in msg_json, "System.Time API did not return time") | ||
|
|
||
|
|
||
| def test_gnoi_system_reboot(duthosts, rand_one_dut_hostname, localhost): | ||
| """ | ||
| Verify the gNOI System Reboot API triggers a reboot and the device comes back online. | ||
| """ | ||
| duthost = duthosts[rand_one_dut_hostname] | ||
|
|
||
| # Trigger reboot | ||
| ret, msg = gnoi_request(duthost, localhost, "Reboot", '{"method": 1}') | ||
| pytest_assert(ret == 0, "System.Reboot API reported failure (rc = {}) with message: {}".format(ret, msg)) | ||
| logging.info("System.Reboot API returned msg: {}".format(msg)) | ||
|
|
||
|
|
||
| def test_gnoi_system_reboot_fail_invalid_method(duthosts, rand_one_dut_hostname, localhost): | ||
| """ | ||
| Verify the gNOI System Reboot API fails with invalid method. | ||
| """ | ||
| duthost = duthosts[rand_one_dut_hostname] | ||
|
|
||
| # Trigger reboot with invalid method | ||
| ret, msg = gnoi_request(duthost, localhost, "Reboot", '{"method": 2}') | ||
|
||
| pytest_assert(ret != 0, "System.Reboot API did not report failure with invalid method") | ||
|
|
||
|
|
||
| def test_gnoi_system_reboot_status_immediately(duthosts, rand_one_dut_hostname, localhost): | ||
| """ | ||
| Verify the gNOI System RebootStatus API returns the correct status immediately after reboot. | ||
| """ | ||
| duthost = duthosts[rand_one_dut_hostname] | ||
|
|
||
| # Trigger reboot | ||
| ret, msg = gnoi_request(duthost, localhost, "Reboot", '{"method": 1, "message": "test"}') | ||
| pytest_assert(ret == 0, "System.Reboot API reported failure (rc = {}) with message: {}".format(ret, msg)) | ||
| logging.info("System.Reboot API returned msg: {}".format(msg)) | ||
|
|
||
| # Get reboot status | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ret, msg = gnoi_request(duthost, localhost, "RebootStatus", "") | ||
| pytest_assert(ret == 0, "System.RebootStatus API reported failure (rc = {}) with message: {}".format(ret, msg)) | ||
| logging.info("System.RebootStatus API returned msg: {}".format(msg)) | ||
| # Message should contain a json substring like this | ||
| # {"active":true,"wait":0,"when":0,"reason":"test","count":1,"method":1,"status":1} | ||
| # Extract JSON part from the message | ||
| msg_json = extract_first_json_substring(msg) | ||
| if not msg_json: | ||
| pytest.fail("Failed to extract JSON from System.RebootStatus API response") | ||
| logging.info("Extracted JSON: {}".format(msg_json)) | ||
| pytest_assert("active" in msg_json, "System.RebootStatus API did not return active") | ||
| pytest_assert(msg_json["active"] is True, "System.RebootStatus API did not return active = true") | ||
|
|
||
|
|
||
| def extract_first_json_substring(s): | ||
| """ | ||
| Extract the first JSON substring from a given string. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hdwhdw Since, all the tests are doing cold reboot, could you rename the tests accordingly to include the cold name? I plan to add similar tests for halt method testing as well.