Skip to main content

sabotage

Codecov PyPI PyPI - Downloads Python Version

sabotage is a package designed to assist developers in testing the resilience and fault tolerance of applications running in Docker containers. It offers functionality to simulate failures by either temporarily stopping containers (sabotaged_container) or disconnecting them from their networks (sabotaged_network).

Installation

$ pip3 install sabotage

Usage

📦 Sabotaged Container

@asynccontextmanager
async def sabotaged_container(service_name: str,
                              project_name: Optional[str] = None,
                              *,
                              wait_timeout: float = 30.0,
                              wait_interval: float = 0.01
                              ) -> AsyncGenerator[None, None]:

Temporarily stops a specified Docker container and restarts it after performing tasks within the context. Useful for testing how applications handle Docker container failures.

Parameters:

  • service_name (str): The name of the Docker service.
  • project_name (str): (Optional) The Docker Compose project name. If not provided, it defaults to the COMPOSE_PROJECT_NAME environment variable.
  • wait_timeout (float): (Optional) The maximum time to wait for the container to become healthy upon restart.
  • wait_interval (float): (Optional) The polling interval to check the container's health status.
import asyncio
from sabotage import sabotaged_container

async def test_container_restart():
    async with sabotaged_container("app"):
        # Perform actions while the container is stopped
        print("Container is temporarily stopped.")

    # Actions after the container restarts
    print("Container has restarted.")

asyncio.run(test_container_restart())

🌐 Sabotaged Network

@asynccontextmanager
async def sabotaged_network(service_name: str,
                            project_name: Optional[str] = None
                            ) -> AsyncGenerator[None, None]:

Disconnects and reconnects a container from its networks to simulate network issues.

  • service_name (str): The name of the Docker service.
  • project_name (str): (Optional) The Docker Compose project name. If not provided, it defaults to the COMPOSE_PROJECT_NAME environment variable.
import asyncio
from sabotage import sabotaged_network

async def test_network_disruption():
    async with sabotaged_network("app"):
        # Perform actions while the network is disconnected
        print("Network is temporarily disconnected.")

    # Actions after the network is reconnected
    print("Network has been reconnected.")

asyncio.run(test_network_disruption())

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sabotage-1.0.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sabotage-1.0.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file sabotage-1.0.1.tar.gz.

File metadata

  • Download URL: sabotage-1.0.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for sabotage-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1ad68f12b84998c6a547c7db2f09cc7fd0db029d45acf9961800106de08da94d
MD5 7a699215501b579b14531025092b3c88
BLAKE2b-256 5ce4c44b2384d46bf867016fc138b815cb3442279f2c3e91dd05ef626241b1d9

See more details on using hashes here.

File details

Details for the file sabotage-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: sabotage-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for sabotage-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d744c2336b275e018909ae03d2e2bf8301dc01a73281632e9828508e5cc47a72
MD5 a4c65f88925d526ce13c2dab78dcb3e0
BLAKE2b-256 1c7f090b46f609183e04a558ee728c103a559a8cd17859ede766f0ca1d27976c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 files

1.0.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page