alexei-led / pumba

Chaos testing, network emulation, and stress testing tool for containers
Apache License 2.0
2.78k stars 196 forks source link

I had a question regarding multiple command orchestration #261

Open DracoStriker opened 2 months ago

DracoStriker commented 2 months ago

Hi,

I have tried out Pumba, it's an incredible tool! I require my test case to perform different perturbations simultaneously in different docker containers and interfaces. Is it possible to perform multiple subcommands to the same interface, or even to multiple interfaces or containers in the same main command or is it required to run multiple processes, one for each subcommand, forking in a bash script?

For example: eth0 of container 1 has packets delayed, container 2 is temporarily stopped, 1 minute after I require to drop some packets from eth0 of container 1 and 1 min after restore container 2.

If you think is a better way to achieve this I'm open to ideas.

Best regards

alexei-led commented 2 months ago

Yes, you can run multiple pumba commands.

#!/bin/bash

# start two containers (alpine with iproute2 package)
docker run -d --name container1 hphil/alpine-iproute2 sh -c "trap 'exit 0' SIGTERM; while true; do sleep 1; done"
docker run -d --name container2 hphil/alpine-iproute2 sh -c "trap 'exit 0' SIGTERM; while true; do sleep 1; done"

# Delay packets on eth0 of container1
pumba netem --interface=eth0 --duration=60s delay container1 &

# Stop container2 and restart it after 120s
pumba stop --duration=120s --restart container2 &

# Wait for 1 minute
sleep 60

# Drop packets on eth0 of container1
pumba netem --interface=eth0 --duration=60s loss container1 &

# Wait for 1 minute
sleep 60

# Wait for all background processes to finish
wait

Description of the Code

DracoStriker commented 2 months ago

That's exactly what I need, thanks for the detailed explanation and example!