Azure / azure-cli

Azure Command-Line Interface
MIT License
3.95k stars 2.93k forks source link

[Backup] Supplying non-existent name or natively formatted name for container causes stack trace #4502

Open tjprescott opened 6 years ago

tjprescott commented 6 years ago

Trying to run: az backup protection backup-now -g tjp-ig -v vault1 --retain-until 01-01-2020 -c container1 -i item1

Yields:

'list' object has no attribute 'name'
Traceback (most recent call last):
  File "/opt/az/lib/python3.6/site-packages/azure/cli/main.py", line 36, in main
    cmd_result = APPLICATION.execute(args)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/application.py", line 212, in execute
    result = expanded_arg.func(params)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 377, in __call__
    return self.handler(*args, **kwargs)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 626, in _execute_command
    reraise(*sys.exc_info())
  File "/opt/az/lib/python3.6/site-packages/six.py", line 693, in reraise
    raise value
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 603, in _execute_command
    result = op(client, **kwargs) if client else op(**kwargs)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/backup/custom.py", line 198, in backup_now
    container_type, item_type)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/backup/custom.py", line 145, in show_item
    items = list_items(client, resource_group_name, vault_name, container_name, container_type, item_type)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/backup/custom.py", line 159, in list_items
    return [item for item in paged_items if item.properties.container_name.lower() in container.name.lower()]
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/backup/custom.py", line 159, in <listcomp>
    return [item for item in paged_items if item.properties.container_name.lower() in container.name.lower()]
AttributeError: 'list' object has no attribute 'name'

In this case, it was not clear to me that a container and item had been created by the enable-for-vm command, so I assumed that these names were the names that would be created. When I realized it expected an existing name, I tried the container name obtained by running the backup container list command. However this yields the same stack trace. This AttributeError should be caught and handled gracefully. Additionally, it is perfectly fine to use a shorthand notation (like the VM name in this case) but:

  1. It should be clearly documented in help
  2. The parameter should definitely accept the format of name that the container object actually uses.

Environment summary

Install Method: How did you install the CLI? (e.g. pip, interactive script, apt-get, Docker, MSI, nightly)
Answer here: WGET

CLI Version: What version of the CLI and modules are installed? (Use az --version)
Answer here: azure-cli (2.0.17+dev)

acr (2.0.11+dev) acs (2.0.15+dev) appservice (0.1.16+dev) backup (1.0.0+dev) batch (3.1.3+dev) billing (0.1.4+dev) cdn (0.0.8+dev) cloud (2.0.7+dev) cognitiveservices (0.1.7+dev) command-modules-nspkg (2.0.1+dev) component (2.0.7+dev) configure (2.0.10+dev) consumption (0.1.4+dev) container (0.1.10+dev) core (2.0.16+dev) cosmosdb (0.1.12+dev) dla (0.0.11+dev) dls (0.0.13+dev) eventgrid (0.1.3+dev) extension (0.0.2+dev) feedback (2.0.6+dev) find (0.2.6+dev) interactive (0.3.9+dev) iot (0.1.11+dev) keyvault (2.0.10+dev) lab (0.0.10+dev) monitor (0.0.9+dev) network (2.0.14+dev) nspkg (3.0.1+dev) profile (2.0.12+dev) rdbms (0.0.6+dev) redis (0.2.8+dev) resource (2.0.14+dev) role (2.0.11+dev) servicefabric (0.0.3+dev) sql (2.0.11+dev) storage (2.0.15+dev) vm (2.0.14+dev)

OS Version: What OS and version are you using?
Answer here: WSL

Shell Type: What shell are you using? (e.g. bash, cmd.exe, Bash on Windows)
Answer here: Bash on Windows

tjprescott commented 6 years ago

The was only partially fixed by PR #5011.

nemo-xue commented 6 years ago

Same error exists in azure-cli (2.0.29)

Trying to run: az backup protection backup-now -g yg391 -v vaultName --container-name node0 --item-name node0 --retain-until 18-04-2018

Error message: 'list' object has no attribute 'name' Traceback (most recent call last): File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 194, in invoke cmd_result = self.invocation.execute(args) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 347, in execute six.reraise(sys.exc_info()) File "/opt/az/lib/python3.6/site-packages/six.py", line 693, in reraise raise value File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 319, in execute result = cmd(params) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 180, in call return super(AzCliCommand, self).call(args, *kwargs) File "/opt/az/lib/python3.6/site-packages/knack/commands.py", line 109, in call return self.handler(args, kwargs) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/init.py", line 418, in default_command_handler result = op(command_args) File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/backup/custom.py", line 238, in backup_now item_name, container_type, item_type) File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/backup/custom.py", line 179, in show_item items = list_items(cmd, client, resource_group_name, vault_name, container_name, container_type, item_type) File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/backup/custom.py", line 197, in list_items return [item for item in paged_items if item.properties.container_name.lower() in container.name.lower()] File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/backup/custom.py", line 197, in return [item for item in paged_items if item.properties.container_name.lower() in container.name.lower()] AttributeError: 'list' object has no attribute 'name'

Environment: azure-cli (2.0.29)

acr (2.0.22) acs (2.0.28) advisor (0.5.0) appservice (0.1.29) backup (1.0.7) batch (3.1.11) batchai (0.1.6) billing (0.1.7) cdn (0.0.13) cloud (2.0.12) cognitiveservices (0.1.11) command-modules-nspkg (2.0.1) configure (2.0.14) consumption (0.2.2) container (0.1.19) core (2.0.29) cosmosdb (0.1.19) dla (0.0.18) dls (0.0.19) eventgrid (0.1.11) eventhubs (0.1.0) extension (0.0.10) feedback (2.1.0) find (0.2.8) interactive (0.3.17) iot (0.1.18) keyvault (2.0.20) lab (0.0.17) monitor (0.1.3) network (2.0.25) nspkg (3.0.2) profile (2.0.20) rdbms (0.1.0) redis (0.2.11) reservations (0.1.1) resource (2.0.25) role (2.0.20) servicebus (0.1.0) servicefabric (0.0.11) sql (2.0.23) storage (2.0.27) vm (2.0.28)

Python location '/opt/az/bin/python3' Extensions directory '/home/yg/.azure/cliextensions'

Python (Linux) 3.6.1 (default, Mar 10 2018, 01:18:09) [GCC 5.4.0 20160609]

I'm running it on azure cloud shell.

andrewdobbie commented 6 years ago

I think the CLI is breaking because of the Azure REST API. https://management.azure.com/Subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/${vaultName}/backupProtectionContainers?api-version=2017-07-01&$filter=backupManagementType eq 'AzureIaasVM' and status eq 'Registered' and friendlyName eq 'myVM' When I call backupProtectionContainers API as above, I get a list instead of the single expected container. It's returning containers from multiple resource groups in the subscription where the containers have the same friendlyName. The CLI will always break when the REST API does not filter using resourceGroupName and vaultName.

dragonfly91 commented 6 years ago

@yg-xue can you please try with the latest version of backup (1.1.0)?

nemo-xue commented 6 years ago

@dragonfly91 How to get backup (1.1.0) installed? I tried to do edge build, but the backup component is still 1.0.7. Command I used for edge build: $ pip install --upgrade --pre azure-cli --extra-index-url https://azurecliprod.blob.core.windows.net/edge --no-cache-dir

dragonfly91 commented 6 years ago

Looks like the change is not yet released. Please follow https://github.com/Azure/azure-cli/milestone/36 for the dates

nemo-xue commented 6 years ago

Hi Samuel,

My --container--name and --item-name are my virtual machine name.

Best regards,

Yougen.Xue

On Fri, Mar 23, 2018 at 6:38 AM, Samuel Anudeep notifications@github.com wrote:

@yg-xue https://github.com/yg-xue can you specify what are the values of the parameters: --container-name and --item-name?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Azure/azure-cli/issues/4502#issuecomment-375618394, or mute the thread https://github.com/notifications/unsubscribe-auth/ARNN_TQwZUZBNwKdRSb9cKOhZ090TLrrks5thNCegaJpZM4PeXcn .

pvrk commented 5 years ago

@siddharth7 : can you please check if the bug is fixed in the latest release?