Skip to content

Commit

Permalink
Upgrade azure-mgmt-storage to 19.0.0 (#777)
Browse files Browse the repository at this point in the history
* Update azure-mgmt-storage to 19.0.0

* Handle keywords with new exceptions

* fix azure_rm_storageaccount sample fail

* modify check name availability paramters

* modify check name availability paramters 02

* Change ResourceNotFounndError to Exception
  • Loading branch information
Fred-sun committed Mar 9, 2022
1 parent 136adeb commit 0bcf917
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 34 deletions.
9 changes: 5 additions & 4 deletions plugins/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def default_api_version(self):
'NetworkManagementClient': '2019-06-01',
'ResourceManagementClient': '2017-05-10',
'SearchManagementClient': '2020-08-01',
'StorageManagementClient': '2019-06-01',
'StorageManagementClient': '2021-06-01',
'SubscriptionClient': '2019-11-01',
'WebSiteManagementClient': '2018-02-01',
'PostgreSQLManagementClient': '2017-12-01',
Expand Down Expand Up @@ -329,7 +329,7 @@ def normalize_location_name(name):
AZURE_PKG_VERSIONS = {
'StorageManagementClient': {
'package_name': 'storage',
'expected_version': '11.1.0'
'expected_version': '19.0.0'
},
'ComputeManagementClient': {
'package_name': 'compute',
Expand Down Expand Up @@ -1000,12 +1000,13 @@ def storage_client(self):
if not self._storage_client:
self._storage_client = self.get_mgmt_svc_client(StorageManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
api_version='2019-06-01')
is_track2=True,
api_version='2021-06-01')
return self._storage_client

@property
def storage_models(self):
return StorageManagementClient.models("2019-06-01")
return StorageManagementClient.models("2021-06-01")

@property
def authorization_client(self):
Expand Down
31 changes: 13 additions & 18 deletions plugins/modules/azure_rm_storageaccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@
'''

try:
from msrestazure.azure_exceptions import CloudError
from azure.core.exceptions import ResourceNotFoundError
from azure.storage.cloudstorageaccount import CloudStorageAccount
from azure.common import AzureMissingResourceHttpError
except ImportError:
Expand Down Expand Up @@ -535,13 +535,11 @@ def exec_module(self, **kwargs):
def check_name_availability(self):
self.log('Checking name availability for {0}'.format(self.name))
try:
response = self.storage_client.storage_accounts.check_name_availability(self.name)
except CloudError as e:
account_name = self.storage_models.StorageAccountCheckNameAvailabilityParameters(name=self.name)
response = self.storage_client.storage_accounts.check_name_availability(account_name)
except Exception as e:
self.log('Error attempting to validate name.')
self.fail("Error checking name availability: {0}".format(str(e)))
if not response.name_available:
self.log('Error name not available.')
self.fail("{0} - {1}".format(response.message, response.reason))

def get_account(self):
self.log('Get properties for account {0}'.format(self.name))
Expand All @@ -552,7 +550,7 @@ def get_account(self):
try:
account_obj = self.storage_client.storage_accounts.get_properties(self.resource_group, self.name)
blob_service_props = self.storage_client.blob_services.get_service_properties(self.resource_group, self.name)
except CloudError:
except Exception:
pass

if account_obj:
Expand All @@ -567,16 +565,13 @@ def account_obj_to_dict(self, account_obj, blob_service_props=None):
location=account_obj.location,
resource_group=self.resource_group,
type=account_obj.type,
access_tier=(account_obj.access_tier.value
if account_obj.access_tier is not None else None),
access_tier=account_obj.access_tier,
sku_tier=account_obj.sku.tier,
sku_name=account_obj.sku.name,
provisioning_state=account_obj.provisioning_state.value,
provisioning_state=account_obj.provisioning_state,
secondary_location=account_obj.secondary_location,
status_of_primary=(account_obj.status_of_primary.value
if account_obj.status_of_primary is not None else None),
status_of_secondary=(account_obj.status_of_secondary.value
if account_obj.status_of_secondary is not None else None),
status_of_primary=account_obj.status_of_primary,
status_of_secondary=account_obj.status_of_secondary,
primary_location=account_obj.primary_location,
https_only=account_obj.enable_https_traffic_only,
minimum_tls_version=account_obj.minimum_tls_version,
Expand Down Expand Up @@ -834,9 +829,9 @@ def create_account(self):
access_tier=self.access_tier)
self.log(str(parameters))
try:
poller = self.storage_client.storage_accounts.create(self.resource_group, self.name, parameters)
poller = self.storage_client.storage_accounts.begin_create(self.resource_group, self.name, parameters)
self.get_poller_result(poller)
except CloudError as e:
except Exception as e:
self.log('Error creating storage account.')
self.fail("Failed to create account: {0}".format(str(e)))
if self.network_acls:
Expand All @@ -858,7 +853,7 @@ def delete_account(self):
status = self.storage_client.storage_accounts.delete(self.resource_group, self.name)
self.log("delete status: ")
self.log(str(status))
except CloudError as e:
except Exception as e:
self.fail("Failed to delete the account: {0}".format(str(e)))
return True

Expand All @@ -871,7 +866,7 @@ def account_has_blob_containers(self):
blob_service = self.get_blob_client(self.resource_group, self.name)
try:
response = blob_service.list_containers()
except AzureMissingResourceHttpError:
except Exception:
# No blob storage available?
return False

Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/azure_rm_storageaccount_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@
'''

try:
from msrestazure.azure_exceptions import CloudError
from azure.core.exceptions import ResourceNotFoundError
except Exception:
# This is handled in azure_rm_common
pass
Expand Down Expand Up @@ -475,7 +475,7 @@ def get_account(self):
try:
account = self.storage_client.storage_accounts.get_properties(self.resource_group, self.name)
return [account]
except CloudError:
except ResourceNotFoundError:
pass
return []

Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/azure_rm_storageshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
'''

try:
from msrestazure.azure_exceptions import CloudError
from azure.core.exceptions import ResourceNotFoundError
except ImportError:
# This is handled in azure_rm_common
pass
Expand Down Expand Up @@ -273,7 +273,7 @@ def get_share(self):
share_name=self.name)
found = True
self.log("Response : {0}".format(storage_share))
except Exception as e:
except ResourceNotFoundError as e:
self.log("Did not find the storage file share with name {0} : {1}".format(self.name, str(e)))
return self.storage_share_to_dict(storage_share) if found else None

Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/azure_rm_storageshare_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
'''

try:
from msrestazure.azure_exceptions import CloudError
from azure.core.exceptions import ResourceNotFoundError
except ImportError:
# This is handled in azure_rm_common
pass
Expand Down Expand Up @@ -222,7 +222,7 @@ def get_share(self):
account_name=self.account_name,
share_name=self.name)
self.log("Response : {0}".format(storage_share))
except Exception as e:
except ResourceNotFoundError as e:
self.log("Did not find the storage share with name {0} : {1}".format(self.name, str(e)))
return self.storage_share_to_dict(storage_share)

Expand Down
7 changes: 4 additions & 3 deletions plugins/modules/azure_rm_virtualmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2162,7 +2162,7 @@ def create_default_storage_account(self, vm_dict=None):

try:
account = self.storage_client.storage_accounts.get_properties(self.resource_group, storage_account_name)
except CloudError:
except Exception:
pass

if account:
Expand All @@ -2177,7 +2177,7 @@ def create_default_storage_account(self, vm_dict=None):
self.log("Creating storage account {0} in location {1}".format(storage_account_name, self.location))
self.results['actions'].append("Created storage account {0}".format(storage_account_name))
try:
poller = self.storage_client.storage_accounts.create(self.resource_group, storage_account_name, parameters)
poller = self.storage_client.storage_accounts.begin_create(self.resource_group, storage_account_name, parameters)
self.get_poller_result(poller)
except Exception as exc:
self.fail("Failed to create storage account: {0} - {1}".format(storage_account_name, str(exc)))
Expand All @@ -2187,7 +2187,8 @@ def create_default_storage_account(self, vm_dict=None):
def check_storage_account_name(self, name):
self.log("Checking storage account name availability for {0}".format(name))
try:
response = self.storage_client.storage_accounts.check_name_availability(name)
account_name = self.storage_models.StorageAccountCheckNameAvailabilityParameters(name=name)
response = self.storage_client.storage_accounts.check_name_availability(account_name)
if response.reason == 'AccountNameInvalid':
raise Exception("Invalid default storage account name: {0}".format(name))
except Exception as exc:
Expand Down
2 changes: 1 addition & 1 deletion requirements-azure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ azure-mgmt-rdbms==1.9.0
azure-mgmt-search==3.0.0
azure-mgmt-servicebus==0.5.3
azure-mgmt-sql==0.10.0
azure-mgmt-storage==11.1.0
azure-mgmt-storage==19.0.0
azure-mgmt-trafficmanager==0.50.0
azure-mgmt-web==0.41.0
azure-nspkg==2.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
- defaults_output.state.id is defined
- defaults_output.state.https_only
- defaults_output.state.access_tier == None
- defaults_output.state.allow_blob_public_access == None
- defaults_output.state.minimum_tls_version == None
- defaults_output.state.allow_blob_public_access == true
- defaults_output.state.minimum_tls_version == "TLS1_0"

- name: Create new storage account with I(kind=FileStorage)
azure_rm_storageaccount:
Expand Down

0 comments on commit 0bcf917

Please sign in to comment.