Skip to content

Extension chaosazure

Version 0.4.0
Repository https://github.com/chaostoolkit-incubator/chaostoolkit-azure

Build Status Python versions

This project is a collection of actions and probes, gathered as an extension to the Chaos Toolkit. It targets the Microsoft Azure platform.

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-azure

Usage

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

{
    "type": "action",
    "name": "start-service-factory-chaos",
    "provider": {
        "type": "python",
        "module": "chaosazure.vm.actions",
        "func": "stop_machines",
        "secrets": ["azure"],
        "arguments": {
            "parameters": {
                "TimeToRunInSeconds": 45
            }
        }
    }
}

That’s it!

Please explore the code to see existing probes and actions.

Configuration

Credentials

This extension uses the Azure SDK libraries under the hood. The Azure SDK library expects that you have a tenant and client identifier, as well as a client secret and subscription, that allows you to authenticate with the Azure resource management API.

There are two ways of doing this:

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

    {
        "azure": {
            "client_id": "AZURE_CLIENT_ID",
            "client_secret": "AZURE_CLIENT_SECRET",
            "tenant_id": "AZURE_TENANT_ID"
        }
    }
    
  • or you inject the secrets explicitly to the experiment definition:

    {
        "azure": {
            "client_id": "your-super-secret-client-id",
            "client_secret": "your-even-more-super-secret-client-secret",
            "tenant_id": "your-tenant-id"
        }
    }
    

    Additionally you need to provide the Azure subscription id.

    {
        "azure": {
            "subscription_id": "your-azure-subscription-id"
        }
    }
    

Putting it all together

Here is a full example:

{
  "version": "1.0.0",
  "title": "...",
  "description": "...",
  "tags": [
    "azure",
    "kubernetes",
    "aks",
    "node"
  ],
  "configuration": {
    "azure": {
      "subscription_id": "xxx"
    }
  },
  "secrets": {
    "azure": {
      "client_id": "xxx",
      "client_secret": "xxx",
      "tenant_id": "xxx"
    }
  },
  "steady-state-hypothesis": {
    "title": "Services are all available and healthy",
    "probes": [
      {
        "type": "probe",
        "name": "consumer-service-must-still-respond",
        "tolerance": 200,
        "provider": {
          "type": "http",
          "url": "https://some-url/"
        }
      }
    ]
  },
  "method": [
    {
      "type": "action",
      "name": "restart-node-at-random",
      "provider": {
        "type": "python",
        "module": "chaosazure.machine.actions",
        "func": "restart_machines",
        "secrets": [
          "azure"
        ],
        "config": [
          "azure"
        ]
      }
    }
  ],
  "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:

$ python setup.py develop

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

Exported Activities

vmss


deallocate_vmss

Type action
Module chaosazure.vmss.actions
Name deallocate_vmss
Return None

Deallocate a virtual machine scale set instance at random. Parameters


filter : str Filter the virtual machine scale set. If the filter is omitted all virtual machine scale sets in the subscription will be selected as potential chaos candidates. Filtering example: ‘where resourceGroup==”myresourcegroup” and name=”myresourcename”’

Signature:

def deallocate_vmss(filter: str = None,
                    configuration: Dict[str, Dict[str, str]] = None,
                    secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.vmss.actions",
    "func": "deallocate_vmss"
  },
  "name": "deallocate-vmss"
}
name: deallocate-vmss
provider:
  func: deallocate_vmss
  module: chaosazure.vmss.actions
  type: python
type: action

delete_vmss

Type action
Module chaosazure.vmss.actions
Name delete_vmss
Return None

Delete a virtual machine scale set instance at random.

Be aware: Deleting a VMSS instance is an invasive action. You will not be able to recover the VMSS instance once you deleted it.

Parameters

filter : str Filter the virtual machine scale set. If the filter is omitted all virtual machine scale sets in the subscription will be selected as potential chaos candidates. Filtering example: ‘where resourceGroup==”myresourcegroup” and name=”myresourcename”’

Signature:

def delete_vmss(filter: str = None,
                configuration: Dict[str, Dict[str, str]] = None,
                secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.vmss.actions",
    "func": "delete_vmss"
  },
  "name": "delete-vmss"
}
name: delete-vmss
provider:
  func: delete_vmss
  module: chaosazure.vmss.actions
  type: python
type: action

restart_vmss

Type action
Module chaosazure.vmss.actions
Name restart_vmss
Return None

Restart a virtual machine scale set instance at random. Parameters


filter : str Filter the virtual machine scale set. If the filter is omitted all virtual machine scale sets in the subscription will be selected as potential chaos candidates. Filtering example: ‘where resourceGroup==”myresourcegroup” and name=”myresourcename”’

Signature:

def restart_vmss(filter: str = None,
                 configuration: Dict[str, Dict[str, str]] = None,
                 secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.vmss.actions",
    "func": "restart_vmss"
  },
  "name": "restart-vmss"
}
name: restart-vmss
provider:
  func: restart_vmss
  module: chaosazure.vmss.actions
  type: python
type: action

stop_vmss

Type action
Module chaosazure.vmss.actions
Name stop_vmss
Return None

Stop a virtual machine scale set instance at random. Parameters


filter : str Filter the virtual machine scale set. If the filter is omitted all virtual machine scale sets in the subscription will be selected as potential chaos candidates. Filtering example: ‘where resourceGroup==”myresourcegroup” and name=”myresourcename”’

Signature:

def stop_vmss(filter: str = None,
              configuration: Dict[str, Dict[str, str]] = None,
              secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.vmss.actions",
    "func": "stop_vmss"
  },
  "name": "stop-vmss"
}
name: stop-vmss
provider:
  func: stop_vmss
  module: chaosazure.vmss.actions
  type: python
type: action

machine


count_machines

Type probe
Module chaosazure.machine.probes
Name count_machines
Return integer

Return count of Azure virtual machines.

Parameters

filter : str Filter the virtual machines. If the filter is omitted all machines in the subscription will be selected for the probe. Filtering example: ‘where resourceGroup==”myresourcegroup” and name=”myresourcename”’

Signature:

def count_machines(filter: str = None,
                   configuration: Dict[str, Dict[str, str]] = None,
                   secrets: Dict[str, Dict[str, str]] = None) -> int:
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "probe",
  "provider": {
    "type": "python",
    "module": "chaosazure.machine.probes",
    "func": "count_machines"
  },
  "name": "count-machines"
}
name: count-machines
provider:
  func: count_machines
  module: chaosazure.machine.probes
  type: python
type: probe

delete_machines

Type action
Module chaosazure.machine.actions
Name delete_machines
Return None

Delete virtual machines at random.

Be aware: Deleting a machine is an invasive action. You will not be able to recover the machine once you deleted it.

Parameters

filter : str, optional Filter the virtual machines. If the filter is omitted all machines in the subscription will be selected as potential chaos candidates.

Examples

Some calling examples. Deep dive into the filter syntax: https://docs.microsoft.com/en-us/azure/kusto/query/

delete_machines(“where resourceGroup==’rg’“, c, s) Delete all machines from the group ‘rg’

delete_machines(“where resourceGroup==’rg’ and name=’name’“, c, s) Delete the machine from the group ‘rg’ having the name ‘name’

delete_machines(“where resourceGroup==’rg’ | sample 2”, c, s) Delete two machines at random from the group ‘rg’

Signature:

def delete_machines(filter: str = None,
                    configuration: Dict[str, Dict[str, str]] = None,
                    secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.machine.actions",
    "func": "delete_machines"
  },
  "name": "delete-machines"
}
name: delete-machines
provider:
  func: delete_machines
  module: chaosazure.machine.actions
  type: python
type: action

describe_machines

Type probe
Module chaosazure.machine.probes
Name describe_machines
Return None

Describe Azure virtual machines.

Parameters

filter : str Filter the virtual machines. If the filter is omitted all machines in the subscription will be selected for the probe. Filtering example: ‘where resourceGroup==”myresourcegroup” and name=”myresourcename”’

Signature:

def describe_machines(filter: str = None,
                      configuration: Dict[str, Dict[str, str]] = None,
                      secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "probe",
  "provider": {
    "type": "python",
    "module": "chaosazure.machine.probes",
    "func": "describe_machines"
  },
  "name": "describe-machines"
}
name: describe-machines
provider:
  func: describe_machines
  module: chaosazure.machine.probes
  type: python
type: probe

restart_machines

Type action
Module chaosazure.machine.actions
Name restart_machines
Return None

Restart virtual machines at random.

Parameters

filter : str, optional Filter the virtual machines. If the filter is omitted all machines in the subscription will be selected as potential chaos candidates.

Examples

Some calling examples. Deep dive into the filter syntax: https://docs.microsoft.com/en-us/azure/kusto/query/

restart_machines(“where resourceGroup==’rg’“, c, s) Restart all machines from the group ‘rg’

restart_machines(“where resourceGroup==’rg’ and name=’name’“, c, s) Restart the machine from the group ‘rg’ having the name ‘name’

restart_machines(“where resourceGroup==’rg’ | sample 2”, c, s) Restart two machines at random from the group ‘rg’

Signature:

def restart_machines(filter: str = None,
                     configuration: Dict[str, Dict[str, str]] = None,
                     secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.machine.actions",
    "func": "restart_machines"
  },
  "name": "restart-machines"
}
name: restart-machines
provider:
  func: restart_machines
  module: chaosazure.machine.actions
  type: python
type: action

start_machines

Type action
Module chaosazure.machine.actions
Name start_machines
Return None

Start virtual machines at random. Thought as a rollback action.

Parameters

filter : str, optional Filter the virtual machines. If the filter is omitted all machines in the subscription will be selected as potential chaos candidates.

Examples

Some calling examples. Deep dive into the filter syntax: https://docs.microsoft.com/en-us/azure/kusto/query/

start_machines(“where resourceGroup==’rg’“, c, s) Start all stopped machines from the group ‘rg’

start_machines(“where resourceGroup==’rg’ and name=’name’“, c, s) Start the stopped machine from the group ‘rg’ having the name ‘name’

start_machines(“where resourceGroup==’rg’ | sample 2”, c, s) Start two stopped machines at random from the group ‘rg’

Signature:

def start_machines(filter: str = None,
                   configuration: Dict[str, Dict[str, str]] = None,
                   secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.machine.actions",
    "func": "start_machines"
  },
  "name": "start-machines"
}
name: start-machines
provider:
  func: start_machines
  module: chaosazure.machine.actions
  type: python
type: action

stop_machines

Type action
Module chaosazure.machine.actions
Name stop_machines
Return None

Stop virtual machines at random.

Parameters

filter : str, optional Filter the virtual machines. If the filter is omitted all machines in the subscription will be selected as potential chaos candidates.

Examples

Some calling examples. Deep dive into the filter syntax: https://docs.microsoft.com/en-us/azure/kusto/query/

stop_machines(“where resourceGroup==’rg’“, c, s) Stop all machines from the group ‘rg’

stop_machines(“where resourceGroup==’mygroup’ and name=’myname’“, c, s) Stop the machine from the group ‘mygroup’ having the name ‘myname’

stop_machines(“where resourceGroup==’mygroup’ | sample 2”, c, s) Stop two machines at random from the group ‘mygroup’

Signature:

def stop_machines(filter: str = None,
                  configuration: Dict[str, Dict[str, str]] = None,
                  secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.machine.actions",
    "func": "stop_machines"
  },
  "name": "stop-machines"
}
name: stop-machines
provider:
  func: stop_machines
  module: chaosazure.machine.actions
  type: python
type: action

stress_cpu

Type action
Module chaosazure.machine.actions
Name stress_cpu
Return None

Stress CPU up to 100% at random machines.

Parameters

filter : str, optional Filter the virtual machines. If the filter is omitted all machines in the subscription will be selected as potential chaos candidates. duration : int, optional Duration of the stress test (in seconds) that generates high CPU usage. Defaults to 120 seconds. timeout : int Additional wait time (in seconds) for stress operation to be completed. Getting and sending data from/to Azure may take some time so it’s not recommended to set this value to less than 30s. Defaults to 60 seconds.

Examples

Some calling examples. Deep dive into the filter syntax: https://docs.microsoft.com/en-us/azure/kusto/query/

stress_cpu(“where resourceGroup==’rg’“, configuration=c, secrets=s) Stress all machines from the group ‘rg’

stress_cpu(“where resourceGroup==’rg’ and name=’name’“, configuration=c, secrets=s) Stress the machine from the group ‘rg’ having the name ‘name’

stress_cpu(“where resourceGroup==’rg’ | sample 2”, configuration=c, secrets=s) Stress two machines at random from the group ‘rg’

Signature:

def stress_cpu(filter: str = None,
               duration: int = 120,
               timeout: int = 60,
               configuration: Dict[str, Dict[str, str]] = None,
               secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No
duration integer 120 No
timeout integer 60 No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.machine.actions",
    "func": "stress_cpu"
  },
  "name": "stress-cpu"
}
name: stress-cpu
provider:
  func: stress_cpu
  module: chaosazure.machine.actions
  type: python
type: action

webapp


delete_webapp

Type action
Module chaosazure.webapp.actions
Name delete_webapp
Return None

Delete a web app at random.

***Be aware**: Deleting a web app is an invasive action. You will not be able to recover the web app once you deleted it.

Parameters

filter : str Filter the web apps. If the filter is omitted all web apps in the subscription will be selected as potential chaos candidates. Filtering example: ‘where resourceGroup==”myresourcegroup” and name=”myresourcename”’

Signature:

def delete_webapp(filter: str = None,
                  configuration: Dict[str, Dict[str, str]] = None,
                  secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.webapp.actions",
    "func": "delete_webapp"
  },
  "name": "delete-webapp"
}
name: delete-webapp
provider:
  func: delete_webapp
  module: chaosazure.webapp.actions
  type: python
type: action

restart_webapp

Type action
Module chaosazure.webapp.actions
Name restart_webapp
Return None

Restart a web app at random.

Parameters

filter : str Filter the web apps. If the filter is omitted all web apps in the subscription will be selected as potential chaos candidates. Filtering example: ‘where resourceGroup==”myresourcegroup” and name=”myresourcename”’

Signature:

def restart_webapp(filter: str = None,
                   configuration: Dict[str, Dict[str, str]] = None,
                   secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.webapp.actions",
    "func": "restart_webapp"
  },
  "name": "restart-webapp"
}
name: restart-webapp
provider:
  func: restart_webapp
  module: chaosazure.webapp.actions
  type: python
type: action

start_webapp

Type action
Module chaosazure.webapp.actions
Name start_webapp
Return None

Start a web app at random.

Parameters

filter : str Filter the web apps. If the filter is omitted all web apps in the subscription will be selected as potential chaos candidates. Filtering example: ‘where resourceGroup==”myresourcegroup” and name=”myresourcename”’

Signature:

def start_webapp(filter: str = None,
                 configuration: Dict[str, Dict[str, str]] = None,
                 secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.webapp.actions",
    "func": "start_webapp"
  },
  "name": "start-webapp"
}
name: start-webapp
provider:
  func: start_webapp
  module: chaosazure.webapp.actions
  type: python
type: action

stop_webapp

Type action
Module chaosazure.webapp.actions
Name stop_webapp
Return None

Stop a web app at random.

Parameters

filter : str Filter the web apps. If the filter is omitted all web apps in the subscription will be selected as potential chaos candidates. Filtering example: ‘where resourceGroup==”myresourcegroup” and name=”myresourcename”’

Signature:

def stop_webapp(filter: str = None,
                configuration: Dict[str, Dict[str, str]] = None,
                secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.webapp.actions",
    "func": "stop_webapp"
  },
  "name": "stop-webapp"
}
name: stop-webapp
provider:
  func: stop_webapp
  module: chaosazure.webapp.actions
  type: python
type: action

aks


delete_node

Type action
Module chaosazure.aks.actions
Name delete_node
Return None

Delete a node at random from a managed Azure Kubernetes Service.

Be aware: Deleting a node is an invasive action. You will not be able to recover the node once you deleted it.

Parameters

filter : str Filter the managed AKS. If the filter is omitted all AKS in the subscription will be selected as potential chaos candidates. Filtering example: ‘where resourceGroup==”myresourcegroup” and name=”myresourcename”’

Signature:

def delete_node(filter: str = None,
                configuration: Dict[str, Dict[str, str]] = None,
                secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.aks.actions",
    "func": "delete_node"
  },
  "name": "delete-node"
}
name: delete-node
provider:
  func: delete_node
  module: chaosazure.aks.actions
  type: python
type: action

restart_node

Type action
Module chaosazure.aks.actions
Name restart_node
Return None

Restart a node at random from a managed Azure Kubernetes Service.

Parameters

filter : str Filter the managed AKS. If the filter is omitted all AKS in the subscription will be selected as potential chaos candidates. Filtering example: ‘where resourceGroup==”myresourcegroup” and name=”myresourcename”’

Signature:

def restart_node(filter: str = None,
                 configuration: Dict[str, Dict[str, str]] = None,
                 secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.aks.actions",
    "func": "restart_node"
  },
  "name": "restart-node"
}
name: restart-node
provider:
  func: restart_node
  module: chaosazure.aks.actions
  type: python
type: action

stop_node

Type action
Module chaosazure.aks.actions
Name stop_node
Return None

Stop a node at random from a managed Azure Kubernetes Service.

Parameters

filter : str Filter the managed AKS. If the filter is omitted all AKS in the subscription will be selected as potential chaos candidates. Filtering example: ‘where resourceGroup==”myresourcegroup” and name=”myresourcename”’

Signature:

def stop_node(filter: str = None,
              configuration: Dict[str, Dict[str, str]] = None,
              secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
filter string null No

Usage:

{
  "type": "action",
  "provider": {
    "type": "python",
    "module": "chaosazure.aks.actions",
    "func": "stop_node"
  },
  "name": "stop-node"
}
name: stop-node
provider:
  func: stop_node
  module: chaosazure.aks.actions
  type: python
type: action