diff --git a/README.rst b/README.rst index 34f951a..8c2aa2e 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/disruption_generator/experiments/latency-example.yaml b/disruption_generator/experiments/latency-example.yaml new file mode 100644 index 0000000..d83d8fa --- /dev/null +++ b/disruption_generator/experiments/latency-example.yaml @@ -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 diff --git a/disruption_generator/trigger/trigger.py b/disruption_generator/trigger/trigger.py index 4fab51e..445f22c 100644 --- a/disruption_generator/trigger/trigger.py +++ b/disruption_generator/trigger/trigger.py @@ -1,8 +1,8 @@ +import asyncio +import asyncssh import logging -from asyncssh import SSHClient, create_connection - -ALL_ACTIONS = ["restart_service"] +ALL_ACTIONS = ["restart_service", "latency"] logger = logging.getLogger(__name__) @@ -41,6 +41,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 + await asyncio.sleep(wait) + if result: + rollback = await self.run_client(cmd_del) + if not rollback: + logger.info("Rollback was not successful") + + return result