Azure / azure-cli

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

Script only works with destination storage account #29727

Open harrchen88 opened 3 months ago

harrchen88 commented 3 months ago

Describe the bug

Tried to create an OR policy using policy json file, following the command reference from https://learn.microsoft.com/en-us/cli/azure/storage/account/or-policy?view=azure-cli-latest#az-storage-account-or-policy-create.

The command works if the parameter "account-name" is give the destination account name. But it fails if given the source account name.

This is the working command: az storage account or-policy create -g rgor -n saortarget20240816 --policy @or.json

This is the failing command: az storage account or-policy create -g rgor -n saorsource20240816 --policy @or.json

The or.json file has this content: { "policyId": "default", "sourceAccount": "/subscriptions/6fa6267c-594e-452d-b328-96de21592df9/resourceGroups/rgor/providers/Microsoft.Storage/storageAccounts/saorsource20240816", "destinationAccount": "/subscriptions/6fa6267c-594e-452d-b328-96de21592df9/resourceGroups/rgor/providers/Microsoft.Storage/storageAccounts/saortarget2024081 6", "rules": [ {
"sourceContainer": "sourceor1", "destinationContainer": "targetor1", "filters": { "minCreationTime": "1601-01-01T00:00:00Z", "prefixMatch": null } }, { "destinationContainer": "targetor2", "filters": null, "sourceContainer": "sourceor2" } ] }

Related command

az storage account or-policy create -g rgor -n saorsource20240816 --policy @or.json

Errors

'dict' object has no attribute 'source_account'

Issue script & Debug output

harry [ ~/or ]$ az storage account or-policy create -g rgor -n saorsource20240816 --policy @or.json Command group 'storage account or-policy' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus The command failed with an unexpected error. Here is the traceback: 'dict' object has no attribute 'source_account' Traceback (most recent call last): File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/command_modules/storage/operations/account.py", line 992, in create_or_policy return client.create_or_update(resource_group_name=resource_group_name, account_name=account_name, File "/usr/lib64/az/lib/python3.9/site-packages/azure/core/tracing/decorator.py", line 76, in wrapper_use_tracer return func(*args, **kwargs) File "/usr/lib64/az/lib/python3.9/site-packages/azure/mgmt/storage/v2023_05_01/operations/_object_replication_policies_operations.py", line 523, in create_or_update raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) azure.core.exceptions.HttpResponseError: (InvalidRequestPropertyValue) The value 'default' is not allowed for property policyId. Code: InvalidRequestPropertyValue Message: The value 'default' is not allowed for property policyId.

During handling of the above exception, another exception occurred:

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 664, in execute raise ex File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 731, 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 701, in _run_job result = cmd_copy(params) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 334, 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 "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/command_modules/storage/operations/account.py", line 997, in create_or_policy if account_name == parse_resource_id(or_policy.source_account)['name']: AttributeError: 'dict' object has no attribute 'source_account' To check existing issues, please visit: https://github.com/Azure/azure-cli/issues

Expected behavior

Policy should be created with the specified storage account. It should work with "account-name" is either source storage account or destination account name.

Environment Summary

azure-cli 2.63.0

core 2.63.0 telemetry 1.1.0

Extensions: ai-examples 0.2.5 datafactory 1.0.2 ml 2.28.0 ssh 2.0.5

Dependencies: msal 1.30.0 azure-mgmt-resource 23.1.1

Python location '/usr/bin/python3.9' Extensions directory '/home/harry/.azure/cliextensions' Extensions system directory '/usr/lib/python3.9/site-packages/azure-cli-extensions'

Python (Linux) 3.9.19 (main, Jul 31 2024, 03:47:41) [GCC 11.2.0]

Legal docs and information: aka.ms/AzureCliLegal

Additional context

No response

yonzhan commented 3 months ago

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

github-actions[bot] commented 3 months ago

Here are some similar issues that might help you. Please check if they can solve your problem.