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())

Release files for sabotage 1.0.1

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

Source distribution (sdist)

Source distribution for sabotage 1.0.1
File Size Uploaded
sabotage-1.0.1.tar.gz 9.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sabotage 1.0.1
File Interpreter ABI Platform
sabotage-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 20.2 kB

Release files / sabotage-1.0.1.tar.gz

Download URL sabotage-1.0.1.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1ad68f12b84998c6a547c7db2f09cc7fd0db029d45acf9961800106de08da94d
BLAKE2b-256 checksum
How to use checksums
5ce4c44b2384d46bf867016fc138b815cb3442279f2c3e91dd05ef626241b1d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.9

Release files / sabotage-1.0.1-py3-none-any.whl

Download URL sabotage-1.0.1-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d744c2336b275e018909ae03d2e2bf8301dc01a73281632e9828508e5cc47a72
BLAKE2b-256 checksum
How to use checksums
1c7f090b46f609183e04a558ee728c103a559a8cd17859ede766f0ca1d27976c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.9

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

1 release file

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