Azure / azure-cli-extensions

Public Repository for Extensions of Azure CLI.
https://docs.microsoft.com/en-us/cli/azure
MIT License
382 stars 1.23k forks source link

azext_storage_preview: Narsty AttributeError when applied to GPv1 account #438

Closed rgiese closed 5 years ago

rgiese commented 5 years ago

azext_storage_preview

Running az storage blob service-properties update --account-name ... --static-website on a storage account that's GPv1 (i.e. doesn't support static sites) should report a useful error (e.g. "Not supported on GPv1 accounts, GPv2 required.") but instead bails with:

'ServiceProperties' object has no attribute 'static_website' Traceback (most recent call last): File "/usr/local/Cellar/azure-cli/2.0.51/libexec/lib/python3.7/site-packages/knack/cli.py", line 197, in invoke cmd_result = self.invocation.execute(args) File "/usr/local/Cellar/azure-cli/2.0.51/libexec/lib/python3.7/site-packages/azure/cli/core/commands/init.py", line 342, in execute cmd.exception_handler(ex) File "/Users/robin/.azure/cliextensions/storage-preview/azext_storage_preview/init.py", line 243, in new_handler handler(ex) File "/Users/robin/.azure/cliextensions/storage-preview/azext_storage_preview/init.py", line 190, in handler raise ex File "/usr/local/Cellar/azure-cli/2.0.51/libexec/lib/python3.7/site-packages/azure/cli/core/commands/init.py", line 319, in execute result = cmd(params) File "/usr/local/Cellar/azure-cli/2.0.51/libexec/lib/python3.7/site-packages/azure/cli/core/commands/init.py", line 169, in call return self.handler(*args, kwargs) File "/usr/local/Cellar/azure-cli/2.0.51/libexec/lib/python3.7/site-packages/azure/cli/core/commands/arm.py", line 512, in handler result = setter(setterargs) File "/Users/robin/.azure/cliextensions/storage-preview/azext_storage_preview/operations/blob.py", line 21, in set_service_properties kwargs['static_website'] = parameters.static_website AttributeError: 'ServiceProperties' object has no attribute 'static_website'

Chasing this down is, uh, let's just call it frustrating.

arichiardi commented 5 years ago

I have run into this as well so is it because it was not created with V2? :man_facepalming:

arichiardi commented 5 years ago

I actually checked mine and it is indeed a StorageV2 (general purpose v2). There seems to be another kind of bug.

We are using the extension version 0.1.17.

2018-12-08T01:31:10.4630267Z + az storage blob service-properties update --account-name laputapromotions --static-website true --404-document error.html --index-document index.html
2018-12-08T01:31:11.4735404Z ERROR: 'ServiceProperties' object has no attribute 'static_website'
2018-12-08T01:31:11.4735736Z Traceback (most recent call last):
2018-12-08T01:31:11.4736093Z   File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 197, in invoke
2018-12-08T01:31:11.4736254Z     cmd_result = self.invocation.execute(args)
2018-12-08T01:31:11.4736600Z   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 342, in execute
2018-12-08T01:31:11.4736733Z     cmd.exception_handler(ex)
2018-12-08T01:31:11.4737067Z   File "/home/vsts/.azure/cliextensions/storage-preview/azext_storage_preview/__init__.py", line 243, in new_handler
2018-12-08T01:31:11.4737200Z     handler(ex)
2018-12-08T01:31:11.4737510Z   File "/home/vsts/.azure/cliextensions/storage-preview/azext_storage_preview/__init__.py", line 190, in handler
2018-12-08T01:31:11.4737627Z     raise ex
2018-12-08T01:31:11.4738034Z   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 319, in execute
2018-12-08T01:31:11.4738141Z     result = cmd(params)
2018-12-08T01:31:11.4738423Z   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 169, in __call__
2018-12-08T01:31:11.4738530Z     return self.handler(*args, **kwargs)
2018-12-08T01:31:11.4739068Z   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/arm.py", line 512, in handler
2018-12-08T01:31:11.4739183Z     result = setter(**setterargs)
2018-12-08T01:31:11.4739501Z   File "/home/vsts/.azure/cliextensions/storage-preview/azext_storage_preview/operations/blob.py", line 21, in set_service_properties
2018-12-08T01:31:11.4739938Z     kwargs['static_website'] = parameters.static_website
2018-12-08T01:31:11.4740207Z AttributeError: 'ServiceProperties' object has no attribute 'static_website'

I see "kind": "StorageV2", in the output of other commands as well.

What can it be?

rgiese commented 5 years ago

In my case it was because I had Terraformed the storage account which defaults to v1.

arichiardi commented 5 years ago

Is there any workaround we can employ on this one? I see it also with the current 0.2.0 version:

We are running from a Azure DevOps CI machine:

2018-12-17T22:35:20.3917475Z azure-cli (2.0.50)
2018-12-17T22:35:20.3917647Z 
2018-12-17T22:35:20.3917769Z acr (2.1.8)
2018-12-17T22:35:20.3917821Z acs (2.3.11)
2018-12-17T22:35:20.3917915Z advisor (2.0.0)
2018-12-17T22:35:20.3917966Z ams (0.3.0)
2018-12-17T22:35:20.3918016Z appservice (0.2.6)
…2018-12-17T22:35:20.3922697Z storage-preview (0.2.0)
2018-12-17T22:35:20.3922731Z 
2018-12-17T22:35:20.3922923Z Python location '/opt/az/bin/python3'
2018-12-17T22:35:20.3923187Z Extensions directory '/home/vsts/.azure/cliextensions'
2018-12-17T22:35:20.3923223Z 
2018-12-17T22:35:20.3923268Z Python (Linux) 3.6.5 (default, Nov  1 2018, 22:27:27) 
2018-12-17T22:35:20.3923354Z [GCC 5.4.0 20160609]
2018-12-17T22:35:20.3923383Z 
2018-12-17T22:35:20.3923427Z Legal docs and information: aka.ms/AzureCliLegal
williexu commented 5 years ago

@rgiese I was able to reproduce this, thanks for opening the issue. I will work on improving the error message.

@arichiardi I only see this for non-StorageV2 accounts, can you try again with the latest version of the CLI and creating a new StorageV2 account?

arichiardi commented 5 years ago

@williexu I still see it, this is what I have in CI:

2018-12-31T19:32:46.4768574Z azure-cli (2.0.54)
2018-12-31T19:32:46.4769325Z 
2018-12-31T19:32:46.4769536Z acr (2.1.11)
2018-12-31T19:32:46.4769757Z acs (2.3.13)
2018-12-31T19:32:46.4769929Z advisor (2.0.0)
2018-12-31T19:32:46.4770125Z ams (0.3.1)
2018-12-31T19:32:46.4770290Z appservice (0.2.10)
2018-12-31T19:32:46.4770443Z backup (1.2.1)
2018-12-31T19:32:46.4770650Z batch (3.4.1)
2018-12-31T19:32:46.4770803Z batchai (0.4.5)
2018-12-31T19:32:46.4771006Z billing (0.2.0)
2018-12-31T19:32:46.4771163Z botservice (0.1.3)
2018-12-31T19:32:46.4771371Z cdn (0.2.0)
2018-12-31T19:32:46.4771527Z cloud (2.1.0)
2018-12-31T19:32:46.4771719Z cognitiveservices (0.2.4)
2018-12-31T19:32:46.4772467Z command-modules-nspkg (2.0.2)
2018-12-31T19:32:46.4772883Z configure (2.0.19)
2018-12-31T19:32:46.4773114Z consumption (0.4.1)
2018-12-31T19:32:46.4773348Z container (0.3.10)
2018-12-31T19:32:46.4773612Z core (2.0.54)
2018-12-31T19:32:46.4773817Z cosmosdb (0.2.6)
2018-12-31T19:32:46.4774076Z dla (0.2.3)
2018-12-31T19:32:46.4774281Z dls (0.1.7)
2018-12-31T19:32:46.4774854Z dms (0.1.1)
2018-12-31T19:32:46.4775079Z eventgrid (0.2.0)
2018-12-31T19:32:46.4775334Z eventhubs (0.3.2)
2018-12-31T19:32:46.4775544Z extension (0.2.3)
2018-12-31T19:32:46.4776060Z feedback (2.1.4)
2018-12-31T19:32:46.4776267Z find (0.2.13)
2018-12-31T19:32:46.4776431Z hdinsight (0.1.0)
2018-12-31T19:32:46.4776637Z interactive (0.4.1)
2018-12-31T19:32:46.4776791Z iot (0.3.4)
2018-12-31T19:32:46.4776983Z iotcentral (0.1.5)
2018-12-31T19:32:46.4777146Z keyvault (2.2.9)
2018-12-31T19:32:46.4777342Z lab (0.1.4)
2018-12-31T19:32:46.4777505Z maps (0.3.3)
2018-12-31T19:32:46.4777657Z monitor (0.2.7)
2018-12-31T19:32:46.4777859Z network (2.2.11)
2018-12-31T19:32:46.4778014Z nspkg (3.0.3)
2018-12-31T19:32:46.4778214Z policyinsights (0.1.0)
2018-12-31T19:32:46.4778373Z profile (2.1.2)
2018-12-31T19:32:46.4778657Z rdbms (0.3.5)
2018-12-31T19:32:46.4778820Z redis (0.3.2)
2018-12-31T19:32:46.4779017Z relay (0.1.2)
2018-12-31T19:32:46.4779180Z reservations (0.4.1)
2018-12-31T19:32:46.4779376Z resource (2.1.7)
2018-12-31T19:32:46.4779555Z role (2.2.0)
2018-12-31T19:32:46.4779708Z search (0.1.1)
2018-12-31T19:32:46.4779909Z servicebus (0.3.2)
2018-12-31T19:32:46.4780066Z servicefabric (0.1.10)
2018-12-31T19:32:46.4780273Z signalr (1.0.0)
2018-12-31T19:32:46.4780424Z sql (2.1.6)
2018-12-31T19:32:46.4780616Z storage (2.2.7)
2018-12-31T19:32:46.4780776Z telemetry (1.0.0)
2018-12-31T19:32:46.4781215Z vm (2.2.11)
2018-12-31T19:32:46.4781409Z 
2018-12-31T19:32:46.4781568Z Extensions:
2018-12-31T19:32:46.4782011Z storage-preview (0.2.0)
2018-12-31T19:32:46.4782630Z 
2018-12-31T19:32:46.4783129Z Python location '/opt/az/bin/python3'
2018-12-31T19:32:46.4783728Z Extensions directory '/home/vsts/.azure/cliextensions'
2018-12-31T19:32:46.4783975Z 
2018-12-31T19:32:46.4784244Z Python (Linux) 3.6.5 (default, Dec 20 2018, 01:00:19) 
2018-12-31T19:32:46.4784679Z [GCC 5.4.0 20160609]
arichiardi commented 5 years ago

And the error:

2018-12-31T19:38:43.0750349Z WARNING: The behavior of this command has been altered by the following extension: storage-preview
2018-12-31T19:38:45.3780680Z {
2018-12-31T19:38:45.3781544Z   "accessTier": "Hot",
2018-12-31T19:38:45.3782328Z   "creationTime": "2018-12-03T23:43:01.752888+00:00",
2018-12-31T19:38:45.3782655Z   "customDomain": null,
2018-12-31T19:38:45.3782863Z   "enableAzureFilesAadIntegration": null,
2018-12-31T19:38:45.3792385Z   "enableHttpsTrafficOnly": false,
2018-12-31T19:38:45.3792559Z   "encryption": {
2018-12-31T19:38:45.3792694Z     "keySource": "Microsoft.Storage",
2018-12-31T19:38:45.3792797Z     "keyVaultProperties": null,
2018-12-31T19:38:45.3792907Z     "services": {
2018-12-31T19:38:45.3793928Z       "blob": {
2018-12-31T19:38:45.3794080Z         "enabled": true,
2018-12-31T19:38:45.3794643Z         "lastEnabledTime": "2018-12-03T23:43:01.862305+00:00"
2018-12-31T19:38:45.3794863Z       },
2018-12-31T19:38:45.3795002Z       "file": {
2018-12-31T19:38:45.3795157Z         "enabled": true,
2018-12-31T19:38:45.3795611Z         "lastEnabledTime": "2018-12-03T23:43:01.862305+00:00"
2018-12-31T19:38:45.3795793Z       },
2018-12-31T19:38:45.3795950Z       "queue": null,
2018-12-31T19:38:45.3796086Z       "table": null
2018-12-31T19:38:45.3796237Z     }
2018-12-31T19:38:45.3796373Z   },
2018-12-31T19:38:45.3796544Z   "failoverInProgress": null,
2018-12-31T19:38:45.3796684Z   "geoReplicationStats": null,
[...]
2018-12-31T19:38:45.3797599Z   "identity": null,
2018-12-31T19:38:45.3797717Z   "isHnsEnabled": false,
2018-12-31T19:38:45.3797833Z   "kind": "StorageV2",
2018-12-31T19:38:45.3797950Z   "lastGeoFailoverTime": null,
[...]
2018-12-31T19:38:45.3798270Z   "networkRuleSet": {
2018-12-31T19:38:45.3798388Z     "bypass": "AzureServices",
2018-12-31T19:38:45.3798489Z     "defaultAction": "Allow",
2018-12-31T19:38:45.3798603Z     "ipRules": [],
2018-12-31T19:38:45.3798702Z     "virtualNetworkRules": []
2018-12-31T19:38:45.3798817Z   },
2018-12-31T19:38:45.3799852Z   "primaryLocation": "westus2",
2018-12-31T19:38:45.3799968Z   "provisioningState": "Succeeded",
[...]
2018-12-31T19:38:45.3804102Z   "statusOfPrimary": "available",
2018-12-31T19:38:45.3804259Z   "statusOfSecondary": "available",
2018-12-31T19:38:45.3804405Z   "tags": {},
2018-12-31T19:38:45.3804559Z   "type": "Microsoft.Storage/storageAccounts"
2018-12-31T19:38:45.3804698Z }
2018-12-31T19:38:46.4638791Z ERROR: 'ServiceProperties' object has no attribute 'static_website'
2018-12-31T19:38:46.4639473Z Traceback (most recent call last):
2018-12-31T19:38:46.4639947Z   File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 206, in invoke
2018-12-31T19:38:46.4640480Z     cmd_result = self.invocation.execute(args)
2018-12-31T19:38:46.4640919Z   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 328, in execute
2018-12-31T19:38:46.4641179Z     raise ex
2018-12-31T19:38:46.4641599Z   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 388, in _run_jobs_serially
2018-12-31T19:38:46.4641854Z     results.append(self._run_job(expanded_arg, cmd_copy))
2018-12-31T19:38:46.4642251Z   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 378, in _run_job
2018-12-31T19:38:46.4642514Z     cmd_copy.exception_handler(ex)
2018-12-31T19:38:46.4643105Z   File "/home/vsts/.azure/cliextensions/storage-preview/azext_storage_preview/__init__.py", line 243, in new_handler
2018-12-31T19:38:46.4643733Z     handler(ex)
2018-12-31T19:38:46.4644254Z   File "/home/vsts/.azure/cliextensions/storage-preview/azext_storage_preview/__init__.py", line 190, in handler
2018-12-31T19:38:46.4644574Z     raise ex
2018-12-31T19:38:46.4645066Z   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 357, in _run_job
2018-12-31T19:38:46.4645365Z     result = cmd_copy(params)
2018-12-31T19:38:46.4645860Z   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 171, in __call__
2018-12-31T19:38:46.4646159Z     return self.handler(*args, **kwargs)
2018-12-31T19:38:46.4646645Z   File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/arm.py", line 515, in handler
2018-12-31T19:38:46.4647076Z     result = setter(**setterargs)
2018-12-31T19:38:46.4647674Z   File "/home/vsts/.azure/cliextensions/storage-preview/azext_storage_preview/operations/blob.py", line 21, in set_service_properties
2018-12-31T19:38:46.4648108Z     kwargs['static_website'] = parameters.static_website
2018-12-31T19:38:46.4648566Z AttributeError: 'ServiceProperties' object has no attribute 'static_website'
williexu commented 5 years ago

Very interesting, could you check to make sure your cloud profile is set to latest (az cloud show) and create a new storage account?

arichiardi commented 5 years ago

It looks like it is:

  "isActive": true,
  "name": "AzureCloud",
  "profile": "latest",

another note, this only happens in CI, we can deploy locally. We also checked the python version and it seems the same, the only diffence, but it might be a red herring, is that GCC version (GCC 5.4.0 20160609 on CI) which in our case is newer.

williexu commented 5 years ago

@arichiardi I'm closing this issue as https://github.com/Azure/azure-cli-extensions/pull/463 has fixed the original intent. With regards to seeing a different GCC version, this should not make a difference, as the python versions are the same (and if it does, it will not be a problem with the extension).

I noticed that your storage account in the CI was created about a month ago, could you try creating a newer storage account, there may have been some bug on the server side. In addition, I would recommend trying to look at what other differences there are between your local machine and CI, if you are able to scope down the cause and reproduce your problem, please raise a new issue and I would be able to better address it.

arichiardi commented 5 years ago

Gotcha, will try the patch.

Thank you for your work on that.

arichiardi commented 5 years ago

FYI, tried today I tried 0.2.1 and this patch has fixed our error against StorageV2 as well. Many thanks!