chaostoolkit-incubator / chaostoolkit-azure

Chaos Toolkit Extension for Azure
https://chaostoolkit.org/
Apache License 2.0
22 stars 28 forks source link

Fix #136 #140

Closed xpdable closed 2 years ago

xpdable commented 2 years ago

Client of azure sdk require and hiden (I do not know why MS doing this way) parameter of credential_scopes while is used to init corresponding ClientConfiguration for multiple region/cloud configuration, e.g. China Cloud Adding this scope parameter.

xpdable commented 2 years ago

@Lawouach I see this is a minimal change to proper use confirmed with MS. I will test this extension in my Azure for UAT

xpdable commented 2 years ago
{
    "title": "Stop VM",
    "description": "Stop VM in Azure",
    "method": [
        {
            "type": "action",
            "name": "stop-vm",
            "provider": {
                "type": "python",
                "module": "chaosazure.machine.actions",
                "func": "stop_machines",
                "arguments": {
                    "filter": "where tolower(resourceGroup) == 'iapimcninfresgp004' and name == 'IAPIMCNINFVMSA004'"
                },
                "secrets": ["azure"],
                "configuration": ["azure"]
            }
        }
    ],
    "secrets": {
        "azure": {
                "client_id": "ssss",
                "client_secret": "sss",
                "tenant_id": "xx",
                "azure_cloud": "AZURE_CHINA_CLOUD"
        }
    },
    "configuration": {
        "azure": {
          "subscription_id": ""
        },
        "environment": "azure"
    }
}
cat OneAPI.log
[2022-07-14 10:44:33 DEBUG] [cli:112] ###############################################################################
[2022-07-14 10:44:33 DEBUG] [cli:113] Running command 'run'
[2022-07-14 10:44:33 DEBUG] [cli:117] Using settings file '/Users/xp/.chaostoolkit/settings.yaml'
[2022-07-14 10:44:33 DEBUG] [settings:30] The Chaos Toolkit settings file could not be found at '/Users/xp/.chaostoolkit/settings.yaml'.
[2022-07-14 10:44:33 DEBUG] [__init__:399] No controls to apply on 'loader'
[2022-07-14 10:44:33 DEBUG] [__init__:399] No controls to apply on 'loader'
[2022-07-14 10:44:33 DEBUG] [caching:24] Building activity cache...
[2022-07-14 10:44:33 DEBUG] [caching:35] Cached 1 activities
[2022-07-14 10:44:33 INFO] [experiment:58] Validating the experiment's syntax
[2022-07-14 10:44:33 DEBUG] [configuration:63] Loading configuration...
[2022-07-14 10:44:33 DEBUG] [secret:78] Loading secrets...
[2022-07-14 10:44:33 DEBUG] [secret:78] Loading secrets...
[2022-07-14 10:44:33 DEBUG] [secret:104] Done loading secrets
[2022-07-14 10:44:33 DEBUG] [secret:104] Done loading secrets
[2022-07-14 10:44:33 INFO] [experiment:109] Experiment looks valid
[2022-07-14 10:44:33 DEBUG] [caching:42] Clearing activities cache
[2022-07-14 10:44:33 DEBUG] [caching:24] Building activity cache...
[2022-07-14 10:44:33 DEBUG] [caching:35] Cached 1 activities
[2022-07-14 10:44:33 DEBUG] [configuration:63] Loading configuration...
[2022-07-14 10:44:33 DEBUG] [secret:78] Loading secrets...
[2022-07-14 10:44:33 DEBUG] [secret:78] Loading secrets...
[2022-07-14 10:44:33 DEBUG] [secret:104] Done loading secrets
[2022-07-14 10:44:33 DEBUG] [secret:104] Done loading secrets
[2022-07-14 10:44:33 DEBUG] [configuration:160] Loading dynamic configuration...
[2022-07-14 10:44:33 INFO] [run:320] Running experiment: Stop VM
[2022-07-14 10:44:33 DEBUG] [__init__:52] Initializing controls
[2022-07-14 10:44:33 INFO] [run:344] Steady-state strategy: default
[2022-07-14 10:44:33 INFO] [run:348] Rollbacks strategy: default
[2022-07-14 10:44:33 INFO] [run:353] No steady state hypothesis defined. That's ok, just exploring.
[2022-07-14 10:44:33 DEBUG] [__init__:399] No controls to apply on 'experiment'
[2022-07-14 10:44:33 INFO] [run:607] Playing your experiment's method now...
[2022-07-14 10:44:33 DEBUG] [__init__:399] No controls to apply on 'method'
[2022-07-14 10:44:33 DEBUG] [__init__:399] No controls to apply on 'activity'
[2022-07-14 10:44:33 INFO] [activity:204] Action: stop-vm
[2022-07-14 10:44:33 DEBUG] [python:33] Activity 'stop-vm' loaded from '/usr/local/lib/python3.9/site-packages/chaosazure/machine/actions.py'
[2022-07-14 10:44:33 DEBUG] [actions:92] Start stop_machines: configuration='{'azure': {'subscription_id': 'ed886107-0f48-4043-835a-2394a94f21a8'}, 'environment': 'azure'}', filter='where tolower(resourceGroup) == 'iapimcninfresgp004' and name == 'IAPIMCNINFVMSA004''
[2022-07-14 10:44:35 DEBUG] [actions:517] Fetched virtual machines: ['IAPIMCNINFVMSA004']
[2022-07-14 10:44:35 DEBUG] [actions:103] Stopping machine: IAPIMCNINFVMSA004
[2022-07-14 10:44:37 DEBUG] [activity:221]   => succeeded with '{'resources': [{'id': '/subscriptions/ed886107-0f48-4043-835a-2394a94f21a8/resourceGroups/iapimcninfresgp004/providers/Microsoft.Compute/virtualMachines/IAPIMCNINFVMSA004', 'name': 'IAPIMCNINFVMSA004', 'type': 'microsoft.compute/virtualmachines', 'tenantId': 'fc5dd6f5-ca13-4bcb-840d-d3c1638f63b1', 'kind': '', 'location': 'chinanorth2', 'resourceGroup': 'iapimcninfresgp004', 'subscriptionId': 'ed886107-0f48-4043-835a-2394a94f21a8', 'managedBy': '', 'sku': None, 'plan': None, 'tags': {'environment': 'Int', 'project': 'OneAPI', 'devopsplatform': '1'}, 'identity': {'principalId': 'adcdc887-0f49-4f85-b145-b6cf77fe13ab', 'tenantId': 'fc5dd6f5-ca13-4bcb-840d-d3c1638f63b1', 'type': 'SystemAssigned'}, 'zones': None, 'extendedLocation': None, 'performed_at': 1657766677}]}'
[2022-07-14 10:44:37 DEBUG] [__init__:399] No controls to apply on 'activity'
[2022-07-14 10:44:37 DEBUG] [__init__:399] No controls to apply on 'method'
[2022-07-14 10:44:37 INFO] [run:893] Let's rollback...
[2022-07-14 10:44:37 DEBUG] [__init__:399] No controls to apply on 'rollback'
[2022-07-14 10:44:37 INFO] [rollback:27] No declared rollbacks, let's move on.
[2022-07-14 10:44:37 DEBUG] [__init__:399] No controls to apply on 'rollback'
[2022-07-14 10:44:37 INFO] [run:458] Experiment ended with status: completed
[2022-07-14 10:44:37 DEBUG] [__init__:399] No controls to apply on 'experiment'
[2022-07-14 10:44:37 DEBUG] [__init__:91] Cleaning up controls
[2022-07-14 10:44:37 DEBUG] [caching:42] Clearing activities cache
Lawouach commented 2 years ago

LGTM @xpdable

But is that a change that will impact other regions, outside of China. Or is it the same everywhere?