chaostoolkit-incubator / chaostoolkit-azure

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

Cannot run 'stress_vmss_instance_cpu' experiment - TypeError: __init__() missing 1 required positional argument: 'credential' error reported #127

Closed datcu closed 3 years ago

datcu commented 3 years ago

Hi,

Using chaostoolkit-azure 0.8.3 (latest version) I was trying to run _stress_vmss_instancecpu experiment. As this issue reported, I couldn't use 0.8.3 version as it is (I had to manually install msrestazure and lock azure-mgmt-resourcegraph to 2.0.0 version). My experiment file looks like below:

{
    "version": "1.0.0",
    "title": "cpu test",
    "description": "N/A",
    "tags": ["azure", "traffic manager", "app services"],
    "steady-state-hypothesis": {
        "title": "CPU OK",
        "probes": []
    },
    "method": [{
        "type": "action",
        "name": "Stress VMSS CPU",
        "provider": {
            "type": "python",
            "module": "chaosazure.vmss.actions",
            "func": "stress_cpu",
            "arguments": {
                "filter": "where resourceGroup=='${region_a_resource_group}' and name=='${region_a_app_service}'"
            },
            "secrets": [
                "azure"
            ],
            "config": [
                "azure_subscription_id"
            ]
        },
        "pauses": {
            "after": 20
        }
    }],
    "rollbacks": [],
    "configuration": {
        "azure_subscription_id": {
            "type": "env",
            "key": "AZURE_SUBSCRIPTION_ID"
        },
        "region_a_resource_group": {
            "type": "env",
            "key": "REGION_A_RESOURCE_GROUP"
        },
        "region_a_app_service": {
            "type": "env",
            "key": "REGION_A_APP_SERVICE"
        }
    },
    "secrets": {
        "azure": {
            "client_id": "xxx",
            "client_secret": "xxx",
            "tenant_id": "xxx"
        }
    }
}

When I'm trying to run it I get:

[2021-02-18 12:11:01 WARNING] [cloud:16] Azure cloud not provided. Using AZURE_PUBLIC_CLOUD as default
[2021-02-18 12:11:02 DEBUG] [fetcher:55] Fetched VMSS: ['aks-nodepool-xxx-vmss']
[2021-02-18 12:11:02 WARNING] [cloud:16] Azure cloud not provided. Using AZURE_PUBLIC_CLOUD as default
[2021-02-18 12:11:02 DEBUG] [activity:235] Activity failed
    Traceback (most recent call last):
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaoslib/provider/python.py", line 55, in run_python_activity
        return func(**arguments)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/vmss/actions.py", line 261, in stress_cpu
        configuration, secrets)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/vmss/fetcher.py", line 17, in fetch_instances
        scale_set, configuration, secrets)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/vmss/fetcher.py", line 87, in __random_instance_from
        scale_set, configuration, secrets)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/vmss/fetcher.py", line 65, in __fetch_vmss_instances
        client = init_client(secrets, configuration)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/__init__.py", line 48, in init_client
        base_url=base_url)
    TypeError: __init__() missing 1 required positional argument: 'credential'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaoslib/activity.py", line 228, in run_activity
        result = run_python_activity(activity, configuration, secrets)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaoslib/provider/python.py", line 60, in run_python_activity
        sys.exc_info()[2])
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaoslib/provider/python.py", line 55, in run_python_activity
        return func(**arguments)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/vmss/actions.py", line 261, in stress_cpu
        configuration, secrets)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/vmss/fetcher.py", line 17, in fetch_instances
        scale_set, configuration, secrets)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/vmss/fetcher.py", line 87, in __random_instance_from
        scale_set, configuration, secrets)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/vmss/fetcher.py", line 65, in __fetch_vmss_instances
        client = init_client(secrets, configuration)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/__init__.py", line 48, in init_client
        base_url=base_url)
    chaoslib.exceptions.ActivityFailed: TypeError: __init__() missing 1 required positional argument: 'credential'
[2021-02-18 12:11:02 ERROR] [activity:188]   => failed: TypeError: __init__() missing 1 required positional argument: 'credential'

Is it something wrong on my end or a product issue? Thanks.

Lawouach commented 3 years ago

fixed in 0.9.0

datcu commented 3 years ago

@Lawouach now with 0.9.0 (following the same initial scenario) it's not fetching VMSS anymore and I get:

[2021-03-16 14:58:19 DEBUG] [activity:235] Activity failed
    Traceback (most recent call last):
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaoslib/provider/python.py", line 55, in run_python_activity
        return func(**arguments)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/vmss/actions.py", line 257, in stress_cpu
        vmss = fetch_vmss(filter, configuration, secrets)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/vmss/fetcher.py", line 48, in fetch_vmss
        vmss = fetch_resources(filter, RES_TYPE_VMSS, secrets, configuration)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/common/resources/graph.py", line 22, in fetch_resources
        client = init_resource_graph_client(secrets)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/__init__.py", line 86, in init_resource_graph_client
        base_url=base_url)
    TypeError: __init__() got an unexpected keyword argument 'credential'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaoslib/activity.py", line 228, in run_activity
        result = run_python_activity(activity, configuration, secrets)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaoslib/provider/python.py", line 60, in run_python_activity
        sys.exc_info()[2])
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaoslib/provider/python.py", line 55, in run_python_activity
        return func(**arguments)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/vmss/actions.py", line 257, in stress_cpu
        vmss = fetch_vmss(filter, configuration, secrets)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/vmss/fetcher.py", line 48, in fetch_vmss
        vmss = fetch_resources(filter, RES_TYPE_VMSS, secrets, configuration)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/common/resources/graph.py", line 22, in fetch_resources
        client = init_resource_graph_client(secrets)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/__init__.py", line 86, in init_resource_graph_client
        base_url=base_url)
    chaoslib.exceptions.ActivityFailed: TypeError: __init__() got an unexpected keyword argument 'credential'
[2021-03-16 14:58:19 ERROR] [activity:188]   => failed: TypeError: __init__() got an unexpected keyword argument 'credential'

Can you please double check the fix?

Lawouach commented 3 years ago

I think you need to update the dependencies:

pip install -U azure-mgmt-resourcegraph msrestazure
datcu commented 3 years ago

@Lawouach that fixed the above problem, thanks. But I get into another one after that.

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaoslib/activity.py", line 228, in run_activity
        result = run_python_activity(activity, configuration, secrets)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaoslib/provider/python.py", line 60, in run_python_activity
        sys.exc_info()[2])
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaoslib/provider/python.py", line 55, in run_python_activity
        return func(**arguments)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/vmss/actions.py", line 257, in stress_cpu
        vmss = fetch_vmss(filter, configuration, secrets)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/vmss/fetcher.py", line 48, in fetch_vmss
        vmss = fetch_resources(filter, RES_TYPE_VMSS, secrets, configuration)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/chaosazure/common/resources/graph.py", line 23, in fetch_resources
        resources = client.resources(_query_request)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/azure/mgmt/resourcegraph/operations/_resource_graph_client_operations.py", line 68, in resources
        pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/azure/core/pipeline/_base.py", line 211, in run
        return first_node.send(pipeline_request)  # type: ignore
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/azure/core/pipeline/_base.py", line 71, in send
        response = self.next.send(request)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/azure/mgmt/core/policies/_base.py", line 47, in send
        response = self.next.send(request)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/azure/core/pipeline/_base.py", line 71, in send
        response = self.next.send(request)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/azure/core/pipeline/_base.py", line 71, in send
        response = self.next.send(request)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/azure/core/pipeline/_base.py", line 71, in send
        response = self.next.send(request)
      [Previous line repeated 1 more time]
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/azure/core/pipeline/policies/_redirect.py", line 158, in send
        response = self.next.send(request)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/azure/core/pipeline/policies/_retry.py", line 435, in send
        response = self.next.send(request)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/azure/core/pipeline/_base.py", line 69, in send
        _await_result(self._policy.on_request, request)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/azure/core/pipeline/_tools.py", line 29, in await_result
        result = func(*args, **kwargs)
      File "/home/developer/.venvs/chaos-toolkit/lib/python3.7/site-packages/azure/core/pipeline/policies/_authentication.py", line 93, in on_request
        self._token = self._credential.get_token(*self._scopes)
    chaoslib.exceptions.ActivityFailed: AttributeError: 'ServicePrincipalCredentials' object has no attribute 'get_token'
[2021-03-16 15:29:56 ERROR] [activity:188]   => failed: AttributeError: 'ServicePrincipalCredentials' object has no attribute 'get_token'

Is it something that I miss in my configuration?

Lawouach commented 3 years ago

Hard fort me to say sadly. I've never used Azure and this extension relies on its contributors.

But also, Azure needs to stop changing the Python packaging all the time... it's saddening.

devops-arch-cloud commented 3 years ago

I am also getting same error, any idea?

failed: AttributeError: 'ServicePrincipalCredentials' object has no attribute 'get_token'

devops-arch-cloud commented 3 years ago

@datcu were you able to fix this issue?

datcu commented 3 years ago

@devops-arch-cloud unfortunately I didn't fix it and I've abandoned the idea to use the tool for now. Looks like Azure keeps changing things and people involved in this project cannot keep up so maybe I will try to use it when is more stable...