-
Notifications
You must be signed in to change notification settings - Fork 4
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
[RFR] Added latency DA #37
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
- disrupt_action: | ||
- name: Restart sysstat on regex ocurrance | ||
listener: | ||
re: FINISH | ||
log: /var/log/vdsm/vdsm.log | ||
host: localhost | ||
trigger: | ||
- action: | ||
name: latency | ||
params: 100ms | ||
target_host: localhost | ||
wait: 3 | ||
timeout: 10 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import asyncio | ||
import asyncssh | ||
import logging | ||
|
||
ALL_ACTIONS = ["restart_service"] | ||
ALL_ACTIONS = ["restart_service", "latency"] | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -28,6 +29,31 @@ async def run_client(self, cmd): | |
return False | ||
|
||
async def restart_service(self): | ||
""" | ||
Restart a service on a remote host | ||
|
||
Returns: | ||
result (bool): Result of the restart | ||
""" | ||
cmd = "systemctl restart" | ||
result = await self.run_client(cmd) | ||
return result | ||
|
||
async def latency(self): | ||
""" | ||
Add latency to a remote hosts link | ||
|
||
Returns: | ||
result (bool): True if successful, False otherwise | ||
""" | ||
cmd_add = "tc qdisc add dev eth0 root netem delay" | ||
cmd_del = "tc qdisc del dev eth0 root netem delay" | ||
result = await self.run_client(cmd_add) | ||
wait = self.action.wait if self.action.wait else 10 | ||
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. I think this is an use case for getattr. Also, I thank that the default wait time (10) should be either configurable or better expose. At least put it to coroutine docstring pls. |
||
await asyncio.sleep(wait) | ||
if result: | ||
rollback = await self.run_client(cmd_del) | ||
if not rollback: | ||
logger.info("Rollback was not successful") | ||
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. Should not this be logger as a warning? Maybe ever error? |
||
|
||
return result |
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.
device eth0 should be configurable