Skip to main content

Chaos Toolkit extension for Docker Swarm

This is a Chaos Toolkit extension package with probes and actions for Docker Swarm. Its main motivation is that in a multinode Swarm cluster, Docker provides no method to act on containers on remote nodes, e.g. to kill it. Thus, in order to harass a random container in a service, you would have to log in to a Swarm node and perform the command there.

This extension solves this shortcoming by launching a global-mode helper service in your swarm which mounts the Docker socket on all nodes and thus allows you to perform specific commands on any node. For more information, see chaostoolkit-docker-swarm-helper.

Install

This package requires Python 3.5+

To be used from your experiment, this package must be installed in the Python environment where chaostoolkit already lives. A fresh setup may look like this:

virtualenv chaosenv -p /usr/bin/python3
. ./chaosenv/bin/activate
pip install chaostoolkit chaostoolkit-docker-swarm

Usage

version: 1.0.0
title: Redis Docker service should survive container death
description: Docker Swarm should recreate the Redis container
steady-state-hypothesis:
  title: Redis service with running container exists
  probes:
    - name: Redis container must exist
      type: probe
      tolerance: 1
      provider:
        type: python
        module: chaosswarm.probes
        func: running_tasks
        arguments:
          service: redis
method:
  - name: Kill a Redis task
    type: action
    provider:
      type: python
      module: chaosswarm.actions
      func: kill_task
      arguments:
        service: redis
    pauses:
      after: 7
docker service create --name redis redis:latest
chaos run ./swarm-experiment.yaml
[2020-01-27 20:34:51 INFO] Validating the experiment's syntax
[2020-01-27 20:34:51 INFO] Experiment looks valid
[2020-01-27 20:34:51 INFO] Running experiment: Redis Docker service should survive container death
[2020-01-27 20:34:51 INFO] Steady state hypothesis: Redis service with running container exists
[2020-01-27 20:34:51 INFO] Probe: Redis container must exist
[2020-01-27 20:34:51 INFO] Steady state hypothesis is met!
[2020-01-27 20:34:51 INFO] Action: Kill a Redis task
[2020-01-27 20:34:51 INFO] Pausing after activity for 5s...
[2020-01-27 20:34:56 INFO] Steady state hypothesis: Redis service with running container exists
[2020-01-27 20:34:56 INFO] Probe: Redis container must exist
[2020-01-27 20:34:56 INFO] Steady state hypothesis is met!
[2020-01-27 20:34:56 INFO] Let's rollback...
[2020-01-27 20:34:56 INFO] No declared rollbacks, let's move on.
[2020-01-27 20:34:56 INFO] Experiment ended with status: completed

Configuration

This extension assumes your environment is set up for Docker access, e.g. using Docker environment variables.

Test

To run the tests for the project execute the following:

python3 setup.py test

There are integration tests which assume you have a Docker Swarm cluster available. You can promote your local dev Docker to a 1-node Swarm cluster with:

docker swarm init

Contribute

If you wish to contribute more functions to this package, you are more than welcome to do so. Please, fork this project, make your changes following the usual PEP 8 code style, sprinkling with tests and submit a PR for review.

Release files for chaostoolkit-docker-swarm 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chaostoolkit-docker-swarm 0.3.0
File Size Uploaded
chaostoolkit-docker-swarm-0.3.0.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chaostoolkit-docker-swarm 0.3.0
File Interpreter ABI Platform
chaostoolkit_docker_swarm-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.5 kB

Release files / chaostoolkit-docker-swarm-0.3.0.tar.gz

Download URL chaostoolkit-docker-swarm-0.3.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4a81cf9b9a11d4fe8662e01a272b8042ab677198108008b41d43aebe2083ec99
BLAKE2b-256 checksum
How to use checksums
d8d41d9a947fa3f278ff215f8b4d3b1ef7831e1f0ce35de046b1e6f1a6ead725
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.0

Release files / chaostoolkit_docker_swarm-0.3.0-py3-none-any.whl

Download URL chaostoolkit_docker_swarm-0.3.0-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b7002c458fbe0fc070a22dc86d895a76783dbfdfb6da194d0f0dfcb5d40a984e
BLAKE2b-256 checksum
How to use checksums
4448c461ae07a137b0606b3c875d4bc73f3ac9e361538a6ff9862deacf268f7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.0

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page