Azure / azure-cli

Azure Command-Line Interface
MIT License
4.03k stars 3.01k forks source link

No module named 'azure.mgmt.authorization.v2020_04_01_preview' #26630

Open pichuang opened 1 year ago

pichuang commented 1 year ago

Describe the bug

The latest version of azure-cli is unable to execute commands such as 'az grafana create' correctly

Related command

az grafana create

Errors

$ az grafana create -g rg-poc1-aks -l EastUS --name grafana-poc2-aks Grafana instance of 'grafana-poc2-aks' was created. Now creating default role assignments for its managed identity, and current CLI account unless --principal-ids are provided The command failed with an unexpected error. Here is the traceback: No module named 'azure.mgmt.authorization.v2020_04_01_preview' Traceback (most recent call last): File "/usr/lib64/az/lib/python3.9/site-packages/knack/cli.py", line 233, in invoke cmd_result = self.invocation.execute(args) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 663, in execute raise ex File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 726, in _run_jobs_serially results.append(self._run_job(expanded_arg, cmd_copy)) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 697, in _run_job result = cmd_copy(params) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 333, in call return self.handler(*args, kwargs) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler return op(command_args) File "/mnt/c/Users/pinhuang/rhwsl-home/.azure/cliextensions/amg/azext_amg/custom.py", line 68, in create_grafana _create_role_assignment(cmd.cli_ctx, p, t, grafana_admin_role_id, resource.id) File "/mnt/c/Users/pinhuang/rhwsl-home/.azure/cliextensions/amg/azext_amg/custom.py", line 115, in _create_role_assignment assignments_client = get_mgmt_service_client(cli_ctx, ResourceType.MGMT_AUTHORIZATION, File "/usr/lib64/az/lib/python3.9/site-packages/azure/mgmt./authorization/_authorization_management_client.py", line 784, in role_assignments from .v2020_04_01_preview.operations import RoleAssignmentsOperations as OperationClass ModuleNotFoundError: No module named 'azure.mgmt.authorization.v2020_04_01_preview'

Issue script & Debug output

az_command_data_logger: command args: grafana create -g {} -l {} --name {} --debug
az_command_data_logger: extension name: amg
az_command_data_logger: extension version: 1.2.5
cli.azure.cli.core.sdk.policies:     'User-Agent': 'AZURECLI/2.49.0 (RPM) azsdk-python-mgmt.-dashboard/1.0.0b1 Python/3.9.13 (Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-with-glibc2.28)'

msal.application: Broker enabled? False
cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "/usr/lib64/az/lib/python3.9/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
    return self. Handler(*args, **kwargs)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
  File "/mnt/c/Users/pinhuang/rhwsl-home/.azure/cliextensions/amg/azext_amg/custom.py", line 68, in create_grafana
    _create_role_assignment(cmd.cli_ctx, p, t, grafana_admin_role_id, resource.id)
  File "/mnt/c/Users/pinhuang/rhwsl-home/.azure/cliextensions/amg/azext_amg/custom.py", line 115, in _create_role_assignment
    assignments_client = get_mgmt_service_client(cli_ctx, ResourceType.MGMT_AUTHORIZATION,
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/mgmt./authorization/_authorization_management_client.py", line 784, in role_assignments
    from .v2020_04_01_preview.operations import RoleAssignmentsOperations as OperationClass
ModuleNotFoundError: No module named 'azure.mgmt.authorization.v2020_04_01_preview'

cli.azure.cli.core.azclierror: The command failed with an unexpected error. Here is the traceback:
az_command_data_logger: The command failed with an unexpected error. Here is the traceback:
cli.azure.cli.core.azclierror: No module named 'azure.mgmt.authorization.v2020_04_01_preview'
Traceback (most recent call last):
  File "/usr/lib64/az/lib/python3.9/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
    results. Append(self._run_job(expanded_arg, cmd_copy))
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
    return self. Handler(*args, **kwargs)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
  File "/mnt/c/Users/pinhuang/rhwsl-home/.azure/cliextensions/amg/azext_amg/custom.py", line 68, in create_grafana
    _create_role_assignment(cmd.cli_ctx, p, t, grafana_admin_role_id, resource.id)
  File "/mnt/c/Users/pinhuang/rhwsl-home/.azure/cliextensions/amg/azext_amg/custom.py", line 115, in _create_role_assignment
    assignments_client = get_mgmt_service_client(cli_ctx, ResourceType.MGMT_AUTHORIZATION,
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/mgmt/authorization/_authorization_management_client.py", line 784, in role_assignments
    from .v2020_04_01_preview.operations import RoleAssignmentsOperations as OperationClass
ModuleNotFoundError: No module named 'azure.mgmt.authorization.v2020_04_01_preview'
az_command_data_logger: No module named 'azure.mgmt.authorization.v2020_04_01_preview'
Traceback (most recent call last):
  File "/usr/lib64/az/lib/python3.9/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
    return self. Handler(*args, **kwargs)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
  File "/mnt/c/Users/pinhuang/rhwsl-home/.azure/cliextensions/amg/azext_amg/custom.py", line 68, in create_grafana
    _create_role_assignment(cmd.cli_ctx, p, t, grafana_admin_role_id, resource.id)
  File "/mnt/c/Users/pinhuang/rhwsl-home/.azure/cliextensions/amg/azext_amg/custom.py", line 115, in _create_role_assignment
    assignments_client = get_mgmt_service_client(cli_ctx, ResourceType.MGMT_AUTHORIZATION,
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/mgmt./authorization/_authorization_management_client.py", line 784, in role_assignments
    from .v2020_04_01_preview.operations import RoleAssignmentsOperations as OperationClass
ModuleNotFoundError: No module named 'azure.mgmt.authorization.v2020_04_01_preview'
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x7f5b9bf5e8b0>]
az_command_data_logger: exit code: 1
cli.__main__: Command ran in 256.068 seconds (init: 0.180, invoke: 255.887)
telemetry.main: Begin splitting cli events and extra events, total events: 1
telemetry.client: Accumulated 0 events. Flush the clients.
telemetry.main: Finish splitting cli events and extra events, cli events: 1
telemetry.save: Save telemetry record of length 7436 in cache
telemetry.check: Returns Positive.
telemetry.main: Begin creating telemetry upload process.
telemetry.process: Creating upload process: "/usr/bin/python3.9 /usr/lib64/az/lib/python3.9/site-packages/azure/cli/telemetry/__init__.py /mnt/c/Users/pin Huang/rhwsl-home/.azure"
telemetry.process: Return from creating process
telemetry. Main: Finish creating telemetry upload process.
$ pip install azure-mgmt-authorization
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: azure-mgmt-authorization in /mnt/c/Users/pinhuang/rhwsl-home/.local/lib/python3.6/site-packages (0.51.1)
Requirement already satisfied: msrestazure<2.0.0,>=0.4.32 in /mnt/c/Users/pinhuang/rhwsl-home/.local/lib/python3.6/site-packages (from azure-mgmt-authorization) (0.6.4)
Requirement already satisfied: azure-common~=1.1 in /mnt/c/Users/pinhuang/rhwsl-home/.local/lib/python3.6/site-packages (from azure-mgmt-authorization) (1.1.24)
Requirement already satisfied: msrest>=0.5.0 in /mnt/c/Users/pinhuang/rhwsl-home/.local/lib/python3.6/site-packages (from azure-mgmt-authorization) (0.6.21)
Requirement already satisfied: isodate>=0.6.0 in /mnt/c/Users/pinhuang/rhwsl-home/.local/lib/python3.6/site-packages (from msrest>=0.5.0->azure-mgmt-authorization) (0.6.1)
Requirement already satisfied: requests-oauthlib>=0.5.0 in /mnt/c/Users/pinhuang/rhwsl-home/.local/lib/python3.6/site-packages (from msrest>=0.5.0->azure-mgmt-authorization) (1.3.1)
Requirement already satisfied: certifi>=2017.4.17 in /mnt/c/Users/pinhuang/rhwsl-home/.local/lib/python3.6/site-packages (from msrest>=0.5.0->azure-mgmt-authorization) (2022.9.14)
Requirement already satisfied: requests~=2.16 in /usr/lib/python3.6/site-packages (from msrest>=0.5.0->azure-mgmt-authorization) (2.20.0)
Requirement already satisfied: adal<2.0.0,>=0.6.0 in /mnt/c/Users/pinhuang/rhwsl-home/.local/lib/python3.6/site-packages (from msrestazure<2.0.0,>=0.4.32->azure-mgmt-authorization) (1.2.7)
Requirement already satisfied: six in /mnt/c/Users/pinhuang/rhwsl-home/.local/lib/python3.6/site-packages (from msrestazure<2.0.0,>=0.4.32->azure-mgmt-authorization) (1.16.0)
Requirement already satisfied: python-dateutil<3,>=2.1.0 in /mnt/c/Users/pinhuang/rhwsl-home/.local/lib/python3.6/site-packages (from adal<2.0.0,>=0.6.0->msrestazure<2.0.0,>=0.4.32->azure-mgmt-authorization) (2.8.2)
Requirement already satisfied: cryptography>=1.1.0 in /usr/local/lib64/python3.6/site-packages (from adal<2.0.0,>=0.6.0->msrestazure<2.0.0,>=0.4.32->azure-mgmt-authorization) (38.0.1)
Requirement already satisfied: PyJWT<3,>=1.0.0 in /mnt/c/Users/pinhuang/rhwsl-home/.local/lib/python3.6/site-packages (from adal<2.0.0,>=0.6.0->msrestazure<2.0.0,>=0.4.32->azure-mgmt-authorization) (2.4.0)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/lib/python3.6/site-packages (from requests~=2.16->msrest>=0.5.0->azure-mgmt-authorization) (3.0.4)
Requirement already satisfied: idna<2.8,>=2.5 in /usr/lib/python3.6/site-packages (from requests~=2.16->msrest>=0.5.0->azure-mgmt-authorization) (2.5)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/lib/python3.6/site-packages (from requests~=2.16->msrest>=0.5.0->azure-mgmt-authorization) (1.24.2)
Requirement already satisfied: oauthlib>=3.0.0 in /mnt/c/Users/pinhuang/rhwsl-home/.local/lib/python3.6/site-packages (from requests-oauthlib>=0.5.0->msrest>=0.5.0->azure-mgmt-authorization) (3.2.1)
Requirement already satisfied: cffi>=1.12 in /mnt/c/Users/pinhuang/rhwsl-home/.local/lib/python3.6/site-packages (from cryptography>=1.1.0->adal<2.0.0,>=0.6.0->msrestazure<2.0.0,>=0.4.32->azure-mgmt-authorization) (1.15.1)
Requirement already satisfied: pycparser in /usr/lib/python3.6/site-packages (from cffi>=1.12->cryptography>=1.1.0->adal<2.0.0,>=0.6.0->msrestazure<2.0.0,>=0.4.32->azure-mgmt-authorization) (2.14)
$ pip install azure-mgmt-authorization==3.0.0
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement azure-mgmt-authorization==3.0.0 (from versions: 0.30.0a1, 0.30.0rc1, 0.30.0rc2, 0.30.0rc3, 0.30.0rc4, 0.30.0rc5, 0.30.0rc6, 0.30.0, 0.40.0, 0.50.0, 0.51.0, 0.51.1, 0.52.0, 0.60.0, 0.61.0, 1.0.0b1, 1.0.0, 2.0.0)
ERROR: No matching distribution found for azure-mgmt-authorization==3.0.0

Expected behavior

No error messages are being displayed.

Environment Summary

$ az --version azure-cli 2.49.0

core 2.49.0 telemetry 1.0.8

Extensions: aks-preview 0.5.141 amg 1.2.5 arcdata 1.5.0 azure-firewall 0.14.7 bastion 0.2.4 connectedk8s 1.3.20 customlocation 0.1.3 k8s-configuration 1.7.0 k8s-extension 1.4.1 ssh 1.1.6 virtual-wan 0.2.17

Dependencies: msal 1.20.0 azure-mgmt-resource 22.0.0

Python location '/usr/bin/python3.9' Extensions directory '/mnt/c/Users/pinhuang/rhwsl-home/.azure/cliextensions'

Python (Linux) 3.9.13 (main, Nov 9 2022, 13:16:24) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15)]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

Additional context

No response

yonzhan commented 1 year ago

Thank you for opening this issue, we will look into it.

ghost commented 1 year ago

Thank you for your feedback. This has been routed to the support team for assistance.

navba-MSFT commented 1 year ago

non-customer reported issue. Adding Service team to look into this.

pichuang commented 1 year ago

Miss v2020_04_01_preview

12:17:53 pinhuang@rhel8 1 /usr/lib64/az/lib/python3.9/site-packages/azure/mgmt./authorization
$ ls
_authorization_management_client.py  models.py    _serialization.py  v2018_01_01_preview  v2021_01_01_preview  _version.py
_configuration.py                    __pycache__  v2015_06_01        v2019_08_01_preview  v2021_12_01_preview
__init__.py                          py.typed     v2015_07_01        v2020_10_01          v2022_04_01

and will break in here

samaea commented 1 year ago

+1 facing the same issue when running az grafana create --name X --resource-group Y. Used to work before.

pauldotyu commented 1 year ago

Also ran into this error. Just wanted to note that the error doesn't affect the creation of the Azure Managed Grafana instance. It was created, but I just needed to add RBAC manually.

pichuang commented 1 year ago

Hi @yonzhan Is it possible to assign someone to take a look? Even through I know it's not an issue of a critical feature being broken, it's an issue of user experience.

yonzhan commented 1 year ago

@yugangw-msft do you know who can help with this?

pichuang commented 1 year ago

Workaround with manual join permission before fixing the issue

  1. Click "Azure Managed Grafana"
  2. Click "Access control (IAM)"
  3. Click "Add role assignment"
  4. Select "Job function role: Grafana Admin" and Next
  5. Click "+Select members" and choose your user account
  6. Click "Review + assign"
  7. Wait 3 mins for the role to be assigned
  8. Login Grafana dashboard
image
pauldotyu commented 1 year ago

Just tested this again using azure-cli version 2.50.0 and it does not seem to be an issue anymore.

pichuang commented 1 year ago

Still have the same issue.

Line 85: az grafana create -g rg-poc-aks -l EastUS --name grafana-poc-aks
Grafana instance of 'grafana-poc-aks' was created. Now creating default role assignments for its managed identity, and current CLI account unless --principal-ids are provided
The command failed with an unexpected error. Here is the traceback:
No module named 'azure.mgmt.authorization.v2020_04_01_preview'
Traceback (most recent call last):
  File "/usr/lib64/az/lib/python3.9/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
    return self.handler(*args, **kwargs)
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
  File "/mnt/c/Users/pinhuang/rhwsl-home/.azure/cliextensions/amg/azext_amg/custom.py", line 68, in create_grafana
    _create_role_assignment(cmd.cli_ctx, p, t, grafana_admin_role_id, resource.id)
  File "/mnt/c/Users/pinhuang/rhwsl-home/.azure/cliextensions/amg/azext_amg/custom.py", line 115, in _create_role_assignment
    assignments_client = get_mgmt_service_client(cli_ctx, ResourceType.MGMT_AUTHORIZATION,
  File "/usr/lib64/az/lib/python3.9/site-packages/azure/mgmt/authorization/_authorization_management_client.py", line 784, in role_assignments
    from .v2020_04_01_preview.operations import RoleAssignmentsOperations as OperationClass
ModuleNotFoundError: No module named 'azure.mgmt.authorization.v2020_04_01_preview'
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues

real    3m14.864s
user    0m0.674s
sys     0m0.318s
$ az version
{
  "azure-cli": "2.50.0",
  "azure-cli-core": "2.50.0",
  "azure-cli-telemetry": "1.0.8",
  "extensions": {
    "aks-preview": "0.5.149",
    "amg": "1.2.7",
    "arcdata": "1.5.3",
    "azure-firewall": "0.14.8",
    "bastion": "0.2.5",
    "connectedk8s": "1.3.20",
    "customlocation": "0.1.3",
    "k8s-configuration": "1.7.0",
    "k8s-extension": "1.4.2",
    "ssh": "2.0.0",
    "virtual-wan": "0.2.17"
  }
}
neaggarwMS commented 1 year ago

still seeing issue in version 2.51.0

image

ramanjk commented 1 year ago

same issue even in version 2.53

sabbour commented 1 year ago

A workaround is to pass --skip-role-assignments but I'd rather know why it is broken and have someone fix it.

ABZhang0 commented 1 year ago

This issue has been fixed in the latest version of the cli extension: 1.2.8

dragonlipz commented 1 year ago

I can confirm that this no longer throws an error in the latest version

$ az version
{
  "azure-cli": "2.53.1",
  "azure-cli-core": "2.53.1",
  "azure-cli-telemetry": "1.1.0",
  "extensions": {
    "account": "0.2.5",
    "aks-preview": "0.5.168",
    "amg": "1.2.9",
    "k8s-configuration": "1.7.0",
    "k8s-extension": "1.5.1"
  }
}