Skip to main content

Chaos Toolkit Extension for SaltStack

Build Status Python versions

This project is a collection of actions and probes, gathered as an extension to the Chaos Toolkit.

Generally SaltStack runs minion agents in machine level, and minions are under management of one or more SaltMaster machines. On the SaltMaster or via API, SaltMaster can run bulk commands or scripts or other actions on any connected minion. The biggest advantage of SaltSatck is adapting cross cloud solutions on VM level chaos experiments. If you are working on hybrid cloud and have network tunnelled, one SaltMaster could control all VMs across multiple clouds, e.g. Azure, AWS, etc.

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.

$ pip install -U chaostoolkit-saltstack

Usage

To use the probes and actions from this package, add the following to your experiment file:

{
    "type": "action",
    "name": "burn_cpu",
    "provider": {
        "type": "python",
        "module": "chaossaltstack.machines.actions",
        "func": "burn_cpu",
        "secrets": ["saltstack"],
        "arguments": {
            "parameters": {
                "execution_duration": "300"
            }
        }
    }
}

That's it!

Please explore the code to see existing probes and actions.

Configuration

Credentials

0. Salt Master URL
    * SALTMASTER_HOST

1. Useranme & Password.
   -d username='salt' -d password='abcd1234' -d eauth='pam'
   Then a token in obrained via <salt_url>/login

2. Token
   A token directly, same with the backend of 1.

3. Key, only from Salt Master
    * SALTMASTER_HOST: Salt Master API address

    You can authenticate with user / password via:
    * SALTMASTER_USER: the user name
    * SALTMASTER_PASSWORD: the password

    Or via a token:
    * SALTMASTER_TOKEN

There are two ways of doing this:

  • you can either pass the name of the environment variables to the experiment definition as follows (recommended):

    {
        "saltstack": {
            "SALTMASTER_HOST": {
                "type": "env",
                "key": "SALTMASTER_HOST"
            },
            "SALTMASTER_USER": {
                "type": "env",
                "key": "SALTMASTER_USER"
            },
            "SALTMASTER_PASSWORD": {
                "type": "env",
                "key": "SALTMASTER_PASSWORD"
            }
        }
    }
    
    {
        "saltstack": {
            "SALTMASTER_HOST": {
                "type": "env",
                "key": "SALTMASTER_HOST"
            },
            "SALTMASTER_TOKEN": {
                "type": "env",
                "key": "SALTMASTER_TOKEN"
            }
        }
    }
    
  • or you inject the secrets explicitly to the experiment definition:

    {
        "saltstack": {
            "SALTMASTER_HOST": "https://172.10.20.666",
            "SALTMASTER_USER": "username",
            "SALTMASTER_PASSWORD": "password"
        }
    }
    
    {
        "saltstack": {
            "SALTMASTER_HOST": "https://172.10.20.666",
            "SALTMASTER_TOKEN": "abcd1234abcd1234abcd1234"
        }
    }
    

    Additionally you may directly use if you are on the SaltMaster

Putting it all together

Here is a full example:

{
  "version": "1.0.0",
  "title": "...",
  "description": "...",
  "tags": [
    "azure",
    "kubernetes",
	"aks",
	"node"
  ],
  "configuration": {
    "saltstack": {
        "environment": "azure"
	}
  },
  "secrets": {
   "saltstack": {
       "SALTMASTER_HOST": "https://172.20.1.172:8000",
       "SALTMASTER_USER": "saltuser",
       "SALTMASTER_PASSWORD": "asfasfasdfa"
    }
   },
  "steady-state-hypothesis": {
    "title": "Services are all available and healthy",
    "probes": [
      {
        "type": "probe",
        "name": "check_minions_online",
        "provider": {
          "type": "python",
          "module": "chaossaltstack.machine.probes",
          "func": "is_minion_online",
          "arguments": {
              "instance_ids": [ "PABCDEFGS0016","PABCDEFGS0666" ]
          },
          "secrets": ["saltstack"]
        }
      }
    ]
  },
  "method": [
    {
        "type": "action",
        "name": "stress_cpu",
        "provider": {
            "type": "python",
          "module": "chaossaltstack.machine.probes",
            "module": "saltstack.machine.actions",
            "func": "stress_cpu",
            "arguments": {
                "execution_duration": "300",
                "instance_ids": [ "PABCDEFGS0016","PABCDEFGS0666" ]
            },
            "secrets": ["saltstack"]
        }
    }
  ],
  "rollbacks": [

  ]
}

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.

The Chaos Toolkit projects require all contributors must sign a Developer Certificate of Origin on each commit they would like to merge into the master branch of the repository. Please, make sure you can abide by the rules of the DCO before submitting a PR.

Develop

If you wish to develop on this project, make sure to install the development dependencies. But first, create a virtual environment and then install those dependencies.

$ pip install -r requirements-dev.txt -r requirements.txt 

Then, point your environment to this directory:

$ pip install -e .

Now, you can edit the files and they will be automatically be seen by your environment, even when running from the chaos command locally.

Test

To run the tests for the project execute the following:

$ pytest

Metadata

Release files for chaostoolkit-saltstack 0.1.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-saltstack 0.1.0
File Size Uploaded
chaostoolkit-saltstack-0.1.0.tar.gz 15.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chaostoolkit-saltstack 0.1.0
File Interpreter ABI Platform
chaostoolkit_saltstack-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.8 kB

Release files / chaostoolkit-saltstack-0.1.0.tar.gz

Download URL chaostoolkit-saltstack-0.1.0.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bcbbba22de15fbe027226e38e2d1932519e8d6b93dcef066aa8cf92a85c2eb5c
BLAKE2b-256 checksum
How to use checksums
2badbf0fa942fb572966d2045f764603b4c4a6fe4177725c2e5d06fd198e0616
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.5.6

Release files / chaostoolkit_saltstack-0.1.0-py3-none-any.whl

Download URL chaostoolkit_saltstack-0.1.0-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e1b60cfad8b42f5bdfefba3516e04703ca66d2d3e860ae0d8e3e0eae5ad7689d
BLAKE2b-256 checksum
How to use checksums
5fd4ecce2e1bb4e6b5ca04d9af1e7b3a24d108b64d8ea5e2bfc2bd2ad4b5287c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.5.6

Release history Release notifications | RSS feed

This release

0.1.0 This release

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