-
Notifications
You must be signed in to change notification settings - Fork 999
draft for dhcp server testcase #4485
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7b979ae
draft for dhcp server testcase
wen587 80c551f
1. Add clean_setup and default_setup for testing
wen587 aa90d91
change naming in arp test
wen587 1015fc0
1. make utils general 2. polling instead of sleep 3.mktemp instead fi…
wen587 c08fcd5
rebase and resolve build issue
wen587 5e71d5c
1. resolve comment; 2. add start-limit-hit handle
wen587 e71312b
resolve lgtm issue
wen587 b88ac51
check return code before check output stdout
wen587 029cbb1
fix minor issue
wen587 8181b43
1. check return code; 2. add comment for util function
wen587 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
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
Empty file.
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 |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import json | ||
| import logging | ||
| from tests.common.helpers.assertions import pytest_assert | ||
| from tests.common.utilities import wait_until | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| def generate_tmpfile(duthost): | ||
| return duthost.shell('mktemp')['stdout'] | ||
|
|
||
| def delete_tmpfile(duthost, tmpfile): | ||
| duthost.file(path=tmpfile, state='absent') | ||
|
|
||
| def apply_patch(duthost, json_data, dest_file): | ||
| duthost.copy(content=json.dumps(json_data, indent=4), dest=dest_file) | ||
|
|
||
| cmds = 'config apply-patch {}'.format(dest_file) | ||
|
|
||
| logger.info("Commands: {}".format(cmds)) | ||
| output = duthost.shell(cmds, module_ignore_errors=True) | ||
|
|
||
| return output | ||
|
|
||
| def expect_op_success(duthost, output): | ||
| pytest_assert(not output['rc'], "Command is not running successfully") | ||
| pytest_assert( | ||
| "Patch applied successfully" in output['stdout'], | ||
| "Please check if json file is validate" | ||
| ) | ||
|
|
||
| def expect_op_success_and_reset_check(duthost, output, container_name, threshold, interval, delay): | ||
| '''Add contianer reset check after op success | ||
| ''' | ||
| expect_op_success(duthost, output) | ||
| if start_limit_hit(duthost, container_name): | ||
| reset_start_limit_hit(duthost, container_name, threshold, interval, delay) | ||
|
|
||
| def expect_res_success(duthost, output, expected_content_list, unexpected_content_list): | ||
| for expected_content in expected_content_list: | ||
| pytest_assert( | ||
| expected_content in output['stdout'], | ||
| "{} is expected content".format(expected_content) | ||
| ) | ||
|
|
||
| for unexpected_content in unexpected_content_list: | ||
| pytest_assert( | ||
| unexpected_content not in output['stdout'], | ||
| "{} is unexpected content".format(unexpected_content) | ||
| ) | ||
|
|
||
| def expect_op_failure(output): | ||
| logger.info("return code {}".format(output['rc'])) | ||
| pytest_assert( | ||
| output['rc'], | ||
| "The command should fail with non zero return code" | ||
| ) | ||
|
|
||
| def start_limit_hit(duthost, container_name): | ||
| """If start-limit-hit is hit, the service will not start anyway. | ||
| """ | ||
| service_status = duthost.shell("sudo systemctl status {}.service | grep 'Active'".format(container_name)) | ||
| pytest_assert( | ||
| not service_status['rc'], | ||
| "{} service status cannot be found".format(container_name) | ||
| ) | ||
|
|
||
| for line in service_status["stdout_lines"]: | ||
| if "start-limit-hit" in line: | ||
| return True | ||
|
|
||
| return False | ||
|
|
||
| def reset_start_limit_hit(duthost, container_name, threshold, interval, delay): | ||
| """Reset container if hit start-limit-hit | ||
| """ | ||
| logger.info("Reset container '{}' due to start-limit-hit".format(container_name)) | ||
|
|
||
| service_reset_failed = duthost.shell("sudo systemctl reset-failed {}.service".format(container_name)) | ||
| pytest_assert( | ||
| not service_reset_failed['rc'], | ||
| "{} systemctl reset-failed service fails" | ||
| ) | ||
|
|
||
| service_start = duthost.shell("sudo systemctl start {}.service".format(container_name)) | ||
| pytest_assert( | ||
| not service_start['rc'], | ||
| "{} systemctl start service fails" | ||
| ) | ||
|
|
||
| reset_container = wait_until(threshold, | ||
| interval, | ||
| delay, | ||
| duthost.is_service_fully_started, | ||
| container_name) | ||
| pytest_assert( | ||
| reset_container, | ||
| "Failed to reset container '{}' due to start-limit-hit".format(container_name) | ||
| ) |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
It's not easy to understand the function just from the name. They are implemented to be reused. Could you add some function level comments, explaining the purpose, parameter, and return values. #Closed
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.
Also applicable to other new functions in this file.
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.
Added