diff --git a/plugins/modules/azure_rm_cosmosdbaccount.py b/plugins/modules/azure_rm_cosmosdbaccount.py index eff572410..b3066126d 100644 --- a/plugins/modules/azure_rm_cosmosdbaccount.py +++ b/plugins/modules/azure_rm_cosmosdbaccount.py @@ -142,7 +142,7 @@ description: - It can be a string containing resource id of a subnet. - It can be a dictionary containing 'resource_group', 'virtual_network_name' and 'subnet_name' - ignore_missing_vnet_service_endpoint: + ignore_missing_v_net_service_endpoint: description: - Create Cosmos DB account without existing virtual network service endpoint. type: bool @@ -215,10 +215,11 @@ from ansible.module_utils.common.dict_transformations import _snake_to_camel try: - from msrestazure.azure_exceptions import CloudError - from msrest.polling import LROPoller + from azure.core.polling import LROPoller + from azure.core.exceptions import ResourceNotFoundError from msrestazure.azure_operation import AzureOperationPoller from azure.mgmt.cosmosdb import CosmosDBManagementClient + from ansible.module_utils.six import string_types except ImportError: # This is handled in azure_rm_common pass @@ -326,7 +327,7 @@ def __init__(self): type='str', required=True ), - ignore_missing_vnet_service_endpoint=dict( + ignore_missing_v_net_service_endpoint=dict( type='bool' ) ) @@ -408,6 +409,7 @@ def exec_module(self, **kwargs): response = None self.mgmt_client = self.get_mgmt_svc_client(CosmosDBManagementClient, + is_track2=True, base_url=self._cloud_environment.endpoints.resource_manager) resource_group = self.get_resource_group(self.resource_group) @@ -469,13 +471,13 @@ def create_update_databaseaccount(self): self.log("Creating / Updating the Database Account instance {0}".format(self.name)) try: - response = self.mgmt_client.database_accounts.create_or_update(resource_group_name=self.resource_group, - account_name=self.name, - create_update_parameters=self.parameters) + response = self.mgmt_client.database_accounts.begin_create_or_update(resource_group_name=self.resource_group, + account_name=self.name, + create_update_parameters=self.parameters) if isinstance(response, LROPoller) or isinstance(response, AzureOperationPoller): response = self.get_poller_result(response) - except CloudError as exc: + except Exception as exc: self.log('Error attempting to create the Database Account instance.') self.fail("Error creating the Database Account instance: {0}".format(str(exc))) return response.as_dict() @@ -488,12 +490,12 @@ def delete_databaseaccount(self): ''' self.log("Deleting the Database Account instance {0}".format(self.name)) try: - response = self.mgmt_client.database_accounts.delete(resource_group_name=self.resource_group, - account_name=self.name) + response = self.mgmt_client.database_accounts.begin_delete(resource_group_name=self.resource_group, + account_name=self.name) if isinstance(response, LROPoller) or isinstance(response, AzureOperationPoller): response = self.get_poller_result(response) - except CloudError as e: + except Exception as e: self.log('Error attempting to delete the Database Account instance.') self.fail("Error deleting the Database Account instance: {0}".format(str(e))) @@ -516,7 +518,7 @@ def get_databaseaccount(self): found = True self.log("Response : {0}".format(response)) self.log("Database Account instance : {0} found".format(response.name)) - except CloudError as e: + except ResourceNotFoundError as e: self.log('Did not find the Database Account instance.') if found is True: return response.as_dict() @@ -565,6 +567,9 @@ def default_compare(new, old, path, result): if path == '/location' or path.endswith('location_name'): new = new.replace(' ', '').lower() old = new.replace(' ', '').lower() + if isinstance(old, string_types) and isinstance(new, string_types): + new = new.lower() + old = old.lower() if new == old: return True else: diff --git a/plugins/modules/azure_rm_cosmosdbaccount_info.py b/plugins/modules/azure_rm_cosmosdbaccount_info.py index b227e61e1..c97b59ea7 100644 --- a/plugins/modules/azure_rm_cosmosdbaccount_info.py +++ b/plugins/modules/azure_rm_cosmosdbaccount_info.py @@ -302,7 +302,7 @@ type: str sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNet works/testvnet/subnets/testsubnet1" - ignore_missing_vnet_service_endpoint: + ignore_missing_v_net_service_endpoint: description: - Create Cosmos DB account without existing virtual network service endpoint. type: bool @@ -378,7 +378,7 @@ from ansible.module_utils.common.dict_transformations import _camel_to_snake try: - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError from azure.mgmt.cosmosdb import CosmosDBManagementClient except ImportError: # This is handled in azure_rm_common @@ -429,6 +429,7 @@ def exec_module(self, **kwargs): for key in self.module_arg_spec: setattr(self, key, kwargs[key]) self.mgmt_client = self.get_mgmt_svc_client(CosmosDBManagementClient, + is_track2=True, base_url=self._cloud_environment.endpoints.resource_manager) if self.name is not None: @@ -446,7 +447,7 @@ def get(self): response = self.mgmt_client.database_accounts.get(resource_group_name=self.resource_group, account_name=self.name) self.log("Response : {0}".format(response)) - except CloudError as e: + except ResourceNotFoundError as e: self.log('Could not get facts for Database Account.') if response and self.has_tags(response.tags, self.tags): @@ -460,7 +461,7 @@ def list_by_resource_group(self): try: response = self.mgmt_client.database_accounts.list_by_resource_group(resource_group_name=self.resource_group) self.log("Response : {0}".format(response)) - except CloudError as e: + except Exception as e: self.log('Could not get facts for Database Account.') if response is not None: @@ -476,7 +477,7 @@ def list_all(self): try: response = self.mgmt_client.database_accounts.list() self.log("Response : {0}".format(response)) - except CloudError as e: + except Exception as e: self.log('Could not get facts for Database Account.') if response is not None: diff --git a/requirements-azure.txt b/requirements-azure.txt index ec2b8729e..293de5d38 100644 --- a/requirements-azure.txt +++ b/requirements-azure.txt @@ -36,11 +36,11 @@ azure-mgmt-trafficmanager==1.0.0b1 azure-mgmt-web==6.1.0 azure-nspkg==2.0.0 azure-storage-blob==12.11.0 -msrest==0.6.21 +msrest==0.7.1 msrestazure==0.6.4 azure-keyvault==1.0.0a1 azure-graphrbac==0.61.1 -azure-mgmt-cosmosdb==0.15.0 +azure-mgmt-cosmosdb==6.4.0 azure-mgmt-hdinsight==9.0.0 azure-mgmt-devtestlabs==3.0.0 azure-mgmt-loganalytics==12.0.0 diff --git a/tests/integration/targets/azure_rm_cosmosdbaccount/tasks/main.yml b/tests/integration/targets/azure_rm_cosmosdbaccount/tasks/main.yml index 1785eb774..ca1cc8b90 100644 --- a/tests/integration/targets/azure_rm_cosmosdbaccount/tasks/main.yml +++ b/tests/integration/targets/azure_rm_cosmosdbaccount/tasks/main.yml @@ -59,7 +59,7 @@ resource_group: "{{ resource_group }}" virtual_network_name: "{{ vnname }}" subnet_name: "{{ subnetname }}" - ignore_missing_vnet_service_endpoint: yes + ignore_missing_v_net_service_endpoint: yes register: output - name: Assert the resource instance is well created assert: @@ -84,7 +84,7 @@ resource_group: "{{ resource_group }}" virtual_network_name: "{{ vnname }}" subnet_name: "{{ subnetname }}" - ignore_missing_vnet_service_endpoint: yes + ignore_missing_v_net_service_endpoint: yes register: output - name: Assert the state has not changed assert: @@ -109,7 +109,7 @@ resource_group: "{{ resource_group }}" virtual_network_name: "{{ vnname }}" subnet_name: "{{ subnetname }}" - ignore_missing_vnet_service_endpoint: yes + ignore_missing_v_net_service_endpoint: yes enable_automatic_failover: yes register: output - name: Assert the state has changed @@ -135,7 +135,7 @@ resource_group: "{{ resource_group }}" virtual_network_name: "{{ vnname }}" subnet_name: "{{ subnetname }}" - ignore_missing_vnet_service_endpoint: yes + ignore_missing_v_net_service_endpoint: yes register: output - name: Assert the resource instance is well created assert: @@ -278,7 +278,7 @@ resource_group: "{{ resource_group }}" virtual_network_name: "{{ vnname }}" subnet_name: "{{ subnetname }}" - ignore_missing_vnet_service_endpoint: yes + ignore_missing_v_net_service_endpoint: yes enable_automatic_failover: yes register: output - name: Assert resource created