Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ Providing an extendable and easy to use tool for developers and QE to ensure the
Features
--------

* Async all the things via asyncio and asyncssh
- Async all the things via asyncio and asyncssh

* Easy disruptive scenarios definitions via yaml files
- Easy disruptive scenarios definitions via yaml files

* Tail remote log files and search for regular expressions
- Tail remote log files and search for regular expressions

* Event driven disruptive actions trigger
- Event driven disruptive actions trigger

- Service restart

- Inject network latency
14 changes: 14 additions & 0 deletions disruption_generator/experiments/latency-example.yaml
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
28 changes: 27 additions & 1 deletion disruption_generator/trigger/trigger.py
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__)

Expand All @@ -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"
Copy link
Collaborator

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

result = await self.run_client(cmd_add)
wait = self.action.wait if self.action.wait else 10
Copy link
Collaborator

Choose a reason for hiding this comment

The 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")
Copy link
Collaborator

Choose a reason for hiding this comment

The 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