-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fault injector boilerplate #3749
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
petyaslavova
merged 4 commits into
redis:master
from
kiryazovi-redis:fault_injector_boilerplate
Aug 25, 2025
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
50e66df
Add fault injector client for Redis Enterprise testing
kiryazovi-redis f6c6ef8
Apply linting fixes to fault injector client
kiryazovi-redis 4b31c1c
take care of review issues
kiryazovi-redis da5dfcf
Merge branch 'master' into fault_injector_boilerplate
petyaslavova 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
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,111 @@ | ||
import json | ||
import urllib.request | ||
from typing import Dict, Any, Optional, Union | ||
from enum import Enum | ||
|
||
|
||
class ActionType(str, Enum): | ||
DMC_RESTART = "dmc_restart" | ||
FAILOVER = "failover" | ||
RESHARD = "reshard" | ||
SEQUENCE_OF_ACTIONS = "sequence_of_actions" | ||
NETWORK_FAILURE = "network_failure" | ||
EXECUTE_RLUTIL_COMMAND = "execute_rlutil_command" | ||
EXECUTE_RLADMIN_COMMAND = "execute_rladmin_command" | ||
|
||
|
||
class RestartDmcParams: | ||
def __init__(self, bdb_id: str): | ||
self.bdb_id = bdb_id | ||
|
||
def to_dict(self) -> Dict[str, str]: | ||
return {"bdb_id": self.bdb_id} | ||
|
||
|
||
class ActionRequest: | ||
def __init__( | ||
self, | ||
action_type: ActionType, | ||
parameters: Union[Dict[str, Any], RestartDmcParams], | ||
): | ||
self.type = action_type | ||
self.parameters = parameters | ||
|
||
def to_dict(self) -> Dict[str, Any]: | ||
return { | ||
"type": self.type.value, # Use the string value of the enum | ||
"parameters": self.parameters.to_dict() | ||
if isinstance(self.parameters, RestartDmcParams) | ||
else self.parameters, | ||
} | ||
|
||
|
||
class FaultInjectorClient: | ||
def __init__(self, base_url: str): | ||
self.base_url = base_url.rstrip("/") | ||
|
||
def _make_request( | ||
self, method: str, path: str, data: Optional[Dict] = None | ||
) -> Dict[str, Any]: | ||
url = f"{self.base_url}{path}" | ||
headers = {"Content-Type": "application/json"} if data else {} | ||
|
||
request_data = None | ||
if data: | ||
request_data = json.dumps(data).encode("utf-8") | ||
print(f"JSON payload being sent: {request_data.decode('utf-8')}") | ||
kiryazovi-redis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
request = urllib.request.Request( | ||
url, method=method, data=request_data, headers=headers | ||
) | ||
|
||
try: | ||
with urllib.request.urlopen(request) as response: | ||
return json.loads(response.read().decode("utf-8")) | ||
except urllib.error.HTTPError as e: | ||
if e.code == 422: | ||
error_body = json.loads(e.read().decode("utf-8")) | ||
raise ValueError(f"Validation Error: {error_body}") | ||
raise | ||
|
||
def list_actions(self) -> Dict[str, Any]: | ||
"""List all available actions""" | ||
return self._make_request("GET", "/action") | ||
|
||
def trigger_action(self, action_request: ActionRequest) -> Dict[str, Any]: | ||
"""Trigger a new action""" | ||
request_data = action_request.to_dict() | ||
print(f"Sending HTTP request data: {request_data}") | ||
kiryazovi-redis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return self._make_request("POST", "/action", request_data) | ||
|
||
def get_action_status(self, action_id: str) -> Dict[str, Any]: | ||
"""Get the status of a specific action""" | ||
return self._make_request("GET", f"/action/{action_id}") | ||
|
||
def execute_rladmin_command( | ||
self, command: str, bdb_id: str = None | ||
) -> Dict[str, Any]: | ||
"""Execute rladmin command directly as string""" | ||
url = f"{self.base_url}/rladmin" | ||
|
||
# The fault injector expects the raw command string | ||
command_string = f"rladmin {command}" | ||
if bdb_id: | ||
command_string = f"rladmin -b {bdb_id} {command}" | ||
|
||
print(f"Sending rladmin command: {command_string}") | ||
kiryazovi-redis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
headers = {"Content-Type": "text/plain"} | ||
|
||
request = urllib.request.Request( | ||
url, method="POST", data=command_string.encode("utf-8"), headers=headers | ||
) | ||
|
||
try: | ||
with urllib.request.urlopen(request) as response: | ||
return json.loads(response.read().decode("utf-8")) | ||
except urllib.error.HTTPError as e: | ||
if e.code == 422: | ||
error_body = json.loads(e.read().decode("utf-8")) | ||
raise ValueError(f"Validation Error: {error_body}") | ||
raise |
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.