Skip to content

Extension chaoswm

Version 0.1.2
Repository https://github.com/chaostoolkit-incubator/chaostoolkit-wiremock

=====================

Build Status image

Chaos Toolkit driver for WireMock.

Package installation

To install the package from pypi.org:

pip install -U chaostoolkit-wiremock

Installation from source

In order to use it, you need python 3.5+ in your environment. Once downloaded the project, cd into it and run:

pip install -r requirements.txt -r requirements-dev.txt
make clean && make test && make install

Configuration

The following keys can be configured in the experiment global configuration section, under the "wiremock" key:

  • host: the wiremock server host
  • port: the wiremock server port
  • contextPath: the contextPath for your wiremock server (optional)
  • timeout: accepted timeout (defaults to 1 sec)
  • down: the delayDistribution section used by the down action

Configuration example:

{
    "configuration": {
        "wiremock": {
            "host": "localhost",
            "port": 8080,
            "contextPath": "/wiremock",
            "timeout": 10,
            "down": {
                "type": "lognormal",
                "median": 3000,
                "sigma": 0.2
            }
        }
    }
}

Exported Actions

Adding a list of mappings:

{
  "method": [
    {
      "type": "action",
      "name": "adding a mapping",
      "provider": {
        "type": "python",
        "module": "chaoswm.actions",
        "func": "add_mappings",
        "arguments": {
          "mappings": [{
            "request": {
               "method": "GET",
               "url": "/hello"
            },
            "response": {
               "status": 200,
               "body": "Hello world!",
               "headers": {
                   "Content-Type": "text/plain"
               }
            } 
          }]
        }
      }
    }
  ]
}

Deleting a list of mappings:

{
  "method": [
    {
      "type": "action",
      "name": "deleting a mapping",
      "provider": {
        "type": "python",
        "module": "chaoswm.actions",
        "func": "delete_mappings",
        "arguments": {
          "filter": [{
             "method": "GET",
             "url": "/hello"
          }]
        }
      }
    }
  ]
}

Adding a global fixed delay:

{
  "method": [
    {
      "type": "action",
      "name": "Adding a global fixed delay",
      "provider": {
        "type": "python",
        "module": "chaoswm.actions",
        "func": "global_fixed_delay",
        "arguments": {
          "fixedDelay": 10
        }
      }
    }
  ]
}

Adding a global random delay:

{
  "method": [
    {
      "type": "action",
      "name": "Adding a global random delay",
      "provider": {
        "type": "python",
        "module": "chaoswm.actions",
        "func": "global_random_delay",
        "arguments": {
          "delayDistribution": {
            "type": "lognormal",
            "median": 20,
            "sigma": 0.1
          }
        }
      }
    }
  ]
}

Adding a fixed delay to a list of mappings:

{
  "method": [
    {
      "type": "action",
      "name": "Adding a fixed delay to a mapping",
      "provider": {
        "type": "python",
        "module": "chaoswm.actions",
        "func": "fixed_delay",
        "arguments": {
          "filter": [{
            "method": "GET",
            "url": "/hello1"
          }],
          "fixedDelayMilliseconds": 1000
        }
      }
    }
  ]
}

Adding a random delay to a list of mappings:

{
  "method": [
    {
      "type": "action",
      "name": "Adding a random delay to a mapping",
      "provider": {
        "type": "python",
        "module": "chaoswm.actions",
        "func": "random_delay",
        "arguments": {
          "filter": [{
            "method": "GET",
            "url": "/hello2"
          }],
          "delayDistribution": {
            "type": "lognormal",
            "median": 2000,
            "sigma": 0.5
          }
        }
      }
    }
  ]
}

Adding a ChunkedDribbleDelay to a list of mappings:

{
  "method": [
    {
      "type": "action",
      "name": "Adding a ChunkedDribbleDelay to a mapping",
      "provider": {
        "type": "python",
        "module": "chaoswm.actions",
        "func": "chunked_dribble_delay",
        "arguments": {
          "filter": [{
            "method": "GET",
            "url": "/hello"
          }],
          "chunkedDribbleDelay": {
            "numberOfChunks": 5,
            "totalDuration": 1000
          }
        }
      }
    }
  ]
}

Taking a list of mappings down (heavy distribution delay). This action will use the parameters specified in the "down" key of the configuration section:

{
  "method": [
    {
      "type": "action",
      "name": "Taking a mapping down",
      "provider": {
        "type": "python",
        "module": "chaoswm.actions",
        "func": "down",
        "arguments": {
          "filter": [{
            "method": "GET",
            "url": "/hello"
          }]
        }
      }
    }
  ]
}

Taking a list of mappings up back again:

{
  "method": [
    {
      "type": "action",
      "name": "Taking a mapping down",
      "provider": {
        "type": "python",
        "module": "chaoswm.actions",
        "func": "up",
        "arguments": {
          "filter": [{
            "method": "GET",
            "url": "/hello"
          }]
        }
      }
    }
  ]
}

Resetting the wiremock server (deleting all mappings):

{
  "method": [
    {
      "type": "action",
      "name": "Taking a mapping down",
      "provider": {
        "type": "python",
        "module": "chaoswm.actions",
        "func": "reset"
      }
    }
  ]
}

Experiments

The driver comes with an experiments directory where you can find snippets to test all APIs against a WireMock server listening on localhost:8080.

Discovery

You may use the Chaos Toolkit to discover the capabilities of this extension:

$ chaos discover chaostoolkit-wiremock  --no-install

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Exported Activities

probes


mappings

Type probe
Module chaoswm.probes
Name mappings
Return list

Signature:

def mappings(c: Dict[str, Dict[str, str]] = None) -> List[Any]:
    pass

Arguments:

Name Type Default Required
c mapping null No

Usage:

{
  "type": "probe",
  "name": "mappings",
  "provider": {
    "func": "mappings",
    "type": "python",
    "module": "chaoswm.probes"
  }
}
name: mappings
provider:
  func: mappings
  module: chaoswm.probes
  type: python
type: probe

server_running

Type probe
Module chaoswm.probes
Name server_running
Return integer

Signature:

def server_running(c: Dict[str, Dict[str, str]] = None) -> int:
    pass

Arguments:

Name Type Default Required
c mapping null No

Usage:

{
  "type": "probe",
  "name": "server-running",
  "provider": {
    "func": "server_running",
    "type": "python",
    "module": "chaoswm.probes"
  }
}
name: server-running
provider:
  func: server_running
  module: chaoswm.probes
  type: python
type: probe

actions


add_mappings

Type action
Module chaoswm.actions
Name add_mappings
Return list

adds more mappings to wiremock returns the list of ids of the mappings added

Signature:

def add_mappings(mappings: List[Any],
                 configuration: Dict[str, Dict[str, str]] = None) -> List[Any]:
    pass

Arguments:

Name Type Default Required
mappings list Yes

Usage:

{
  "type": "action",
  "name": "add-mappings",
  "provider": {
    "func": "add_mappings",
    "type": "python",
    "module": "chaoswm.actions",
    "arguments": {
      "mappings": []
    }
  }
}
name: add-mappings
provider:
  arguments:
    mappings: []
  func: add_mappings
  module: chaoswm.actions
  type: python
type: action

chunked_dribble_delay

Type action
Module chaoswm.actions
Name chunked_dribble_delay
Return list

adds a chunked dribble delay to a list of mappings

Signature:

def chunked_dribble_delay(
        filter: List[Any],
        chunkedDribbleDelay: Mapping[str, Any],
        configuration: Dict[str, Dict[str, str]] = None) -> List[Any]:
    pass

Arguments:

Name Type Default Required
filter list Yes
chunkedDribbleDelay object Yes

Usage:

{
  "type": "action",
  "name": "chunked-dribble-delay",
  "provider": {
    "func": "chunked_dribble_delay",
    "type": "python",
    "module": "chaoswm.actions",
    "arguments": {
      "chunkedDribbleDelay": null,
      "filter": []
    }
  }
}
name: chunked-dribble-delay
provider:
  arguments:
    chunkedDribbleDelay: null
    filter: []
  func: chunked_dribble_delay
  module: chaoswm.actions
  type: python
type: action

delete_mappings

Type action
Module chaoswm.actions
Name delete_mappings
Return list

deletes a list of mappings returns the list of ids of the mappings deleted

Signature:

def delete_mappings(
        filter: List[Any],
        configuration: Dict[str, Dict[str, str]] = None) -> List[Any]:
    pass

Arguments:

Name Type Default Required
filter list Yes

Usage:

{
  "type": "action",
  "name": "delete-mappings",
  "provider": {
    "func": "delete_mappings",
    "type": "python",
    "module": "chaoswm.actions",
    "arguments": {
      "filter": []
    }
  }
}
name: delete-mappings
provider:
  arguments:
    filter: []
  func: delete_mappings
  module: chaoswm.actions
  type: python
type: action

down

Type action
Module chaoswm.actions
Name down
Return list

set a list of services down more correctly it adds a chunked dribble delay to the mapping as defined in the configuration section (or action attributes) Returns the list of delayed mappings

Signature:

def down(filter: List[Any],
         configuration: Dict[str, Dict[str, str]] = None) -> List[Any]:
    pass

Arguments:

Name Type Default Required
filter list Yes

Usage:

{
  "type": "action",
  "name": "down",
  "provider": {
    "func": "down",
    "type": "python",
    "module": "chaoswm.actions",
    "arguments": {
      "filter": []
    }
  }
}
name: down
provider:
  arguments:
    filter: []
  func: down
  module: chaoswm.actions
  type: python
type: action

fixed_delay

Type action
Module chaoswm.actions
Name fixed_delay
Return list

adds a fixed delay to a list of mappings

Signature:

def fixed_delay(filter: List[Any],
                fixedDelayMilliseconds: int,
                configuration: Dict[str, Dict[str, str]] = None) -> List[Any]:
    pass

Arguments:

Name Type Default Required
filter list Yes
fixedDelayMilliseconds integer Yes

Usage:

{
  "type": "action",
  "name": "fixed-delay",
  "provider": {
    "func": "fixed_delay",
    "type": "python",
    "module": "chaoswm.actions",
    "arguments": {
      "fixedDelayMilliseconds": 0,
      "filter": []
    }
  }
}
name: fixed-delay
provider:
  arguments:
    filter: []
    fixedDelayMilliseconds: 0
  func: fixed_delay
  module: chaoswm.actions
  type: python
type: action

global_fixed_delay

Type action
Module chaoswm.actions
Name global_fixed_delay
Return integer

add a fixed delay to all mappings

Signature:

def global_fixed_delay(fixedDelay: int = 0,
                       configuration: Dict[str, Dict[str, str]] = None) -> int:
    pass

Arguments:

Name Type Default Required
fixedDelay integer 0 No

Usage:

{
  "type": "action",
  "name": "global-fixed-delay",
  "provider": {
    "func": "global_fixed_delay",
    "type": "python",
    "module": "chaoswm.actions"
  }
}
name: global-fixed-delay
provider:
  func: global_fixed_delay
  module: chaoswm.actions
  type: python
type: action

global_random_delay

Type action
Module chaoswm.actions
Name global_random_delay
Return integer

adds a random delay to all mappings

Signature:

def global_random_delay(
        delayDistribution: Mapping[str, Any],
        configuration: Dict[str, Dict[str, str]] = None) -> int:
    pass

Arguments:

Name Type Default Required
delayDistribution object Yes

Usage:

{
  "type": "action",
  "name": "global-random-delay",
  "provider": {
    "func": "global_random_delay",
    "type": "python",
    "module": "chaoswm.actions",
    "arguments": {
      "delayDistribution": null
    }
  }
}
name: global-random-delay
provider:
  arguments:
    delayDistribution: null
  func: global_random_delay
  module: chaoswm.actions
  type: python
type: action

populate_from_dir

Type action
Module chaoswm.actions
Name populate_from_dir
Return list

adds all mappings found in the passed folder returns the list of ids of the mappings added

Signature:

def populate_from_dir(
        dir: str = '.',
        configuration: Dict[str, Dict[str, str]] = None) -> List[Any]:
    pass

Arguments:

Name Type Default Required
dir string ”.” No

Usage:

{
  "type": "action",
  "name": "populate-from-dir",
  "provider": {
    "func": "populate_from_dir",
    "type": "python",
    "module": "chaoswm.actions"
  }
}
name: populate-from-dir
provider:
  func: populate_from_dir
  module: chaoswm.actions
  type: python
type: action

random_delay

Type action
Module chaoswm.actions
Name random_delay
Return list

adds a random delay to a list of mapppings

Signature:

def random_delay(filter: List[Any],
                 delayDistribution: Mapping[str, Any],
                 configuration: Dict[str, Dict[str, str]] = None) -> List[Any]:
    pass

Arguments:

Name Type Default Required
filter list Yes
delayDistribution object Yes

Usage:

{
  "type": "action",
  "name": "random-delay",
  "provider": {
    "func": "random_delay",
    "type": "python",
    "module": "chaoswm.actions",
    "arguments": {
      "delayDistribution": null,
      "filter": []
    }
  }
}
name: random-delay
provider:
  arguments:
    delayDistribution: null
    filter: []
  func: random_delay
  module: chaoswm.actions
  type: python
type: action

reset

Type action
Module chaoswm.actions
Name reset
Return integer

resets the wiremock server: deletes all mappings!

Signature:

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

Arguments:

Name Type Default Required

Usage:

{
  "type": "action",
  "name": "reset",
  "provider": {
    "func": "reset",
    "type": "python",
    "module": "chaoswm.actions"
  }
}
name: reset
provider:
  func: reset
  module: chaoswm.actions
  type: python
type: action

up

Type action
Module chaoswm.actions
Name up
Return list

deletes all delays connected with a list of mappings

Signature:

def up(filter: List[Any],
       configuration: Dict[str, Dict[str, str]] = None) -> List[Any]:
    pass

Arguments:

Name Type Default Required
filter list Yes

Usage:

{
  "type": "action",
  "name": "up",
  "provider": {
    "func": "up",
    "type": "python",
    "module": "chaoswm.actions",
    "arguments": {
      "filter": []
    }
  }
}
name: up
provider:
  arguments:
    filter: []
  func: up
  module: chaoswm.actions
  type: python
type: action

utils


can_connect_to

Type
Module chaoswm.utils
Name can_connect_to
Return boolean

Test a connection to a host/port

Signature:

def can_connect_to(host: str, port: int) -> bool:
    pass

Arguments:

Name Type Default Required
host string Yes
port integer Yes

Usage:

{
  "type": "",
  "name": "can-connect-to",
  "provider": {
    "func": "can_connect_to",
    "type": "python",
    "module": "chaoswm.utils",
    "arguments": {
      "port": 0,
      "host": ""
    }
  }
}
name: can-connect-to
provider:
  arguments:
    host: ''
    port: 0
  func: can_connect_to
  module: chaoswm.utils
  type: python
type: ''

check_configuration

Type
Module chaoswm.utils
Name check_configuration
Return boolean

Signature:

def check_configuration(c: Dict[str, Any] = None) -> bool:
    pass

Arguments:

Name Type Default Required
c mapping null No

Usage:

{
  "type": "",
  "name": "check-configuration",
  "provider": {
    "func": "check_configuration",
    "type": "python",
    "module": "chaoswm.utils"
  }
}
name: check-configuration
provider:
  func: check_configuration
  module: chaoswm.utils
  type: python
type: ''

get_wm_params

Type
Module chaoswm.utils
Name get_wm_params
Return Union[Dict[str, Any], NoneType]

Signature:

def get_wm_params(c: Dict[str, Any]) -> Union[Dict[str, Any], NoneType]:
    pass

Arguments:

Name Type Default Required
c mapping Yes

Usage:

{
  "type": "",
  "name": "get-wm-params",
  "provider": {
    "func": "get_wm_params",
    "type": "python",
    "module": "chaoswm.utils",
    "arguments": {
      "c": {}
    }
  }
}
name: get-wm-params
provider:
  arguments:
    c: {}
  func: get_wm_params
  module: chaoswm.utils
  type: python
type: ''