-
Notifications
You must be signed in to change notification settings - Fork 0
feat: modify fault parameters manually #375
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
13 commits
Select commit
Hold shift + click to select a range
d40e421
feat: modify fault parameters manually
nhitar 4dd6f1e
Merge branch 'main' into reduce-fault-injection-overhead
nhitar ce7e6ec
refactor: remove leftover logger.info
nhitar 45c5a85
refactor: move kirk function to class
nhitar 37a1447
refactor: move debugfs functions to separate file
nhitar 642c0c4
fix: remove self from the function
nhitar 5dba9de
chore: add comments and fix debugfs path
nhitar 07336a3
refactor: add cleanup mixin and error processing in runner
nhitar a078961
Merge branch 'main' into reduce-fault-injection-overhead
nhitar db3ae94
fix: mixin dependencies
nhitar a8d3676
refactor: fix type issues and moves FaultCleanupMixin to fault_inject…
Artanias 3ad5744
refactor: changes constant usage in the debugfs module.
Artanias 6c149aa
refactor: use library function for calculating subtests timeouts.
Artanias 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,94 @@ | ||
| import logging | ||
| from pathlib import Path | ||
| from typing import TYPE_CHECKING, Final | ||
|
|
||
| from imgtests.exec.exec import ExecResult, SSHClient, common_run_command | ||
|
|
||
| if TYPE_CHECKING: | ||
| from imgtests.exec.exec import ExecResult, SSHClient | ||
|
|
||
| DEBUGFS_PATH: Final = Path("/sys/kernel/debug") | ||
| MAX_FAULT_PROBABILITY: Final = 100 | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def ensure_debugfs(ssh_client: SSHClient | None) -> ExecResult: | ||
| """Ensures that debugfs is created and mounted.""" | ||
| result = common_run_command(("sudo", "mkdir", "-p", str(DEBUGFS_PATH)), ssh_client) | ||
| if result.returncode: | ||
| return result | ||
| mount_pattern = f"[[:space:]]{DEBUGFS_PATH}[[:space:]]debugfs[[:space:]]" | ||
| result = common_run_command( | ||
| ("sudo", "grep", "-qs", mount_pattern, "/proc/mounts"), | ||
| ssh_client, | ||
| ) | ||
| if result.returncode == 0 or result.returncode != 1: | ||
| return result | ||
| logger.info("Mounting debugfs to '%s'.", str(DEBUGFS_PATH)) | ||
| result = common_run_command( | ||
| ("sudo", "mount", "-t", "debugfs", "debugfs", str(DEBUGFS_PATH)), | ||
| ssh_client, | ||
| ) | ||
|
|
||
| if result.returncode: | ||
| logger.info("Unmounting debugfs from '%s'.", str(DEBUGFS_PATH)) | ||
| common_run_command(("sudo", "umount", str(DEBUGFS_PATH)), ssh_client) | ||
| return result | ||
|
|
||
|
|
||
| def validate_fault_probability(fault_prob: int) -> None: | ||
| """Checks if fault injection probability is in between borders.""" | ||
| if not 0 <= fault_prob <= MAX_FAULT_PROBABILITY: | ||
| err_msg = f"fault_probability must be in range 0..{MAX_FAULT_PROBABILITY}." | ||
| raise ValueError(err_msg) | ||
|
|
||
|
|
||
| def change_fault_parameters( | ||
| client: SSHClient | None, | ||
| fault_probability: int, | ||
| fault_interval: int, | ||
| ) -> ExecResult: | ||
| result = ensure_debugfs(client) | ||
| if result.returncode: | ||
| return result | ||
|
|
||
| result = common_run_command(["ls", str(DEBUGFS_PATH)], ssh_client=client) | ||
| if result.returncode: | ||
| logger.error("Failed to list debugfs directory.") | ||
| return result | ||
|
|
||
| dirs = [ | ||
| dir_name | ||
| for dir_name in result.stdout.splitlines() | ||
| if ("fail" in dir_name or "fault" in dir_name) and dir_name != "fault_around_bytes" | ||
| ] | ||
| if not dirs: | ||
| logger.warning("No fault-injection debugfs entries found under %s", str(DEBUGFS_PATH)) | ||
| return result | ||
|
|
||
| # When fault injection is enabled, times should be set to -1, so that it would run infinitely | ||
| # When fault injection is disabled, times set to default 1 | ||
| times = -1 if fault_probability > 0 else 1 | ||
| last_result = result | ||
| for directory in dirs: | ||
| dir_path = DEBUGFS_PATH / directory | ||
| updates = ( | ||
| ("interval", fault_interval), | ||
| ("space", 0), | ||
| ("times", times), | ||
| ("probability", fault_probability), | ||
| ) | ||
|
|
||
| for parameter, value in updates: | ||
| write_cmd = ["echo", f"{value}", ">", f"{dir_path}/{parameter}"] | ||
| result = common_run_command(write_cmd, ssh_client=client) | ||
| last_result = result | ||
| if result.returncode: | ||
| logger.error( | ||
| "Failed to update fault-injection parameter %s in %s", | ||
| parameter, | ||
| dir_path, | ||
| ) | ||
| return result | ||
| return last_result | ||
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
Oops, something went wrong.
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.