-
Notifications
You must be signed in to change notification settings - Fork 1k
Add test case for k8s cleanup container #18404
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
lixiaoyuner
wants to merge
8
commits into
sonic-net:master
from
lixiaoyuner:dev/yunli1/add-cleanup-to-container-upgrade-test
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
25fe15f
Add kubesonic cleanup test case
lixiaoyuner eee5b92
Fix string parameter
lixiaoyuner e7ab923
Fix static check staff
lixiaoyuner ee85050
Seprate the cleanup container test case
lixiaoyuner 70d2a24
Fix comments
lixiaoyuner b53005c
Update
lixiaoyuner fdd996a
Only add containers parameter for cleanup test
lixiaoyuner 44d793c
Check log file path to know the caller
lixiaoyuner 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "testcases": [ | ||
| "kubesonic/test_k8s_cleanup.py" | ||
| ] | ||
| } |
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
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,75 @@ | ||
| import logging | ||
| import pytest | ||
|
|
||
| from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| pytestmark = [ | ||
| pytest.mark.topology('any'), | ||
| pytest.mark.disable_loganalyzer | ||
| ] | ||
|
|
||
| CLEANUP_CONTAINER_NAME = "k8s_cleanup" | ||
|
|
||
|
|
||
| def test_k8s_cleanup(duthosts, rand_one_dut_hostname, request): | ||
| """ | ||
| Test the cleanup of kubesonic containers | ||
| """ | ||
| # Check if the test is called from container upgrade test | ||
| log_file = request.config.getoption("--log-file", default=None) | ||
| logger.info(f"Kubesonic cleanup test log_file: {log_file}") | ||
| if not (log_file and "container_upgrade" in log_file): | ||
| pytest.skip("Skipping test as this test is not called from container upgrade test") | ||
|
|
||
| duthost = duthosts[rand_one_dut_hostname] | ||
| status_cmd = r"docker inspect {} --format \{{\{{.State.Running\}}\}}".format(CLEANUP_CONTAINER_NAME) | ||
| cleanup_container_status = duthost.shell(status_cmd, module_ignore_errors=True) | ||
|
|
||
| if "No such object" in cleanup_container_status["stderr"]: | ||
| pytest.fail("Skipping test as the kubesonic cleanup container is not present") | ||
| elif cleanup_container_status["stdout"] != "true": | ||
| pytest.fail("Kubesonic cleanup container is not running") | ||
| else: | ||
| logger.info("Kubesonic cleanup container is running") | ||
|
|
||
| # Check if the watchdog script exited code is 0 or not | ||
| exec_watchdog_cmd = f"docker exec {CLEANUP_CONTAINER_NAME} /watchdog.sh" | ||
| exec_watchdog_status = duthost.shell(exec_watchdog_cmd, module_ignore_errors=True) | ||
| if exec_watchdog_status["rc"] != 0: | ||
| pytest.fail("Kubesonic watchdog script exited with non-zero code: {}".format( | ||
| exec_watchdog_status["rc"])) | ||
| else: | ||
| logger.info("Kubesonic watchdog script executed successfully") | ||
|
|
||
| # Check if the syslog contains the expected message | ||
| loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix="kubesonic_cleanup_test") | ||
| loganalyzer.expect_regex = [r".*kubesonic-image-cleanup: root-overlay size status\(total available\): (\d+) (\d+)"] | ||
| loganalyzer.match_regex = [r"(?i).*kubesonic-image-cleanup:.*fail.*"] | ||
| marker = loganalyzer.init() | ||
| try: | ||
| exec_cleanup_script_cmd = f"docker exec {CLEANUP_CONTAINER_NAME} /image_cleanup.sh" | ||
| exec_cleanup_script_status = duthost.shell(exec_cleanup_script_cmd, module_ignore_errors=True) | ||
| if exec_cleanup_script_status["rc"] != 0: | ||
| pytest.fail("Kubesonic cleanup script exited with non-zero code: {}".format( | ||
| exec_cleanup_script_status["rc"])) | ||
| else: | ||
| logger.info("Kubesonic cleanup script executed successfully") | ||
|
|
||
| exec_report_disk_size_cmd = f"docker exec {CLEANUP_CONTAINER_NAME} /report_disk_size.sh" | ||
| exec_report_disk_size_status = duthost.shell(exec_report_disk_size_cmd, module_ignore_errors=True) | ||
| if exec_report_disk_size_status["rc"] != 0: | ||
| pytest.fail("Kubesonic report disk size script exited with non-zero code: {}".format( | ||
| exec_report_disk_size_status["rc"])) | ||
| else: | ||
| logger.info("Kubesonic report disk size script executed successfully") | ||
|
|
||
| loganalyzer_summary = loganalyzer.analyze(marker, fail=False) | ||
| if loganalyzer_summary["total"]["match"] != 0: | ||
| pytest.fail("Kubesonic cleanup container error log is found") | ||
| if loganalyzer_summary["total"]["expected_match"] == 0: | ||
| pytest.fail("Kubesonic cleanup container disk size log is not found") | ||
|
|
||
| except Exception as e: | ||
| pytest.fail(f"Failed to check syslog for kubesonic cleanup test: {e}") |
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.
Where is the container defined?