Name | sabotage JSON |
Version |
1.0.1
JSON |
| download |
home_page | https://github.com/tsv1/sabotage |
Summary | Simulates Docker container and network failures to test application resilience and fault tolerance |
upload_time | 2024-04-26 15:32:46 |
maintainer | None |
docs_url | None |
author | Nikita Tsvetkov |
requires_python | >=3.8 |
license | Apache-2.0 |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# sabotage
[![Codecov](https://img.shields.io/codecov/c/github/tsv1/sabotage/master.svg?style=flat-square)](https://codecov.io/gh/tsv1/sabotage)
[![PyPI](https://img.shields.io/pypi/v/sabotage.svg?style=flat-square)](https://pypi.python.org/pypi/sabotage/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/sabotage?style=flat-square)](https://pypi.python.org/pypi/sabotage/)
[![Python Version](https://img.shields.io/pypi/pyversions/sabotage.svg?style=flat-square)](https://pypi.python.org/pypi/sabotage/)
`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
```shell
$ pip3 install sabotage
```
## Usage
### 📦 Sabotaged Container
```python
@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.
```python
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
```python
@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.
```python
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())
```
Raw data
{
"_id": null,
"home_page": "https://github.com/tsv1/sabotage",
"name": "sabotage",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Nikita Tsvetkov",
"author_email": "tsv1@fastmail.com",
"download_url": "https://files.pythonhosted.org/packages/5c/e4/c44b2384d46bf867016fc138b815cb3442279f2c3e91dd05ef626241b1d9/sabotage-1.0.1.tar.gz",
"platform": null,
"description": "# sabotage\n\n[![Codecov](https://img.shields.io/codecov/c/github/tsv1/sabotage/master.svg?style=flat-square)](https://codecov.io/gh/tsv1/sabotage)\n[![PyPI](https://img.shields.io/pypi/v/sabotage.svg?style=flat-square)](https://pypi.python.org/pypi/sabotage/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/sabotage?style=flat-square)](https://pypi.python.org/pypi/sabotage/)\n[![Python Version](https://img.shields.io/pypi/pyversions/sabotage.svg?style=flat-square)](https://pypi.python.org/pypi/sabotage/)\n\n`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`). \n\n## Installation\n\n```shell\n$ pip3 install sabotage\n```\n\n## Usage\n\n### \ud83d\udce6 Sabotaged Container\n\n```python\n@asynccontextmanager\nasync def sabotaged_container(service_name: str,\n project_name: Optional[str] = None,\n *,\n wait_timeout: float = 30.0,\n wait_interval: float = 0.01\n ) -> AsyncGenerator[None, None]:\n```\nTemporarily stops a specified Docker container and restarts it after performing tasks within the context. Useful for testing how applications handle Docker container failures.\n\nParameters:\n- `service_name` (str): The name of the Docker service.\n- `project_name` (str): (Optional) The Docker Compose project name. If not provided, it defaults to the `COMPOSE_PROJECT_NAME` environment variable.\n- `wait_timeout` (float): (Optional) The maximum time to wait for the container to become healthy upon restart.\n- `wait_interval` (float): (Optional) The polling interval to check the container's health status.\n\n```python\nimport asyncio\nfrom sabotage import sabotaged_container\n\nasync def test_container_restart():\n async with sabotaged_container(\"app\"):\n # Perform actions while the container is stopped\n print(\"Container is temporarily stopped.\")\n\n # Actions after the container restarts\n print(\"Container has restarted.\")\n\nasyncio.run(test_container_restart())\n```\n\n### \ud83c\udf10 Sabotaged Network\n\n\n```python\n@asynccontextmanager\nasync def sabotaged_network(service_name: str,\n project_name: Optional[str] = None\n ) -> AsyncGenerator[None, None]:\n```\n\nDisconnects and reconnects a container from its networks to simulate network issues.\n\n- `service_name` (str): The name of the Docker service.\n- `project_name` (str): (Optional) The Docker Compose project name. If not provided, it defaults to the `COMPOSE_PROJECT_NAME` environment variable.\n\n```python\nimport asyncio\nfrom sabotage import sabotaged_network\n\nasync def test_network_disruption():\n async with sabotaged_network(\"app\"):\n # Perform actions while the network is disconnected\n print(\"Network is temporarily disconnected.\")\n\n # Actions after the network is reconnected\n print(\"Network has been reconnected.\")\n\nasyncio.run(test_network_disruption())\n```\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Simulates Docker container and network failures to test application resilience and fault tolerance",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/tsv1/sabotage"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1c7f090b46f609183e04a558ee728c103a559a8cd17859ede766f0ca1d27976c",
"md5": "a4c65f88925d526ce13c2dab78dcb3e0",
"sha256": "d744c2336b275e018909ae03d2e2bf8301dc01a73281632e9828508e5cc47a72"
},
"downloads": -1,
"filename": "sabotage-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a4c65f88925d526ce13c2dab78dcb3e0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 10305,
"upload_time": "2024-04-26T15:32:45",
"upload_time_iso_8601": "2024-04-26T15:32:45.398419Z",
"url": "https://files.pythonhosted.org/packages/1c/7f/090b46f609183e04a558ee728c103a559a8cd17859ede766f0ca1d27976c/sabotage-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5ce4c44b2384d46bf867016fc138b815cb3442279f2c3e91dd05ef626241b1d9",
"md5": "7a699215501b579b14531025092b3c88",
"sha256": "1ad68f12b84998c6a547c7db2f09cc7fd0db029d45acf9961800106de08da94d"
},
"downloads": -1,
"filename": "sabotage-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "7a699215501b579b14531025092b3c88",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 9860,
"upload_time": "2024-04-26T15:32:46",
"upload_time_iso_8601": "2024-04-26T15:32:46.429105Z",
"url": "https://files.pythonhosted.org/packages/5c/e4/c44b2384d46bf867016fc138b815cb3442279f2c3e91dd05ef626241b1d9/sabotage-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-26 15:32:46",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "tsv1",
"github_project": "sabotage",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "sabotage"
}