Package: chaostoolkit-azure
Chaos Toolkit Extension for AzureThis project is a collection ofactionsandprobes, gathered as an
extension to theChaos Toolkit. It targets theMicrosoft Azureplatform.InstallThis package requires Python 3.5+To be used from your experiment, this package must be installed in the Python
environment wherechaostoolkitalready lives.$ pip install -U chaostoolkit-azureUsageTo 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.ConfigurationThis extension uses theAzure SDKlibraries 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.Configuration values for the Chaos Toolkit Extension for Azure can come from several sources:Experiment fileAzure credential fileThe extension will first try to load the configuration from theexperiment file. If configuration is not provided in theexperiment file, it will try to load it from theAzure credential file.CredentialsEnvironment VariablesYou can pass credentials via the following environment variables:AZURE_CLIENT_IDAZURE_CLIENT_SECRETAZURE_TENANT_IDOr:AZURE_CLIENT_IDAZURE_ACCESS_TOKENExperiment SecretsYou may also pass them via the secrets block of the experiment:{"secrets":{"azure":{"client_id":"your-super-secret-client-id","client_secret":"your-even-more-super-secret-client-secret","tenant_id":"your-tenant-id"}}}You can retrieve secretes as well fromenvironmentorHashiCorp vault.If you are not working with Public Global Azure, e.g. China Cloud You can set the cloud environment.{"client_id":"your-super-secret-client-id","client_secret":"your-even-more-super-secret-client-secret","tenant_id":"your-tenant-id","cloud":"AZURE_CHINA_CLOUD"}Available cloud names:AZURE_CHINA_CLOUDAZURE_GERMAN_CLOUDAZURE_PUBLIC_CLOUDAZURE_US_GOV_CLOUDEither of these values can be passed viaAZURE_CLOUDas well.Azure Credential FileYou may also pass them via the Azure credential file:You can retrieve a credentials file with your subscription ID already in place by signing in to Azure using the az login command followed by the az ad sp create-for-rbac commandazlogin
azadspcreate-for-rbac--sdk-auth>credentials.jsoncredentials.json:{"subscriptionId":"<azure_aubscription_id>","tenantId":"<tenant_id>","clientId":"<application_id>","clientSecret":"<application_secret>","activeDirectoryEndpointUrl":"https://login.microsoftonline.com","resourceManagerEndpointUrl":"https://management.azure.com/","activeDirectoryGraphResourceId":"https://graph.windows.net/","sqlManagementEndpointUrl":"https://management.core.windows.net:8443/","galleryEndpointUrl":"https://gallery.azure.com/","managementEndpointUrl":"https://management.core.windows.net/"}Store the path to the file in an environment variable calledAZURE_AUTH_LOCATIONand make sure that your experiment doesNOTcontainsecretssection.SubscriptionAdditionally you need to provide the Azure subscription id.As an  environment variableAZURE_SUBSCRIPTION_IDSubscription id in the experiment file{"configuration":{"azure_subscription_id":"your-azure-subscription-id"}}Configuration may be as well retrieved from anenvironment.An old, but deprecated way of doing it was as follows, this still works
but should not be favoured over the previous approaches as it's not the
Chaos Toolkit way to pass structured configurations.{"configuration":{"azure":{"subscription_id":"your-azure-subscription-id"}}}Subscription id in the Azure credential fileCredential file described in the previous "Credential" section contains as well subscription id. IfAZURE_AUTH_LOCATIONis set and subscription id isNOTset in the experiment definition, extension will try to load it from the credential file.Putting it all togetherHere is a full example for an experiment containing secrets and configuration:{"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_subscription_id"]}}],"rollbacks":[]}ContributeIf 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
usualPEP 8code style, sprinkling with tests and submit a PR for
review.The Chaos Toolkit projects require all contributors must sign aDeveloper Certificate of Originon 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.DevelopIf you wish to develop on this project, make sure to install the development
dependencies. But first,create a virtual environmentand then install
those dependencies.$pipinstall-rrequirements-dev.txt-rrequirements.txtThen, point your environment to this directory:$pythonsetup.pydevelopNow, you can edit the files and they will be automatically be seen by your
environment, even when running from thechaoscommand locally.TestTo run the tests for the project execute the following:$ pytest