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

I had a question regarding multiple command orchestration #261

Open
DracoStriker opened this issue Sep 3, 2024 · 2 comments
Open

I had a question regarding multiple command orchestration #261

DracoStriker opened this issue Sep 3, 2024 · 2 comments

Comments

@DracoStriker
Copy link

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
Copy link
Owner

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

  • Container Initialization:

    • Starts two Docker containers named container1 and container2 using the hphil/alpine-iproute2 image.
    • Each container runs a shell command that includes an infinite loop, allowing it to remain active and handle the SIGTERM signal gracefully.
  • Network Delay Simulation:

    • Uses Pumba to introduce a delay on the eth0 interface of container1 for a duration of 60 seconds.
    • The command runs in the background, allowing other commands to execute concurrently.
  • Container Stop and Restart:

    • Stops container2 for a duration of 120 seconds using Pumba, after which the container is automatically restarted.
    • This simulates a temporary outage and recovery of the container.
  • Packet Loss Simulation:

    • After a 60-second wait, introduces packet loss on the eth0 interface of container1 for 60 seconds.
    • This simulates network instability and tests the application's resilience to packet loss.
  • Final Wait:

    • Includes an additional 60-second wait to ensure all operations complete before the script exits.
    • The final wait command ensures that all background processes initiated by Pumba finish executing.
  • Overall Purpose:

    • The script demonstrates the orchestration of multiple chaos engineering scenarios using Pumba, allowing for testing of application behavior under various network conditions and container states.

@DracoStriker
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants