From a70012061e829a87a606784dd7a7ea71afa94846 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Mon, 1 Nov 2021 16:55:53 +0800 Subject: [PATCH 01/19] Ugrade azure-mgmt-compute SDK to track2 --- plugins/module_utils/azure_rm_common.py | 10 +++-- plugins/modules/azure_rm_availabilityset.py | 10 ++--- .../modules/azure_rm_availabilityset_info.py | 4 +- plugins/modules/azure_rm_diskencryptionset.py | 12 +++--- .../azure_rm_diskencryptionset_info.py | 6 +-- plugins/modules/azure_rm_image.py | 6 +-- plugins/modules/azure_rm_image_info.py | 6 +-- plugins/modules/azure_rm_manageddisk.py | 20 ++++----- plugins/modules/azure_rm_manageddisk_info.py | 6 +-- .../azure_rm_proximityplacementgroup.py | 13 +++--- .../azure_rm_proximityplacementgroup_info.py | 6 +-- plugins/modules/azure_rm_virtualmachine.py | 22 +++++----- .../modules/azure_rm_virtualmachine_info.py | 4 +- .../azure_rm_virtualmachineextension.py | 10 ++--- .../azure_rm_virtualmachineextension_info.py | 4 +- .../azure_rm_virtualmachineimage_info.py | 8 +--- .../azure_rm_virtualmachinescaleset.py | 24 +++++------ .../azure_rm_virtualmachinescaleset_info.py | 4 +- ...zure_rm_virtualmachinescalesetextension.py | 20 ++++----- ...rm_virtualmachinescalesetextension_info.py | 4 +- ...azure_rm_virtualmachinescalesetinstance.py | 43 ++++++++++--------- .../azure_rm_virtualmachinesize_info.py | 2 +- requirements-azure.txt | 2 +- 23 files changed, 120 insertions(+), 126 deletions(-) diff --git a/plugins/module_utils/azure_rm_common.py b/plugins/module_utils/azure_rm_common.py index 1f6d3f031..73a639921 100644 --- a/plugins/module_utils/azure_rm_common.py +++ b/plugins/module_utils/azure_rm_common.py @@ -1084,13 +1084,14 @@ def image_client(self): if not self._image_client: self._image_client = self.get_mgmt_svc_client(ComputeManagementClient, base_url=self._cloud_environment.endpoints.resource_manager, - api_version='2018-06-01') + is_track2=True, + api_version='2021-07-01') return self._image_client @property def image_models(self): self.log("Getting compute image models") - return ComputeManagementClient.models("2018-06-01") + return ComputeManagementClient.models("2021-07-01") @property def compute_client(self): @@ -1098,13 +1099,14 @@ def compute_client(self): if not self._compute_client: self._compute_client = self.get_mgmt_svc_client(ComputeManagementClient, base_url=self._cloud_environment.endpoints.resource_manager, - api_version='2019-07-01') + is_track2=True, + api_version='2021-07-01') return self._compute_client @property def compute_models(self): self.log("Getting compute models") - return ComputeManagementClient.models("2019-07-01") + return ComputeManagementClient.models("2021-07-01") @property def dns_client(self): diff --git a/plugins/modules/azure_rm_availabilityset.py b/plugins/modules/azure_rm_availabilityset.py index 1af19d15c..a7cce2321 100644 --- a/plugins/modules/azure_rm_availabilityset.py +++ b/plugins/modules/azure_rm_availabilityset.py @@ -326,8 +326,8 @@ def create_or_update_availabilityset(self): proximity_placement_group=self.proximity_placement_group_resource, sku=params_sku ) - response = self.compute_client.availability_sets.create_or_update(self.resource_group, self.name, params) - except CloudError as e: + response = self.compute_client.availability_sets.begin_create_or_update(self.resource_group, self.name, params) + except Exception as e: self.log('Error attempting to create the availability set.') self.fail("Error creating the availability set: {0}".format(str(e))) @@ -340,8 +340,8 @@ def delete_availabilityset(self): ''' self.log("Deleting availabilityset {0}".format(self.name)) try: - response = self.compute_client.availability_sets.delete(self.resource_group, self.name) - except CloudError as e: + response = self.compute_client.availability_sets.begin_delete(self.resource_group, self.name) + except Exception as e: self.log('Error attempting to delete the availability set.') self.fail("Error deleting the availability set: {0}".format(str(e))) @@ -357,7 +357,7 @@ def get_availabilityset(self): try: response = self.compute_client.availability_sets.get(self.resource_group, self.name) found = True - except CloudError as e: + except Exception as e: self.log('Did not find the Availability set.') if found is True: return availability_set_to_dict(response) diff --git a/plugins/modules/azure_rm_availabilityset_info.py b/plugins/modules/azure_rm_availabilityset_info.py index d8d0cbe55..39a0eef34 100644 --- a/plugins/modules/azure_rm_availabilityset_info.py +++ b/plugins/modules/azure_rm_availabilityset_info.py @@ -169,7 +169,7 @@ def get_item(self): try: item = self.compute_client.availability_sets.get(self.resource_group, self.name) - except CloudError: + except Exception: pass if item and self.has_tags(item.tags, self.tags): @@ -188,7 +188,7 @@ def list_items(self): try: response = self.compute_client.availability_sets.list(self.resource_group) - except CloudError as exc: + except Exception as exc: self.fail('Failed to list all items - {0}'.format(str(exc))) results = [] diff --git a/plugins/modules/azure_rm_diskencryptionset.py b/plugins/modules/azure_rm_diskencryptionset.py index 0ba2b1ac7..03fe4637d 100644 --- a/plugins/modules/azure_rm_diskencryptionset.py +++ b/plugins/modules/azure_rm_diskencryptionset.py @@ -245,7 +245,7 @@ def exec_module(self, **kwargs): elif self.state == 'absent': changed = True - except CloudError: + except Exception: if self.state == 'present': changed = True else: @@ -284,9 +284,9 @@ def create_or_update_diskencryptionset(self, disk_encryption_set): try: # create the disk encryption set response = \ - self.compute_client.disk_encryption_sets.create_or_update(resource_group_name=self.resource_group, - disk_encryption_set_name=self.name, - disk_encryption_set=disk_encryption_set) + self.compute_client.disk_encryption_sets.begin_create_or_update(resource_group_name=self.resource_group, + disk_encryption_set_name=self.name, + disk_encryption_set=disk_encryption_set) if isinstance(response, LROPoller): response = self.get_poller_result(response) except Exception as exc: @@ -296,8 +296,8 @@ def create_or_update_diskencryptionset(self, disk_encryption_set): def delete_diskencryptionset(self): try: # delete the disk encryption set - response = self.compute_client.disk_encryption_sets.delete(resource_group_name=self.resource_group, - disk_encryption_set_name=self.name) + response = self.compute_client.disk_encryption_sets.begin_delete(resource_group_name=self.resource_group, + disk_encryption_set_name=self.name) if isinstance(response, LROPoller): response = self.get_poller_result(response) except Exception as exc: diff --git a/plugins/modules/azure_rm_diskencryptionset_info.py b/plugins/modules/azure_rm_diskencryptionset_info.py index b6f87e2a8..31e9fc342 100644 --- a/plugins/modules/azure_rm_diskencryptionset_info.py +++ b/plugins/modules/azure_rm_diskencryptionset_info.py @@ -148,7 +148,7 @@ def get_item(self): # get specific disk encryption set try: item = self.compute_client.disk_encryption_sets.get(self.resource_group, self.name) - except CloudError: + except Exception: pass # serialize result @@ -160,7 +160,7 @@ def list_resource_group(self): self.log('List all disk encryption sets for resource group - {0}'.format(self.resource_group)) try: response = self.compute_client.disk_encryption_sets.list_by_resource_group(self.resource_group) - except AzureHttpError as exc: + except Exception as exc: self.fail("Failed to list for resource group {0} - {1}".format(self.resource_group, str(exc))) results = [] @@ -173,7 +173,7 @@ def list_items(self): self.log('List all disk encryption sets for a subscription ') try: response = self.compute_client.disk_encryption_sets.list() - except AzureHttpError as exc: + except Exception as exc: self.fail("Failed to list all items - {0}".format(str(exc))) results = [] diff --git a/plugins/modules/azure_rm_image.py b/plugins/modules/azure_rm_image.py index e52a3fd09..cf006e844 100644 --- a/plugins/modules/azure_rm_image.py +++ b/plugins/modules/azure_rm_image.py @@ -328,7 +328,7 @@ def _get_resource(self, get_method, resource_group, name, expand=None): return get_method(resource_group, name, expand=expand) else: return get_method(resource_group, name) - except CloudError as cloud_err: + except Exception as cloud_err: # Return None iff the resource is not found if cloud_err.status_code == 404: self.log('{0}'.format(str(cloud_err))) @@ -339,7 +339,7 @@ def _get_resource(self, get_method, resource_group, name, expand=None): def create_image(self, image): try: - poller = self.image_client.images.create_or_update(self.resource_group, self.name, image) + poller = self.image_client.images.begin_create_or_update(self.resource_group, self.name, image) new_image = self.get_poller_result(poller) except Exception as exc: self.fail("Error creating image {0} - {1}".format(self.name, str(exc))) @@ -349,7 +349,7 @@ def create_image(self, image): def delete_image(self): self.log('Deleting image {0}'.format(self.name)) try: - poller = self.image_client.images.delete(self.resource_group, self.name) + poller = self.image_client.images.begin_delete(self.resource_group, self.name) result = self.get_poller_result(poller) except Exception as exc: self.fail("Error deleting image {0} - {1}".format(self.name, str(exc))) diff --git a/plugins/modules/azure_rm_image_info.py b/plugins/modules/azure_rm_image_info.py index d9e27037b..798b52b02 100644 --- a/plugins/modules/azure_rm_image_info.py +++ b/plugins/modules/azure_rm_image_info.py @@ -231,7 +231,7 @@ def get_image(self, resource_group, image_name): item = None try: item = self.image_client.images.get(resource_group, image_name) - except CloudError as exc: + except Exception as exc: self.fail('Failed to list images - {0}'.format(str(exc))) result = [self.format_item(item)] @@ -246,7 +246,7 @@ def list_images_by_resource_group(self, resource_group): response = None try: response = self.image_client.images.list_by_resource_group(resource_group) - except CloudError as exc: + except Exception as exc: self.fail("Failed to list images: {0}".format(str(exc))) return [self.format_item(x) for x in response if self.has_tags(x.tags, self.tags)] if response else [] @@ -261,7 +261,7 @@ def list_images(self, image_name=None): results = [] try: response = self.image_client.images.list() - except CloudError as exc: + except Exception as exc: self.fail("Failed to list all images: {0}".format(str(exc))) results = [self.format_item(x) for x in response if self.has_tags(x.tags, self.tags)] if response else [] diff --git a/plugins/modules/azure_rm_manageddisk.py b/plugins/modules/azure_rm_manageddisk.py index f1598d7c7..6d30d19e4 100644 --- a/plugins/modules/azure_rm_manageddisk.py +++ b/plugins/modules/azure_rm_manageddisk.py @@ -424,7 +424,7 @@ def detach(self, vm_name, disk): def _update_vm(self, name, params): try: - poller = self.compute_client.virtual_machines.create_or_update(self.resource_group, name, params) + poller = self.compute_client.virtual_machines.begin_create_or_update(self.resource_group, name, params) self.get_poller_result(poller) except Exception as exc: self.fail("Error updating virtual machine {0} - {1}".format(name, str(exc))) @@ -467,13 +467,12 @@ def generate_managed_disk_property(self): def create_or_update_managed_disk(self, parameter): try: - poller = self.compute_client.disks.create_or_update( - self.resource_group, - self.name, - parameter) + poller = self.compute_client.disks.begin_create_or_update(self.resource_group, + self.name, + parameter) aux = self.get_poller_result(poller) return managed_disk_to_dict(aux) - except CloudError as e: + except Exception as e: self.fail("Error creating the managed disk: {0}".format(str(e))) # This method accounts for the difference in structure between the @@ -500,11 +499,10 @@ def is_different(self, found_disk, new_disk): def delete_managed_disk(self): try: - poller = self.compute_client.disks.delete( - self.resource_group, - self.name) + poller = self.compute_client.disks.begin_delete(self.resource_group, + self.name) return self.get_poller_result(poller) - except CloudError as e: + except Exception as e: self.fail("Error deleting the managed disk: {0}".format(str(e))) def get_managed_disk(self): @@ -513,7 +511,7 @@ def get_managed_disk(self): self.resource_group, self.name) return managed_disk_to_dict(resp) - except CloudError as e: + except Exception as e: self.log('Did not find managed disk') def is_attach_caching_option_different(self, vm_name, disk): diff --git a/plugins/modules/azure_rm_manageddisk_info.py b/plugins/modules/azure_rm_manageddisk_info.py index 1c4c0f8e7..a8234971d 100644 --- a/plugins/modules/azure_rm_manageddisk_info.py +++ b/plugins/modules/azure_rm_manageddisk_info.py @@ -191,7 +191,7 @@ def get_disk(self): if self.tags: results = [disk for disk in results if self.has_tags(disk.tags, self.tags)] results = [self.managed_disk_to_dict(disk) for disk in results] - except CloudError: + except Exception: self.log('Could not find disk {0} in resource group {1}'.format(self.name, self.resource_group)) return results @@ -207,7 +207,7 @@ def list_disks(self): if self.tags: results = [disk for disk in results if self.has_tags(disk.tags, self.tags)] results = [self.managed_disk_to_dict(disk) for disk in results] - except CloudError as exc: + except Exception as exc: self.fail('Failed to list all items - {0}'.format(str(exc))) return results @@ -223,7 +223,7 @@ def list_disks_by_resource_group(self): if self.tags: results = [disk for disk in results if self.has_tags(disk.tags, self.tags)] results = [self.managed_disk_to_dict(disk) for disk in results] - except CloudError as exc: + except Exception as exc: self.fail('Failed to list items by resource group - {0}'.format(str(exc))) return results diff --git a/plugins/modules/azure_rm_proximityplacementgroup.py b/plugins/modules/azure_rm_proximityplacementgroup.py index 81ee44e89..a8b5e71aa 100644 --- a/plugins/modules/azure_rm_proximityplacementgroup.py +++ b/plugins/modules/azure_rm_proximityplacementgroup.py @@ -190,7 +190,7 @@ def exec_module(self, **kwargs): elif self.state == 'absent': changed = True - except CloudError: + except Exception: if self.state == 'present': changed = True else: @@ -222,10 +222,9 @@ def exec_module(self, **kwargs): def create_or_update_placementgroup(self, proximity_placement_group): try: # create the placement group - response = self.compute_client.proximity_placement_groups.create_or_update( - resource_group_name=self.resource_group, - proximity_placement_group_name=self.name, - parameters=proximity_placement_group) + response = self.compute_client.proximity_placement_groups.begin_create_or_update(resource_group_name=self.resource_group, + proximity_placement_group_name=self.name, + parameters=proximity_placement_group) except Exception as exc: self.fail("Error creating or updating proximity placement group {0} - {1}".format(self.name, str(exc))) return self.ppg_to_dict(response) @@ -233,8 +232,8 @@ def create_or_update_placementgroup(self, proximity_placement_group): def delete_placementgroup(self): try: # delete the placement group - response = self.compute_client.proximity_placement_groups.delete(resource_group_name=self.resource_group, - proximity_placement_group_name=self.name) + response = self.compute_client.proximity_placement_groups.begin_delete(resource_group_name=self.resource_group, + proximity_placement_group_name=self.name) except Exception as exc: self.fail("Error deleting proximity placement group {0} - {1}".format(self.name, str(exc))) return response diff --git a/plugins/modules/azure_rm_proximityplacementgroup_info.py b/plugins/modules/azure_rm_proximityplacementgroup_info.py index 9d8751145..a77a39702 100644 --- a/plugins/modules/azure_rm_proximityplacementgroup_info.py +++ b/plugins/modules/azure_rm_proximityplacementgroup_info.py @@ -150,7 +150,7 @@ def get_item(self): # get specific proximity placement group try: item = self.compute_client.proximity_placement_groups.get(self.resource_group, self.name) - except CloudError: + except Exception: pass # serialize result @@ -162,7 +162,7 @@ def list_resource_group(self): self.log('List all proximity placement groups for resource group - {0}'.format(self.resource_group)) try: response = self.compute_client.proximity_placement_groups.list_by_resource_group(self.resource_group) - except AzureHttpError as exc: + except Exception as exc: self.fail("Failed to list for resource group {0} - {1}".format(self.resource_group, str(exc))) results = [] @@ -175,7 +175,7 @@ def list_items(self): self.log('List all proximity placement groups for a subscription ') try: response = self.compute_client.proximity_placement_groups.list_by_subscription() - except AzureHttpError as exc: + except Exception as exc: self.fail("Failed to list all items - {0}".format(str(exc))) results = [] diff --git a/plugins/modules/azure_rm_virtualmachine.py b/plugins/modules/azure_rm_virtualmachine.py index 8c2ac844b..d4052a94c 100644 --- a/plugins/modules/azure_rm_virtualmachine.py +++ b/plugins/modules/azure_rm_virtualmachine.py @@ -1796,7 +1796,7 @@ def power_off_vm(self): self.log("Powered off virtual machine {0}".format(self.name)) self.results['actions'].append("Powered off virtual machine {0}".format(self.name)) try: - poller = self.compute_client.virtual_machines.power_off(self.resource_group, self.name) + poller = self.compute_client.virtual_machines.begin_power_off(self.resource_group, self.name) self.get_poller_result(poller) except Exception as exc: self.fail("Error powering off virtual machine {0} - {1}".format(self.name, str(exc))) @@ -1806,7 +1806,7 @@ def power_on_vm(self): self.results['actions'].append("Powered on virtual machine {0}".format(self.name)) self.log("Power on virtual machine {0}".format(self.name)) try: - poller = self.compute_client.virtual_machines.start(self.resource_group, self.name) + poller = self.compute_client.virtual_machines.begin_start(self.resource_group, self.name) self.get_poller_result(poller) except Exception as exc: self.fail("Error powering on virtual machine {0} - {1}".format(self.name, str(exc))) @@ -1816,7 +1816,7 @@ def restart_vm(self): self.results['actions'].append("Restarted virtual machine {0}".format(self.name)) self.log("Restart virtual machine {0}".format(self.name)) try: - poller = self.compute_client.virtual_machines.restart(self.resource_group, self.name) + poller = self.compute_client.virtual_machines.begin_restart(self.resource_group, self.name) self.get_poller_result(poller) except Exception as exc: self.fail("Error restarting virtual machine {0} - {1}".format(self.name, str(exc))) @@ -1826,7 +1826,7 @@ def deallocate_vm(self): self.results['actions'].append("Deallocated virtual machine {0}".format(self.name)) self.log("Deallocate virtual machine {0}".format(self.name)) try: - poller = self.compute_client.virtual_machines.deallocate(self.resource_group, self.name) + poller = self.compute_client.virtual_machines.begin_deallocate(self.resource_group, self.name) self.get_poller_result(poller) except Exception as exc: self.fail("Error deallocating virtual machine {0} - {1}".format(self.name, str(exc))) @@ -1910,7 +1910,7 @@ def delete_vm(self, vm): self.log("Deleting virtual machine {0}".format(self.name)) self.results['actions'].append("Deleted virtual machine {0}".format(self.name)) try: - poller = self.compute_client.virtual_machines.delete(self.resource_group, self.name) + poller = self.compute_client.virtual_machines.begin_delete(self.resource_group, self.name) # wait for the poller to finish self.get_poller_result(poller) except Exception as exc: @@ -2085,7 +2085,7 @@ def get_storage_account(self, resource_group, name): def create_or_update_vm(self, params, remove_autocreated_on_failure): try: - poller = self.compute_client.virtual_machines.create_or_update(self.resource_group, self.name, params) + poller = self.compute_client.virtual_machines.begin_create_or_update(self.resource_group, self.name, params) self.get_poller_result(poller) except Exception as exc: if remove_autocreated_on_failure: @@ -2148,7 +2148,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: @@ -2198,7 +2198,7 @@ def create_default_nic(self): self.log("Check to see if NIC {0} exists".format(network_interface_name)) try: nic = self.network_client.network_interfaces.get(self.resource_group, network_interface_name) - except CloudError: + except Exception: pass if nic: @@ -2218,7 +2218,7 @@ def create_default_nic(self): try: self.network_client.virtual_networks.list(virtual_network_resource_group, self.virtual_network_name) virtual_network_name = self.virtual_network_name - except CloudError as exc: + except Exception as exc: self.fail("Error: fetching virtual network {0} - {1}".format(self.virtual_network_name, str(exc))) else: @@ -2230,7 +2230,7 @@ def create_default_nic(self): virtual_network_name = None try: vnets = self.network_client.virtual_networks.list(virtual_network_resource_group) - except CloudError: + except Exception: self.log('cloud error!') self.fail(no_vnets_msg) @@ -2256,7 +2256,7 @@ def create_default_nic(self): subnet_id = None try: subnets = self.network_client.subnets.list(virtual_network_resource_group, virtual_network_name) - except CloudError: + except Exception: self.fail(no_subnets_msg) for subnet in subnets: diff --git a/plugins/modules/azure_rm_virtualmachine_info.py b/plugins/modules/azure_rm_virtualmachine_info.py index 2dec9f3ed..6fb5bcd6c 100644 --- a/plugins/modules/azure_rm_virtualmachine_info.py +++ b/plugins/modules/azure_rm_virtualmachine_info.py @@ -347,7 +347,7 @@ def list_items_by_resourcegroup(self): self.log('List all items') try: items = self.compute_client.virtual_machines.list(self.resource_group) - except CloudError as exc: + except Exception as exc: self.fail("Failed to list all items - {0}".format(str(exc))) results = [] @@ -360,7 +360,7 @@ def list_all_items(self): self.log('List all items') try: items = self.compute_client.virtual_machines.list_all() - except CloudError as exc: + except Exception as exc: self.fail("Failed to list all items - {0}".format(str(exc))) results = [] diff --git a/plugins/modules/azure_rm_virtualmachineextension.py b/plugins/modules/azure_rm_virtualmachineextension.py index 0f41aeebc..c0fee458a 100644 --- a/plugins/modules/azure_rm_virtualmachineextension.py +++ b/plugins/modules/azure_rm_virtualmachineextension.py @@ -286,11 +286,11 @@ def create_or_update_vmextension(self): settings=self.settings, protected_settings=self.protected_settings ) - poller = self.compute_client.virtual_machine_extensions.create_or_update(self.resource_group, self.virtual_machine_name, self.name, params) + poller = self.compute_client.virtual_machine_extensions.begin_create_or_update(self.resource_group, self.virtual_machine_name, self.name, params) response = self.get_poller_result(poller) return vmextension_to_dict(response) - except CloudError as e: + except Exception as e: self.log('Error attempting to create the VM extension.') self.fail("Error creating the VM extension: {0}".format(str(e))) @@ -301,9 +301,9 @@ def delete_vmextension(self): ''' self.log("Deleting vmextension {0}".format(self.name)) try: - poller = self.compute_client.virtual_machine_extensions.delete(self.resource_group, self.virtual_machine_name, self.name) + poller = self.compute_client.virtual_machine_extensions.begin_delete(self.resource_group, self.virtual_machine_name, self.name) self.get_poller_result(poller) - except CloudError as e: + except Exception as e: self.log('Error attempting to delete the vmextension.') self.fail("Error deleting the vmextension: {0}".format(str(e))) @@ -317,7 +317,7 @@ def get_vmextension(self): try: response = self.compute_client.virtual_machine_extensions.get(self.resource_group, self.virtual_machine_name, self.name) found = True - except CloudError as e: + except Exception as e: self.log('Did not find vm extension') if found: return vmextension_to_dict(response) diff --git a/plugins/modules/azure_rm_virtualmachineextension_info.py b/plugins/modules/azure_rm_virtualmachineextension_info.py index 5faed010e..b05b3ef3a 100644 --- a/plugins/modules/azure_rm_virtualmachineextension_info.py +++ b/plugins/modules/azure_rm_virtualmachineextension_info.py @@ -192,7 +192,7 @@ def get_extensions(self): vm_name=self.virtual_machine_name, vm_extension_name=self.name) self.log("Response : {0}".format(response)) - except CloudError as e: + except Exception as e: self.log('Could not get facts for Virtual Machine Extension.') if response and self.has_tags(response.tags, self.tags): @@ -207,7 +207,7 @@ def list_extensions(self): response = self.compute_client.virtual_machine_extensions.list(resource_group_name=self.resource_group, vm_name=self.virtual_machine_name) self.log("Response : {0}".format(response)) - except CloudError as e: + except Exception as e: self.log('Could not get facts for Virtual Machine Extension.') if response is not None and response.value is not None: diff --git a/plugins/modules/azure_rm_virtualmachineimage_info.py b/plugins/modules/azure_rm_virtualmachineimage_info.py index a41fb7bc0..053158186 100644 --- a/plugins/modules/azure_rm_virtualmachineimage_info.py +++ b/plugins/modules/azure_rm_virtualmachineimage_info.py @@ -186,7 +186,7 @@ def get_item(self): self.sku, top=1, orderby='name desc') - except CloudError: + except Exception: pass if self.version == 'latest': @@ -209,8 +209,6 @@ def list_images(self): self.publisher, self.offer, self.sku,) - except CloudError: - pass except Exception as exc: self.fail("Failed to list images: {0}".format(str(exc))) @@ -226,8 +224,6 @@ def list_offers(self): try: response = self.compute_client.virtual_machine_images.list_offers(self.location, self.publisher) - except CloudError: - pass except Exception as exc: self.fail("Failed to list offers: {0}".format(str(exc))) @@ -242,8 +238,6 @@ def list_publishers(self): results = [] try: response = self.compute_client.virtual_machine_images.list_publishers(self.location) - except CloudError: - pass except Exception as exc: self.fail("Failed to list publishers: {0}".format(str(exc))) diff --git a/plugins/modules/azure_rm_virtualmachinescaleset.py b/plugins/modules/azure_rm_virtualmachinescaleset.py index 6a16885b8..074b1224e 100644 --- a/plugins/modules/azure_rm_virtualmachinescaleset.py +++ b/plugins/modules/azure_rm_virtualmachinescaleset.py @@ -864,7 +864,7 @@ def exec_module(self, **kwargs): results = dict() changed = True - except CloudError: + except Exception: self.log('Virtual machine scale set {0} does not exist'.format(self.name)) if self.state == 'present': self.log("CHANGED: virtual machine scale set {0} does not exist but state is 'present'.".format(self.name)) @@ -1117,21 +1117,21 @@ def get_vmss(self): try: vmss = self.compute_client.virtual_machine_scale_sets.get(self.resource_group, self.name) return vmss - except CloudError as exc: + except Exception as exc: self.fail("Error getting virtual machine scale set {0} - {1}".format(self.name, str(exc))) def get_virtual_network(self, name): try: vnet = self.network_client.virtual_networks.get(self.virtual_network_resource_group, name) return vnet - except CloudError as exc: + except Exception as exc: self.fail("Error fetching virtual network {0} - {1}".format(name, str(exc))) def get_subnet(self, vnet_name, subnet_name): self.log("Fetching subnet {0} in virtual network {1}".format(subnet_name, vnet_name)) try: subnet = self.network_client.subnets.get(self.virtual_network_resource_group, vnet_name, subnet_name) - except CloudError as exc: + except Exception as exc: self.fail("Error: fetching subnet {0} in virtual network {1} - {2}".format( subnet_name, vnet_name, @@ -1142,14 +1142,14 @@ def get_load_balancer(self, id): id_dict = parse_resource_id(id) try: return self.network_client.load_balancers.get(id_dict.get('resource_group', self.resource_group), id_dict.get('name')) - except CloudError as exc: + except Exception as exc: self.fail("Error fetching load balancer {0} - {1}".format(id, str(exc))) def get_application_gateway(self, id): id_dict = parse_resource_id(id) try: return self.network_client.application_gateways.get(id_dict.get('resource_group', self.resource_group), id_dict.get('name')) - except CloudError as exc: + except Exception as exc: self.fail("Error fetching application_gateway {0} - {1}".format(id, str(exc))) def serialize_vmss(self, vmss): @@ -1173,10 +1173,10 @@ def delete_vmss(self, vmss): self.log("Deleting virtual machine scale set {0}".format(self.name)) self.results['actions'].append("Deleted virtual machine scale set {0}".format(self.name)) try: - poller = self.compute_client.virtual_machine_scale_sets.delete(self.resource_group, self.name) + poller = self.compute_client.virtual_machine_scale_sets.begin_delete(self.resource_group, self.name) # wait for the poller to finish self.get_poller_result(poller) - except CloudError as exc: + except Exception as exc: self.fail("Error deleting virtual machine scale set {0} - {1}".format(self.name, str(exc))) return True @@ -1187,7 +1187,7 @@ def get_marketplace_image_version(self): self.image['publisher'], self.image['offer'], self.image['sku']) - except CloudError as exc: + except Exception as exc: self.fail("Error fetching image {0} {1} {2} - {3}".format(self.image['publisher'], self.image['offer'], self.image['sku'], @@ -1222,9 +1222,9 @@ def get_custom_image_reference(self, name, resource_group=None): def create_or_update_vmss(self, params): try: - poller = self.compute_client.virtual_machine_scale_sets.create_or_update(self.resource_group, self.name, params) + poller = self.compute_client.virtual_machine_scale_sets.begin_create_or_update(self.resource_group, self.name, params) self.get_poller_result(poller) - except CloudError as exc: + except Exception as exc: self.fail("Error creating or updating virtual machine {0} - {1}".format(self.name, str(exc))) def vm_size_is_valid(self): @@ -1235,7 +1235,7 @@ def vm_size_is_valid(self): ''' try: sizes = self.compute_client.virtual_machine_sizes.list(self.location) - except CloudError as exc: + except Exception as exc: self.fail("Error retrieving available machine sizes - {0}".format(str(exc))) for size in sizes: if size.name == self.vm_size: diff --git a/plugins/modules/azure_rm_virtualmachinescaleset_info.py b/plugins/modules/azure_rm_virtualmachinescaleset_info.py index 587f24bfa..676174ef4 100644 --- a/plugins/modules/azure_rm_virtualmachinescaleset_info.py +++ b/plugins/modules/azure_rm_virtualmachinescaleset_info.py @@ -397,7 +397,7 @@ def get_item(self): try: item = self.compute_client.virtual_machine_scale_sets.get(self.resource_group, self.name) - except CloudError: + except Exception: pass if item and self.has_tags(item.tags, self.tags): @@ -412,7 +412,7 @@ def list_items(self): try: response = self.compute_client.virtual_machine_scale_sets.list(self.resource_group) - except CloudError as exc: + except Exception as exc: self.fail('Failed to list all items - {0}'.format(str(exc))) results = [] diff --git a/plugins/modules/azure_rm_virtualmachinescalesetextension.py b/plugins/modules/azure_rm_virtualmachinescalesetextension.py index 91ead15ad..601216157 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetextension.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetextension.py @@ -256,25 +256,25 @@ def create_or_update_vmssextension(self): settings=self.settings, protected_settings=self.protected_settings ) - poller = self.compute_client.virtual_machine_scale_set_extensions.create_or_update(resource_group_name=self.resource_group, - vm_scale_set_name=self.vmss_name, - vmss_extension_name=self.name, - extension_parameters=params) + poller = self.compute_client.virtual_machine_scale_set_extensions.begin_create_or_update(resource_group_name=self.resource_group, + vm_scale_set_name=self.vmss_name, + vmss_extension_name=self.name, + extension_parameters=params) response = self.get_poller_result(poller) return response.as_dict() - except CloudError as e: + except Exception as e: self.log('Error attempting to create the VMSS extension.') self.fail("Error creating the VMSS extension: {0}".format(str(e))) def delete_vmssextension(self): self.log("Deleting vmextension {0}".format(self.name)) try: - poller = self.compute_client.virtual_machine_scale_set_extensions.delete(resource_group_name=self.resource_group, - vm_scale_set_name=self.vmss_name, - vmss_extension_name=self.name) + poller = self.compute_client.virtual_machine_scale_set_extensions.begin_delete(resource_group_name=self.resource_group, + vm_scale_set_name=self.vmss_name, + vmss_extension_name=self.name) self.get_poller_result(poller) - except CloudError as e: + except Exception as e: self.log('Error attempting to delete the vmextension.') self.fail("Error deleting the vmextension: {0}".format(str(e))) @@ -283,7 +283,7 @@ def get_vmssextension(self): try: response = self.compute_client.virtual_machine_scale_set_extensions.get(self.resource_group, self.vmss_name, self.name) return response.as_dict() - except CloudError as e: + except Exception as e: self.log('Did not find VMSS extension') return False diff --git a/plugins/modules/azure_rm_virtualmachinescalesetextension_info.py b/plugins/modules/azure_rm_virtualmachinescalesetextension_info.py index fabd5af6a..6c42dba02 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetextension_info.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetextension_info.py @@ -174,7 +174,7 @@ def get_extensions(self): vm_scale_set_name=self.vmss_name, vmss_extension_name=self.name) self.log("Response : {0}".format(response)) - except CloudError as e: + except Exception as e: self.log('Could not get facts for Virtual Machine Extension.') if response: @@ -189,7 +189,7 @@ def list_extensions(self): response = self.compute_client.virtual_machine_scale_set_extensions.list(resource_group_name=self.resource_group, vm_scale_set_name=self.vmss_name) self.log("Response : {0}".format(response)) - except CloudError as e: + except Exception as e: self.log('Could not get facts for Virtual Machine Extension.') if response is not None: diff --git a/plugins/modules/azure_rm_virtualmachinescalesetinstance.py b/plugins/modules/azure_rm_virtualmachinescalesetinstance.py index 420b36e6b..e3cb74c5e 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetinstance.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetinstance.py @@ -160,7 +160,8 @@ def exec_module(self, **kwargs): setattr(self, key, kwargs[key]) self.mgmt_client = self.get_mgmt_svc_client(ComputeManagementClient, base_url=self._cloud_environment.endpoints.resource_manager, - api_version='2019-07-01') + is_track2=True, + api_version='2021-07-01') instances = self.get() @@ -213,7 +214,7 @@ def get(self): vm_scale_set_name=self.vmss_name, instance_id=self.instance_id) self.log("Response : {0}".format(response)) - except CloudError as e: + except Exception as e: self.log('Could not get facts for Virtual Machine Scale Set VM.') if response: @@ -223,47 +224,47 @@ def get(self): def apply_latest_model(self, instance_id): try: - poller = self.compute_client.virtual_machine_scale_sets.update_instances(resource_group_name=self.resource_group, - vm_scale_set_name=self.vmss_name, - instance_ids=[instance_id]) + poller = self.compute_client.virtual_machine_scale_sets.begin_update_instances(resource_group_name=self.resource_group, + vm_scale_set_name=self.vmss_name, + instance_ids=[instance_id]) self.get_poller_result(poller) - except CloudError as exc: + except Exception as exc: self.log("Error applying latest model {0} - {1}".format(self.vmss_name, str(exc))) self.fail("Error applying latest model {0} - {1}".format(self.vmss_name, str(exc))) def delete(self, instance_id): try: - self.mgmt_client.virtual_machine_scale_set_vms.delete(resource_group_name=self.resource_group, - vm_scale_set_name=self.vmss_name, - instance_id=instance_id) - except CloudError as e: + self.mgmt_client.virtual_machine_scale_set_vms.begin_delete(resource_group_name=self.resource_group, + vm_scale_set_name=self.vmss_name, + instance_id=instance_id) + except Exception as e: self.log('Could not delete instance of Virtual Machine Scale Set VM.') self.fail('Could not delete instance of Virtual Machine Scale Set VM.') def start(self, instance_id): try: - self.mgmt_client.virtual_machine_scale_set_vms.start(resource_group_name=self.resource_group, - vm_scale_set_name=self.vmss_name, - instance_id=instance_id) - except CloudError as e: + self.mgmt_client.virtual_machine_scale_set_vms.begin_start(resource_group_name=self.resource_group, + vm_scale_set_name=self.vmss_name, + instance_id=instance_id) + except Exception as e: self.log('Could not start instance of Virtual Machine Scale Set VM.') self.fail('Could not start instance of Virtual Machine Scale Set VM.') def stop(self, instance_id): try: - self.mgmt_client.virtual_machine_scale_set_vms.power_off(resource_group_name=self.resource_group, - vm_scale_set_name=self.vmss_name, - instance_id=instance_id) - except CloudError as e: + self.mgmt_client.virtual_machine_scale_set_vms.begin_power_off(resource_group_name=self.resource_group, + vm_scale_set_name=self.vmss_name, + instance_id=instance_id) + except Exception as e: self.log('Could not stop instance of Virtual Machine Scale Set VM.') self.fail('Could not stop instance of Virtual Machine Scale Set VM.') def deallocate(self, instance_id): try: - self.mgmt_client.virtual_machine_scale_set_vms.deallocate(resource_group_name=self.resource_group, + self.mgmt_client.virtual_machine_scale_set_vms.begin_deallocate(resource_group_name=self.resource_group, vm_scale_set_name=self.vmss_name, instance_id=instance_id) - except CloudError as e: + except Exception as e: self.log('Could not deallocate instance of Virtual Machine Scale Set VM.') self.fail('Could not deallocate instance of Virtual Machine Scale Set VM.') @@ -284,7 +285,7 @@ def update_protection_policy(self, instance_id, protect_from_scale_in, protect_f instance_id=instance_id, parameters=instance) self.get_poller_result(poller) - except CloudError as e: + except Exception as e: self.log('Could not update instance protection policy.') self.fail('Could not update instance protection policy.') diff --git a/plugins/modules/azure_rm_virtualmachinesize_info.py b/plugins/modules/azure_rm_virtualmachinesize_info.py index 3e2f6af1b..2aaae5beb 100644 --- a/plugins/modules/azure_rm_virtualmachinesize_info.py +++ b/plugins/modules/azure_rm_virtualmachinesize_info.py @@ -135,7 +135,7 @@ def list_items_by_location(self): self.log('List items by location') try: items = self.compute_client.virtual_machine_sizes.list(location=self.location) - except CloudError as exc: + except Exception as exc: self.fail("Failed to list items - {0}".format(str(exc))) return [self.serialize_size(item) for item in items if self.name is None or self.name == item.name] diff --git a/requirements-azure.txt b/requirements-azure.txt index b2b73896f..667453f30 100644 --- a/requirements-azure.txt +++ b/requirements-azure.txt @@ -8,7 +8,7 @@ azure-mgmt-apimanagement==0.2.0 azure-mgmt-authorization==0.51.1 azure-mgmt-batch==5.0.1 azure-mgmt-cdn==3.0.0 -azure-mgmt-compute==10.0.0 +azure-mgmt-compute==23.1.0 azure-mgmt-containerinstance==1.4.0 azure-mgmt-containerregistry==2.0.0 azure-mgmt-containerservice==9.1.0 From 39dc0dddec56af8f442cdb31663a24736c45d57d Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Mon, 1 Nov 2021 17:45:28 +0800 Subject: [PATCH 02/19] fix small --- plugins/module_utils/azure_rm_common.py | 1 - plugins/modules/azure_rm_image.py | 2 -- plugins/modules/azure_rm_virtualmachinescalesetinstance.py | 4 ++-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/module_utils/azure_rm_common.py b/plugins/module_utils/azure_rm_common.py index 73a639921..218de8c93 100644 --- a/plugins/module_utils/azure_rm_common.py +++ b/plugins/module_utils/azure_rm_common.py @@ -234,7 +234,6 @@ def default_api_version(self): from azure.common.credentials import ServicePrincipalCredentials, UserPassCredentials from azure.mgmt.network.version import VERSION as network_client_version from azure.mgmt.storage.version import VERSION as storage_client_version - from azure.mgmt.compute.version import VERSION as compute_client_version from azure.mgmt.resource.version import VERSION as resource_client_version from azure.mgmt.dns.version import VERSION as dns_client_version from azure.mgmt.web.version import VERSION as web_client_version diff --git a/plugins/modules/azure_rm_image.py b/plugins/modules/azure_rm_image.py index cf006e844..ce9dcebd1 100644 --- a/plugins/modules/azure_rm_image.py +++ b/plugins/modules/azure_rm_image.py @@ -334,8 +334,6 @@ def _get_resource(self, get_method, resource_group, name, expand=None): self.log('{0}'.format(str(cloud_err))) return None self.fail('Error: failed to get resource {0} - {1}'.format(name, str(cloud_err))) - except Exception as exc: - self.fail('Error: failed to get resource {0} - {1}'.format(name, str(exc))) def create_image(self, image): try: diff --git a/plugins/modules/azure_rm_virtualmachinescalesetinstance.py b/plugins/modules/azure_rm_virtualmachinescalesetinstance.py index e3cb74c5e..78a2709de 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetinstance.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetinstance.py @@ -262,8 +262,8 @@ def stop(self, instance_id): def deallocate(self, instance_id): try: self.mgmt_client.virtual_machine_scale_set_vms.begin_deallocate(resource_group_name=self.resource_group, - vm_scale_set_name=self.vmss_name, - instance_id=instance_id) + vm_scale_set_name=self.vmss_name, + instance_id=instance_id) except Exception as e: self.log('Could not deallocate instance of Virtual Machine Scale Set VM.') self.fail('Could not deallocate instance of Virtual Machine Scale Set VM.') From 311e02e513c17c8a0985bd0bae1edcdce1ac26e3 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Mon, 1 Nov 2021 19:36:47 +0800 Subject: [PATCH 03/19] Modify version from v2021-07-01 to v2020-04-01, no disk encryptions operation --- plugins/module_utils/azure_rm_common.py | 8 ++++---- plugins/modules/azure_rm_availabilityset.py | 4 ++-- plugins/modules/azure_rm_virtualmachine.py | 2 +- .../modules/azure_rm_virtualmachinescalesetinstance.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/module_utils/azure_rm_common.py b/plugins/module_utils/azure_rm_common.py index 218de8c93..e1c75be15 100644 --- a/plugins/module_utils/azure_rm_common.py +++ b/plugins/module_utils/azure_rm_common.py @@ -1084,13 +1084,13 @@ def image_client(self): self._image_client = self.get_mgmt_svc_client(ComputeManagementClient, base_url=self._cloud_environment.endpoints.resource_manager, is_track2=True, - api_version='2021-07-01') + api_version='2021-04-01') return self._image_client @property def image_models(self): self.log("Getting compute image models") - return ComputeManagementClient.models("2021-07-01") + return ComputeManagementClient.models("2021-04-01") @property def compute_client(self): @@ -1099,13 +1099,13 @@ def compute_client(self): self._compute_client = self.get_mgmt_svc_client(ComputeManagementClient, base_url=self._cloud_environment.endpoints.resource_manager, is_track2=True, - api_version='2021-07-01') + api_version='2021-04-01') return self._compute_client @property def compute_models(self): self.log("Getting compute models") - return ComputeManagementClient.models("2021-07-01") + return ComputeManagementClient.models("2021-04-01") @property def dns_client(self): diff --git a/plugins/modules/azure_rm_availabilityset.py b/plugins/modules/azure_rm_availabilityset.py index a7cce2321..76f7b7519 100644 --- a/plugins/modules/azure_rm_availabilityset.py +++ b/plugins/modules/azure_rm_availabilityset.py @@ -326,7 +326,7 @@ def create_or_update_availabilityset(self): proximity_placement_group=self.proximity_placement_group_resource, sku=params_sku ) - response = self.compute_client.availability_sets.begin_create_or_update(self.resource_group, self.name, params) + response = self.compute_client.availability_sets.create_or_update(self.resource_group, self.name, params) except Exception as e: self.log('Error attempting to create the availability set.') self.fail("Error creating the availability set: {0}".format(str(e))) @@ -340,7 +340,7 @@ def delete_availabilityset(self): ''' self.log("Deleting availabilityset {0}".format(self.name)) try: - response = self.compute_client.availability_sets.begin_delete(self.resource_group, self.name) + response = self.compute_client.availability_sets.delete(self.resource_group, self.name) except Exception as e: self.log('Error attempting to delete the availability set.') self.fail("Error deleting the availability set: {0}".format(str(e))) diff --git a/plugins/modules/azure_rm_virtualmachine.py b/plugins/modules/azure_rm_virtualmachine.py index d4052a94c..d1cc807b2 100644 --- a/plugins/modules/azure_rm_virtualmachine.py +++ b/plugins/modules/azure_rm_virtualmachine.py @@ -1264,7 +1264,7 @@ def exec_module(self, **kwargs): results = dict() changed = True - except CloudError: + except Exception: self.log('Virtual machine {0} does not exist'.format(self.name)) if self.state == 'present': self.log("CHANGED: virtual machine {0} does not exist but state is 'present'.".format(self.name)) diff --git a/plugins/modules/azure_rm_virtualmachinescalesetinstance.py b/plugins/modules/azure_rm_virtualmachinescalesetinstance.py index 78a2709de..5e4b87c9b 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetinstance.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetinstance.py @@ -161,7 +161,7 @@ def exec_module(self, **kwargs): self.mgmt_client = self.get_mgmt_svc_client(ComputeManagementClient, base_url=self._cloud_environment.endpoints.resource_manager, is_track2=True, - api_version='2021-07-01') + api_version='2021-04-01') instances = self.get() From 8b239c090e5cb7e7068e9c68a235d7dd099676a0 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Mon, 1 Nov 2021 19:49:49 +0800 Subject: [PATCH 04/19] Update small --- plugins/modules/azure_rm_proximityplacementgroup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/modules/azure_rm_proximityplacementgroup.py b/plugins/modules/azure_rm_proximityplacementgroup.py index a8b5e71aa..f39f542e8 100644 --- a/plugins/modules/azure_rm_proximityplacementgroup.py +++ b/plugins/modules/azure_rm_proximityplacementgroup.py @@ -222,9 +222,9 @@ def exec_module(self, **kwargs): def create_or_update_placementgroup(self, proximity_placement_group): try: # create the placement group - response = self.compute_client.proximity_placement_groups.begin_create_or_update(resource_group_name=self.resource_group, - proximity_placement_group_name=self.name, - parameters=proximity_placement_group) + response = self.compute_client.proximity_placement_groups.create_or_update(resource_group_name=self.resource_group, + proximity_placement_group_name=self.name, + parameters=proximity_placement_group) except Exception as exc: self.fail("Error creating or updating proximity placement group {0} - {1}".format(self.name, str(exc))) return self.ppg_to_dict(response) @@ -232,8 +232,8 @@ def create_or_update_placementgroup(self, proximity_placement_group): def delete_placementgroup(self): try: # delete the placement group - response = self.compute_client.proximity_placement_groups.begin_delete(resource_group_name=self.resource_group, - proximity_placement_group_name=self.name) + response = self.compute_client.proximity_placement_groups.delete(resource_group_name=self.resource_group, + proximity_placement_group_name=self.name) except Exception as exc: self.fail("Error deleting proximity placement group {0} - {1}".format(self.name, str(exc))) return response From 42c2234a3e5947b1c97df73da6ff27790a200d69 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Mon, 1 Nov 2021 20:42:02 +0800 Subject: [PATCH 05/19] fix azure_rm_diskencryption test fail --- plugins/modules/azure_rm_diskencryptionset.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/modules/azure_rm_diskencryptionset.py b/plugins/modules/azure_rm_diskencryptionset.py index 03fe4637d..90221276d 100644 --- a/plugins/modules/azure_rm_diskencryptionset.py +++ b/plugins/modules/azure_rm_diskencryptionset.py @@ -298,8 +298,7 @@ def delete_diskencryptionset(self): # delete the disk encryption set response = self.compute_client.disk_encryption_sets.begin_delete(resource_group_name=self.resource_group, disk_encryption_set_name=self.name) - if isinstance(response, LROPoller): - response = self.get_poller_result(response) + response = self.get_poller_result(response) except Exception as exc: self.fail("Error deleting disk encryption set {0} - {1}".format(self.name, str(exc))) return response From faa0a43712c6944f665cc1f7a316b7e4cec28956 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Mon, 1 Nov 2021 21:17:52 +0800 Subject: [PATCH 06/19] fix azure_rm_diskencryption test fail02 --- plugins/modules/azure_rm_diskencryptionset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/azure_rm_diskencryptionset.py b/plugins/modules/azure_rm_diskencryptionset.py index 90221276d..36d2ccf93 100644 --- a/plugins/modules/azure_rm_diskencryptionset.py +++ b/plugins/modules/azure_rm_diskencryptionset.py @@ -304,7 +304,7 @@ def delete_diskencryptionset(self): return response def diskencryptionset_to_dict(self, diskencryptionset): - result = diskencryptionset.as_dict() + # result = diskencryptionset.as_dict() result['tags'] = diskencryptionset.tags return result From 00282e5b7034fe30989e6e634b4ac29fb8f7da61 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Tue, 2 Nov 2021 09:28:28 +0800 Subject: [PATCH 07/19] fix sanity error --- plugins/modules/azure_rm_diskencryptionset.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/modules/azure_rm_diskencryptionset.py b/plugins/modules/azure_rm_diskencryptionset.py index 36d2ccf93..af8562b68 100644 --- a/plugins/modules/azure_rm_diskencryptionset.py +++ b/plugins/modules/azure_rm_diskencryptionset.py @@ -304,8 +304,16 @@ def delete_diskencryptionset(self): return response def diskencryptionset_to_dict(self, diskencryptionset): - # result = diskencryptionset.as_dict() - result['tags'] = diskencryptionset.tags + result = dict( + id=diskencryptionset.id, + name=diskencryptionset.name, + location=diskencryptionset.location, + tags=diskencryptionset.tags, + active_key=diskencryptionset.active_key.as_dict(), + provisioning_state=diskencryptionset.provisioning_state, + identity=diskencryptionset.identity.as_dict(), + type=diskencryptionset.type + ) return result From 51154c64a8604deb1d7b168cbd1eb5d66f9b2981 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Tue, 2 Nov 2021 13:58:39 +0800 Subject: [PATCH 08/19] fix azure_rm_diskcryptionset test fail --- plugins/modules/azure_rm_diskencryptionset.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/plugins/modules/azure_rm_diskencryptionset.py b/plugins/modules/azure_rm_diskencryptionset.py index af8562b68..93142f500 100644 --- a/plugins/modules/azure_rm_diskencryptionset.py +++ b/plugins/modules/azure_rm_diskencryptionset.py @@ -287,8 +287,7 @@ def create_or_update_diskencryptionset(self, disk_encryption_set): self.compute_client.disk_encryption_sets.begin_create_or_update(resource_group_name=self.resource_group, disk_encryption_set_name=self.name, disk_encryption_set=disk_encryption_set) - if isinstance(response, LROPoller): - response = self.get_poller_result(response) + response = self.get_poller_result(response) except Exception as exc: self.fail("Error creating or updating disk encryption set {0} - {1}".format(self.name, str(exc))) return self.diskencryptionset_to_dict(response) @@ -304,16 +303,8 @@ def delete_diskencryptionset(self): return response def diskencryptionset_to_dict(self, diskencryptionset): - result = dict( - id=diskencryptionset.id, - name=diskencryptionset.name, - location=diskencryptionset.location, - tags=diskencryptionset.tags, - active_key=diskencryptionset.active_key.as_dict(), - provisioning_state=diskencryptionset.provisioning_state, - identity=diskencryptionset.identity.as_dict(), - type=diskencryptionset.type - ) + result = diskencryptionset.as_dict() + result['tags'] = diskencryptionset.tags return result From adbc8c16a735bb1105c40f20cd8391c86029559d Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Tue, 2 Nov 2021 16:02:26 +0800 Subject: [PATCH 09/19] fix azure_rm_virtualmachinescalesetinstance_info bug --- .../modules/azure_rm_virtualmachinescalesetinstance_info.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py b/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py index 7044460f9..c30049e1f 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py @@ -163,7 +163,9 @@ 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(ComputeManagementClient, - base_url=self._cloud_environment.endpoints.resource_manager) + base_url=self._cloud_environment.endpoints.resource_manager + is_track2=True, + api_version='2021-04-01') if (self.instance_id is None): self.results['instances'] = self.list() From 884809426bb4ecad9477e9fbedbdc76a4e2b70f3 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Tue, 2 Nov 2021 16:30:15 +0800 Subject: [PATCH 10/19] fix azure_rm_virtualmachinescalesetinstance_info bug 02 --- plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py b/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py index c30049e1f..edf9b0d48 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py @@ -163,7 +163,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(ComputeManagementClient, - base_url=self._cloud_environment.endpoints.resource_manager + base_url=self._cloud_environment.endpoints.resource_manager, is_track2=True, api_version='2021-04-01') From b1a31cac91d1d953a07c393a291e760e69ee6be9 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Wed, 3 Nov 2021 17:26:46 +0800 Subject: [PATCH 11/19] fix azure_rm_virtualmachien*extension test fail --- plugins/modules/azure_rm_virtualmachineextension.py | 4 ++-- plugins/modules/azure_rm_virtualmachineextension_info.py | 2 +- plugins/modules/azure_rm_virtualmachinescalesetextension.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/modules/azure_rm_virtualmachineextension.py b/plugins/modules/azure_rm_virtualmachineextension.py index c0fee458a..6826829b0 100644 --- a/plugins/modules/azure_rm_virtualmachineextension.py +++ b/plugins/modules/azure_rm_virtualmachineextension.py @@ -127,7 +127,7 @@ def vmextension_to_dict(extension): name=extension.name, location=extension.location, publisher=extension.publisher, - virtual_machine_extension_type=extension.virtual_machine_extension_type, + virtual_machine_extension_type=extension.type_properties_type, type_handler_version=extension.type_handler_version, auto_upgrade_minor_version=extension.auto_upgrade_minor_version, settings=extension.settings, @@ -280,7 +280,7 @@ def create_or_update_vmextension(self): params = self.compute_models.VirtualMachineExtension( location=self.location, publisher=self.publisher, - virtual_machine_extension_type=self.virtual_machine_extension_type, + type_properties_type=self.virtual_machine_extension_type, type_handler_version=self.type_handler_version, auto_upgrade_minor_version=self.auto_upgrade_minor_version, settings=self.settings, diff --git a/plugins/modules/azure_rm_virtualmachineextension_info.py b/plugins/modules/azure_rm_virtualmachineextension_info.py index b05b3ef3a..e575913ad 100644 --- a/plugins/modules/azure_rm_virtualmachineextension_info.py +++ b/plugins/modules/azure_rm_virtualmachineextension_info.py @@ -226,7 +226,7 @@ def format_response(self, item): 'location': d.get('location'), 'name': d.get('name'), 'publisher': d.get('publisher'), - 'type': d.get('virtual_machine_extension_type'), + 'type': d.get('type_properties_type'), 'settings': d.get('settings'), 'auto_upgrade_minor_version': d.get('auto_upgrade_minor_version'), 'tags': d.get('tags', None), diff --git a/plugins/modules/azure_rm_virtualmachinescalesetextension.py b/plugins/modules/azure_rm_virtualmachinescalesetextension.py index 601216157..d74fe7248 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetextension.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetextension.py @@ -250,7 +250,7 @@ def create_or_update_vmssextension(self): params = self.compute_models.VirtualMachineScaleSetExtension( location=self.location, publisher=self.publisher, - type=self.type, + type_properties_type=self.type, type_handler_version=self.type_handler_version, auto_upgrade_minor_version=self.auto_upgrade_minor_version, settings=self.settings, From f9e468688f6b13e6f74617da26985d5c62995d6e Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Thu, 4 Nov 2021 10:02:42 +0800 Subject: [PATCH 12/19] Update azure_rm_virtualmachinescalesetinstance func paramter to vm_instance_i_ds --- plugins/modules/azure_rm_virtualmachinescalesetinstance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/azure_rm_virtualmachinescalesetinstance.py b/plugins/modules/azure_rm_virtualmachinescalesetinstance.py index 5e4b87c9b..c93363af7 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetinstance.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetinstance.py @@ -226,7 +226,7 @@ def apply_latest_model(self, instance_id): try: poller = self.compute_client.virtual_machine_scale_sets.begin_update_instances(resource_group_name=self.resource_group, vm_scale_set_name=self.vmss_name, - instance_ids=[instance_id]) + vm_instance_i_ds=[instance_id]) self.get_poller_result(poller) except Exception as exc: self.log("Error applying latest model {0} - {1}".format(self.vmss_name, str(exc))) @@ -280,7 +280,7 @@ def update_protection_policy(self, instance_id, protect_from_scale_in, protect_f vm_scale_set_name=self.vmss_name, instance_id=instance_id) instance.protection_policy = protection_policy - poller = self.mgmt_client.virtual_machine_scale_set_vms.update(resource_group_name=self.resource_group, + poller = self.mgmt_client.virtual_machine_scale_set_vms.begin_update(resource_group_name=self.resource_group, vm_scale_set_name=self.vmss_name, instance_id=instance_id, parameters=instance) From dcd5063918eb154b11752b571c69ea35d995825a Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Thu, 4 Nov 2021 13:53:59 +0800 Subject: [PATCH 13/19] fix azure_rm_virtualmachinescalesetinstance test fail --- .../modules/azure_rm_virtualmachinescalesetinstance.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/modules/azure_rm_virtualmachinescalesetinstance.py b/plugins/modules/azure_rm_virtualmachinescalesetinstance.py index c93363af7..ccc6bf496 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetinstance.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetinstance.py @@ -176,7 +176,7 @@ def exec_module(self, **kwargs): for item in instances: if not item.get('latest_model', None): if not self.check_mode: - self.apply_latest_model(item['instance_id']) + self.apply_latest_model([item['instance_id']]) item['latest_model'] = True self.results['changed'] = True @@ -226,7 +226,7 @@ def apply_latest_model(self, instance_id): try: poller = self.compute_client.virtual_machine_scale_sets.begin_update_instances(resource_group_name=self.resource_group, vm_scale_set_name=self.vmss_name, - vm_instance_i_ds=[instance_id]) + vm_instance_i_ds={'instance_ids':instance_id}) self.get_poller_result(poller) except Exception as exc: self.log("Error applying latest model {0} - {1}".format(self.vmss_name, str(exc))) @@ -281,9 +281,9 @@ def update_protection_policy(self, instance_id, protect_from_scale_in, protect_f instance_id=instance_id) instance.protection_policy = protection_policy poller = self.mgmt_client.virtual_machine_scale_set_vms.begin_update(resource_group_name=self.resource_group, - vm_scale_set_name=self.vmss_name, - instance_id=instance_id, - parameters=instance) + vm_scale_set_name=self.vmss_name, + instance_id=instance_id, + parameters=instance) self.get_poller_result(poller) except Exception as e: self.log('Could not update instance protection policy.') From b2e3054232ae06908e781dc20a509bf12859866c Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Thu, 4 Nov 2021 14:26:50 +0800 Subject: [PATCH 14/19] fix sanity test fail --- plugins/modules/azure_rm_virtualmachinescalesetinstance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/azure_rm_virtualmachinescalesetinstance.py b/plugins/modules/azure_rm_virtualmachinescalesetinstance.py index ccc6bf496..26fd1d595 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetinstance.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetinstance.py @@ -226,7 +226,7 @@ def apply_latest_model(self, instance_id): try: poller = self.compute_client.virtual_machine_scale_sets.begin_update_instances(resource_group_name=self.resource_group, vm_scale_set_name=self.vmss_name, - vm_instance_i_ds={'instance_ids':instance_id}) + vm_instance_i_ds={'instance_ids': instance_id}) self.get_poller_result(poller) except Exception as exc: self.log("Error applying latest model {0} - {1}".format(self.vmss_name, str(exc))) From 00770e4a77744f5e843e6b0ffb5c393d9792a8d5 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Fri, 5 Nov 2021 09:52:36 +0800 Subject: [PATCH 15/19] change exception type --- .../modules/azure_rm_virtualmachinescalesetinstance_info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py b/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py index edf9b0d48..cb72ed84b 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py @@ -181,7 +181,7 @@ def get(self): vm_scale_set_name=self.vmss_name, instance_id=self.instance_id) self.log("Response : {0}".format(response)) - except CloudError as e: + except Exception as e: self.log('Could not get facts for Virtual Machine Scale Set VM.') if response and self.has_tags(response.tags, self.tags): @@ -195,7 +195,7 @@ def list(self): items = self.mgmt_client.virtual_machine_scale_set_vms.list(resource_group_name=self.resource_group, virtual_machine_scale_set_name=self.vmss_name) self.log("Response : {0}".format(items)) - except CloudError as e: + except Exception as e: self.log('Could not get facts for Virtual Machine ScaleSet VM.') results = [] From f147c2b59dd085b2004b0f9c9cf5ffdefe88190b Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Wed, 29 Dec 2021 17:33:41 +0800 Subject: [PATCH 16/19] fix azure_rm_hostgroup module --- plugins/modules/azure_rm_hostgroup.py | 2 +- plugins/modules/azure_rm_hostgroup_info.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/modules/azure_rm_hostgroup.py b/plugins/modules/azure_rm_hostgroup.py index e09127303..2f44b8012 100644 --- a/plugins/modules/azure_rm_hostgroup.py +++ b/plugins/modules/azure_rm_hostgroup.py @@ -226,7 +226,7 @@ def exec_module(self, **kwargs): elif self.state == 'absent': changed = True - except CloudError: + except Exception: if self.state == 'present': changed = True else: diff --git a/plugins/modules/azure_rm_hostgroup_info.py b/plugins/modules/azure_rm_hostgroup_info.py index d9d4d650a..5d89bbd8e 100644 --- a/plugins/modules/azure_rm_hostgroup_info.py +++ b/plugins/modules/azure_rm_hostgroup_info.py @@ -139,7 +139,7 @@ def get_item(self): # get specific host group try: item = self.compute_client.dedicated_host_groups.get(self.resource_group, self.name) - except CloudError: + except Exception: pass # serialize result @@ -151,7 +151,7 @@ def list_resource_group(self): self.log('List all host groups for resource group - {0}'.format(self.resource_group)) try: response = self.compute_client.dedicated_host_groups.list_by_resource_group(self.resource_group) - except AzureHttpError as exc: + except Exception as exc: self.fail("Failed to list for resource group {0} - {1}".format(self.resource_group, str(exc))) results = [] @@ -164,7 +164,7 @@ def list_items(self): self.log('List all host groups for a subscription ') try: response = self.compute_client.dedicated_host_groups.list_by_subscription() - except AzureHttpError as exc: + except Exception as exc: self.fail("Failed to list all items - {0}".format(str(exc))) results = [] From 02099088c3a50e504c141ff0795b927268265b0a Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Fri, 14 Jan 2022 16:02:07 +0800 Subject: [PATCH 17/19] Update the code that throws the exception --- plugins/modules/azure_rm_availabilityset.py | 6 +++--- .../modules/azure_rm_availabilityset_info.py | 6 +++--- plugins/modules/azure_rm_diskencryptionset.py | 12 +++++++----- .../azure_rm_diskencryptionset_info.py | 9 ++++----- plugins/modules/azure_rm_hostgroup.py | 4 ++-- plugins/modules/azure_rm_hostgroup_info.py | 9 ++++----- plugins/modules/azure_rm_image.py | 4 ++-- plugins/modules/azure_rm_image_info.py | 8 ++++---- plugins/modules/azure_rm_manageddisk.py | 4 ++-- plugins/modules/azure_rm_manageddisk_info.py | 8 ++++---- .../azure_rm_proximityplacementgroup.py | 5 ++--- .../azure_rm_proximityplacementgroup_info.py | 9 ++++----- plugins/modules/azure_rm_virtualmachine.py | 15 ++++++++------- .../modules/azure_rm_virtualmachine_info.py | 8 ++++---- .../azure_rm_virtualmachineextension.py | 4 ++-- .../azure_rm_virtualmachineextension_info.py | 6 +++--- .../azure_rm_virtualmachineimage_info.py | 10 +++++----- .../azure_rm_virtualmachinescaleset.py | 19 ++++++++++--------- .../azure_rm_virtualmachinescaleset_info.py | 6 +++--- ...zure_rm_virtualmachinescalesetextension.py | 4 ++-- ...rm_virtualmachinescalesetextension_info.py | 6 +++--- ...azure_rm_virtualmachinescalesetinstance.py | 4 ++-- ..._rm_virtualmachinescalesetinstance_info.py | 6 +++--- .../azure_rm_virtualmachinesize_info.py | 4 ++-- 24 files changed, 88 insertions(+), 88 deletions(-) diff --git a/plugins/modules/azure_rm_availabilityset.py b/plugins/modules/azure_rm_availabilityset.py index 76f7b7519..e401869d9 100644 --- a/plugins/modules/azure_rm_availabilityset.py +++ b/plugins/modules/azure_rm_availabilityset.py @@ -152,8 +152,8 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: - from msrestazure.azure_exceptions import CloudError from msrestazure.tools import parse_resource_id + from azure.core.exceptions import ResourceNotFoundError except ImportError: # This is handled in azure_rm_common pass @@ -357,7 +357,7 @@ def get_availabilityset(self): try: response = self.compute_client.availability_sets.get(self.resource_group, self.name) found = True - except Exception as e: + except ResourceNotFoundError as e: self.log('Did not find the Availability set.') if found is True: return availability_set_to_dict(response) @@ -367,7 +367,7 @@ def get_availabilityset(self): def get_proximity_placement_group(self, resource_group, name): try: return self.compute_client.proximity_placement_groups.get(resource_group, name) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Error fetching proximity placement group {0} - {1}".format(name, str(exc))) diff --git a/plugins/modules/azure_rm_availabilityset_info.py b/plugins/modules/azure_rm_availabilityset_info.py index 39a0eef34..1ca0f5353 100644 --- a/plugins/modules/azure_rm_availabilityset_info.py +++ b/plugins/modules/azure_rm_availabilityset_info.py @@ -104,7 +104,7 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError except Exception: # handled in azure_rm_common pass @@ -169,7 +169,7 @@ def get_item(self): try: item = self.compute_client.availability_sets.get(self.resource_group, self.name) - except Exception: + except ResourceNotFoundError: pass if item and self.has_tags(item.tags, self.tags): @@ -188,7 +188,7 @@ def list_items(self): try: response = self.compute_client.availability_sets.list(self.resource_group) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail('Failed to list all items - {0}'.format(str(exc))) results = [] diff --git a/plugins/modules/azure_rm_diskencryptionset.py b/plugins/modules/azure_rm_diskencryptionset.py index 93142f500..93bd8ab47 100644 --- a/plugins/modules/azure_rm_diskencryptionset.py +++ b/plugins/modules/azure_rm_diskencryptionset.py @@ -157,8 +157,8 @@ format_resource_id, normalize_location_name try: - from msrestazure.azure_exceptions import CloudError - from msrest.polling import LROPoller + from azure.core.polling import LROPoller + from azure.core.exceptions import ResourceNotFoundError except ImportError: # This is handled in azure_rm_common pass @@ -245,7 +245,7 @@ def exec_module(self, **kwargs): elif self.state == 'absent': changed = True - except Exception: + except ResourceNotFoundError: if self.state == 'present': changed = True else: @@ -287,7 +287,8 @@ def create_or_update_diskencryptionset(self, disk_encryption_set): self.compute_client.disk_encryption_sets.begin_create_or_update(resource_group_name=self.resource_group, disk_encryption_set_name=self.name, disk_encryption_set=disk_encryption_set) - response = self.get_poller_result(response) + if isinstance(response, LROPoller): + response = self.get_poller_result(response) except Exception as exc: self.fail("Error creating or updating disk encryption set {0} - {1}".format(self.name, str(exc))) return self.diskencryptionset_to_dict(response) @@ -297,7 +298,8 @@ def delete_diskencryptionset(self): # delete the disk encryption set response = self.compute_client.disk_encryption_sets.begin_delete(resource_group_name=self.resource_group, disk_encryption_set_name=self.name) - response = self.get_poller_result(response) + if isinstance(response, LROPoller): + response = self.get_poller_result(response) except Exception as exc: self.fail("Error deleting disk encryption set {0} - {1}".format(self.name, str(exc))) return response diff --git a/plugins/modules/azure_rm_diskencryptionset_info.py b/plugins/modules/azure_rm_diskencryptionset_info.py index 31e9fc342..3be47dc44 100644 --- a/plugins/modules/azure_rm_diskencryptionset_info.py +++ b/plugins/modules/azure_rm_diskencryptionset_info.py @@ -89,8 +89,7 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: - from msrestazure.azure_exceptions import CloudError - from azure.common import AzureMissingResourceHttpError, AzureHttpError + from azure.core.exceptions import ResourceNotFoundError except Exception: # This is handled in azure_rm_common pass @@ -148,7 +147,7 @@ def get_item(self): # get specific disk encryption set try: item = self.compute_client.disk_encryption_sets.get(self.resource_group, self.name) - except Exception: + except ResourceNotFoundError: pass # serialize result @@ -160,7 +159,7 @@ def list_resource_group(self): self.log('List all disk encryption sets for resource group - {0}'.format(self.resource_group)) try: response = self.compute_client.disk_encryption_sets.list_by_resource_group(self.resource_group) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Failed to list for resource group {0} - {1}".format(self.resource_group, str(exc))) results = [] @@ -173,7 +172,7 @@ def list_items(self): self.log('List all disk encryption sets for a subscription ') try: response = self.compute_client.disk_encryption_sets.list() - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Failed to list all items - {0}".format(str(exc))) results = [] diff --git a/plugins/modules/azure_rm_hostgroup.py b/plugins/modules/azure_rm_hostgroup.py index 2f44b8012..d7e80bf14 100644 --- a/plugins/modules/azure_rm_hostgroup.py +++ b/plugins/modules/azure_rm_hostgroup.py @@ -147,7 +147,7 @@ normalize_location_name try: - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError except ImportError: # This is handled in azure_rm_common pass @@ -226,7 +226,7 @@ def exec_module(self, **kwargs): elif self.state == 'absent': changed = True - except Exception: + except ResourceNotFoundError: if self.state == 'present': changed = True else: diff --git a/plugins/modules/azure_rm_hostgroup_info.py b/plugins/modules/azure_rm_hostgroup_info.py index 5d89bbd8e..1c27bd5a3 100644 --- a/plugins/modules/azure_rm_hostgroup_info.py +++ b/plugins/modules/azure_rm_hostgroup_info.py @@ -80,8 +80,7 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: - from msrestazure.azure_exceptions import CloudError - from azure.common import AzureMissingResourceHttpError, AzureHttpError + from azure.core.exceptions import ResourceNotFoundError except Exception: # This is handled in azure_rm_common pass @@ -139,7 +138,7 @@ def get_item(self): # get specific host group try: item = self.compute_client.dedicated_host_groups.get(self.resource_group, self.name) - except Exception: + except ResourceNotFoundError: pass # serialize result @@ -151,7 +150,7 @@ def list_resource_group(self): self.log('List all host groups for resource group - {0}'.format(self.resource_group)) try: response = self.compute_client.dedicated_host_groups.list_by_resource_group(self.resource_group) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Failed to list for resource group {0} - {1}".format(self.resource_group, str(exc))) results = [] @@ -164,7 +163,7 @@ def list_items(self): self.log('List all host groups for a subscription ') try: response = self.compute_client.dedicated_host_groups.list_by_subscription() - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Failed to list all items - {0}".format(str(exc))) results = [] diff --git a/plugins/modules/azure_rm_image.py b/plugins/modules/azure_rm_image.py index ce9dcebd1..32a254369 100644 --- a/plugins/modules/azure_rm_image.py +++ b/plugins/modules/azure_rm_image.py @@ -113,7 +113,7 @@ try: from msrestazure.tools import parse_resource_id - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError except ImportError: # This is handled in azure_rm_common pass @@ -328,7 +328,7 @@ def _get_resource(self, get_method, resource_group, name, expand=None): return get_method(resource_group, name, expand=expand) else: return get_method(resource_group, name) - except Exception as cloud_err: + except ResourceNotFoundError as cloud_err: # Return None iff the resource is not found if cloud_err.status_code == 404: self.log('{0}'.format(str(cloud_err))) diff --git a/plugins/modules/azure_rm_image_info.py b/plugins/modules/azure_rm_image_info.py index 798b52b02..5b1bb6522 100644 --- a/plugins/modules/azure_rm_image_info.py +++ b/plugins/modules/azure_rm_image_info.py @@ -164,7 +164,7 @@ try: - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError except Exception: # This is handled in azure_rm_common pass @@ -231,7 +231,7 @@ def get_image(self, resource_group, image_name): item = None try: item = self.image_client.images.get(resource_group, image_name) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail('Failed to list images - {0}'.format(str(exc))) result = [self.format_item(item)] @@ -246,7 +246,7 @@ def list_images_by_resource_group(self, resource_group): response = None try: response = self.image_client.images.list_by_resource_group(resource_group) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Failed to list images: {0}".format(str(exc))) return [self.format_item(x) for x in response if self.has_tags(x.tags, self.tags)] if response else [] @@ -261,7 +261,7 @@ def list_images(self, image_name=None): results = [] try: response = self.image_client.images.list() - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Failed to list all images: {0}".format(str(exc))) results = [self.format_item(x) for x in response if self.has_tags(x.tags, self.tags)] if response else [] diff --git a/plugins/modules/azure_rm_manageddisk.py b/plugins/modules/azure_rm_manageddisk.py index 6d30d19e4..584efb3a1 100644 --- a/plugins/modules/azure_rm_manageddisk.py +++ b/plugins/modules/azure_rm_manageddisk.py @@ -228,7 +228,7 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: from msrestazure.tools import parse_resource_id - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError except ImportError: # This is handled in azure_rm_common pass @@ -511,7 +511,7 @@ def get_managed_disk(self): self.resource_group, self.name) return managed_disk_to_dict(resp) - except Exception as e: + except ResourceNotFoundError as e: self.log('Did not find managed disk') def is_attach_caching_option_different(self, vm_name, disk): diff --git a/plugins/modules/azure_rm_manageddisk_info.py b/plugins/modules/azure_rm_manageddisk_info.py index a8234971d..5780e1b3c 100644 --- a/plugins/modules/azure_rm_manageddisk_info.py +++ b/plugins/modules/azure_rm_manageddisk_info.py @@ -130,7 +130,7 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError except Exception: # handled in azure_rm_common pass @@ -191,7 +191,7 @@ def get_disk(self): if self.tags: results = [disk for disk in results if self.has_tags(disk.tags, self.tags)] results = [self.managed_disk_to_dict(disk) for disk in results] - except Exception: + except ResourceNotFoundError: self.log('Could not find disk {0} in resource group {1}'.format(self.name, self.resource_group)) return results @@ -207,7 +207,7 @@ def list_disks(self): if self.tags: results = [disk for disk in results if self.has_tags(disk.tags, self.tags)] results = [self.managed_disk_to_dict(disk) for disk in results] - except Exception as exc: + except ResourceNotFoundError as exc: self.fail('Failed to list all items - {0}'.format(str(exc))) return results @@ -223,7 +223,7 @@ def list_disks_by_resource_group(self): if self.tags: results = [disk for disk in results if self.has_tags(disk.tags, self.tags)] results = [self.managed_disk_to_dict(disk) for disk in results] - except Exception as exc: + except ResourceNotFoundError as exc: self.fail('Failed to list items by resource group - {0}'.format(str(exc))) return results diff --git a/plugins/modules/azure_rm_proximityplacementgroup.py b/plugins/modules/azure_rm_proximityplacementgroup.py index f39f542e8..da68e776e 100644 --- a/plugins/modules/azure_rm_proximityplacementgroup.py +++ b/plugins/modules/azure_rm_proximityplacementgroup.py @@ -125,8 +125,7 @@ format_resource_id, normalize_location_name try: - from msrestazure.azure_exceptions import CloudError - from msrest.polling import LROPoller + from azure.core.exceptions import ResourceNotFoundError except ImportError: # This is handled in azure_rm_common pass @@ -190,7 +189,7 @@ def exec_module(self, **kwargs): elif self.state == 'absent': changed = True - except Exception: + except ResourceNotFoundError: if self.state == 'present': changed = True else: diff --git a/plugins/modules/azure_rm_proximityplacementgroup_info.py b/plugins/modules/azure_rm_proximityplacementgroup_info.py index a77a39702..88c225968 100644 --- a/plugins/modules/azure_rm_proximityplacementgroup_info.py +++ b/plugins/modules/azure_rm_proximityplacementgroup_info.py @@ -91,8 +91,7 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: - from msrestazure.azure_exceptions import CloudError - from azure.common import AzureMissingResourceHttpError, AzureHttpError + from azure.core.exceptions import ResourceNotFoundError except Exception: # This is handled in azure_rm_common pass @@ -150,7 +149,7 @@ def get_item(self): # get specific proximity placement group try: item = self.compute_client.proximity_placement_groups.get(self.resource_group, self.name) - except Exception: + except ResourceNotFoundError: pass # serialize result @@ -162,7 +161,7 @@ def list_resource_group(self): self.log('List all proximity placement groups for resource group - {0}'.format(self.resource_group)) try: response = self.compute_client.proximity_placement_groups.list_by_resource_group(self.resource_group) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Failed to list for resource group {0} - {1}".format(self.resource_group, str(exc))) results = [] @@ -175,7 +174,7 @@ def list_items(self): self.log('List all proximity placement groups for a subscription ') try: response = self.compute_client.proximity_placement_groups.list_by_subscription() - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Failed to list all items - {0}".format(str(exc))) results = [] diff --git a/plugins/modules/azure_rm_virtualmachine.py b/plugins/modules/azure_rm_virtualmachine.py index d1cc807b2..5e2c14faa 100644 --- a/plugins/modules/azure_rm_virtualmachine.py +++ b/plugins/modules/azure_rm_virtualmachine.py @@ -811,9 +811,10 @@ import re try: + from azure.core.exceptions import ResourceNotFoundError + from azure.core.polling import LROPoller from msrestazure.azure_exceptions import CloudError from msrestazure.tools import parse_resource_id - from msrest.polling import LROPoller except ImportError: # This is handled in azure_rm_common pass @@ -1264,7 +1265,7 @@ def exec_module(self, **kwargs): results = dict() changed = True - except Exception: + except ResourceNotFoundError: self.log('Virtual machine {0} does not exist'.format(self.name)) if self.state == 'present': self.log("CHANGED: virtual machine {0} does not exist but state is 'present'.".format(self.name)) @@ -2148,7 +2149,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 Exception: + except CloudError: pass if account: @@ -2198,7 +2199,7 @@ def create_default_nic(self): self.log("Check to see if NIC {0} exists".format(network_interface_name)) try: nic = self.network_client.network_interfaces.get(self.resource_group, network_interface_name) - except Exception: + except CloudError: pass if nic: @@ -2218,7 +2219,7 @@ def create_default_nic(self): try: self.network_client.virtual_networks.list(virtual_network_resource_group, self.virtual_network_name) virtual_network_name = self.virtual_network_name - except Exception as exc: + except CloudError as exc: self.fail("Error: fetching virtual network {0} - {1}".format(self.virtual_network_name, str(exc))) else: @@ -2230,7 +2231,7 @@ def create_default_nic(self): virtual_network_name = None try: vnets = self.network_client.virtual_networks.list(virtual_network_resource_group) - except Exception: + except CloudError: self.log('cloud error!') self.fail(no_vnets_msg) @@ -2246,7 +2247,7 @@ def create_default_nic(self): try: subnet = self.network_client.subnets.get(virtual_network_resource_group, virtual_network_name, self.subnet_name) subnet_id = subnet.id - except Exception as exc: + except CloudError as exc: self.fail("Error: fetching subnet {0} - {1}".format(self.subnet_name, str(exc))) else: no_subnets_msg = "Error: unable to find a subnet in virtual network {0}. A virtual network " \ diff --git a/plugins/modules/azure_rm_virtualmachine_info.py b/plugins/modules/azure_rm_virtualmachine_info.py index 6fb5bcd6c..52a28900f 100644 --- a/plugins/modules/azure_rm_virtualmachine_info.py +++ b/plugins/modules/azure_rm_virtualmachine_info.py @@ -272,8 +272,8 @@ ''' try: - from msrestazure.azure_exceptions import CloudError from msrestazure.tools import parse_resource_id + from azure.core.exceptions import ResourceNotFoundError except Exception: # This is handled in azure_rm_common pass @@ -347,7 +347,7 @@ def list_items_by_resourcegroup(self): self.log('List all items') try: items = self.compute_client.virtual_machines.list(self.resource_group) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Failed to list all items - {0}".format(str(exc))) results = [] @@ -360,7 +360,7 @@ def list_all_items(self): self.log('List all items') try: items = self.compute_client.virtual_machines.list_all() - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Failed to list all items - {0}".format(str(exc))) results = [] @@ -378,7 +378,7 @@ def get_vm(self, resource_group, name): try: vm = self.compute_client.virtual_machines.get(resource_group, name, expand='instanceview') return self.serialize_vm(vm) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Error getting virtual machine {0} - {1}".format(self.name, str(exc))) def serialize_vm(self, vm): diff --git a/plugins/modules/azure_rm_virtualmachineextension.py b/plugins/modules/azure_rm_virtualmachineextension.py index 6826829b0..806fc7838 100644 --- a/plugins/modules/azure_rm_virtualmachineextension.py +++ b/plugins/modules/azure_rm_virtualmachineextension.py @@ -111,7 +111,7 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError except ImportError: # This is handled in azure_rm_common pass @@ -317,7 +317,7 @@ def get_vmextension(self): try: response = self.compute_client.virtual_machine_extensions.get(self.resource_group, self.virtual_machine_name, self.name) found = True - except Exception as e: + except ResourceNotFoundError as e: self.log('Did not find vm extension') if found: return vmextension_to_dict(response) diff --git a/plugins/modules/azure_rm_virtualmachineextension_info.py b/plugins/modules/azure_rm_virtualmachineextension_info.py index e575913ad..7016d4142 100644 --- a/plugins/modules/azure_rm_virtualmachineextension_info.py +++ b/plugins/modules/azure_rm_virtualmachineextension_info.py @@ -132,7 +132,7 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError from msrest.serialization import Model except ImportError: # This is handled in azure_rm_common @@ -192,7 +192,7 @@ def get_extensions(self): vm_name=self.virtual_machine_name, vm_extension_name=self.name) self.log("Response : {0}".format(response)) - except Exception as e: + except ResourceNotFoundError as e: self.log('Could not get facts for Virtual Machine Extension.') if response and self.has_tags(response.tags, self.tags): @@ -207,7 +207,7 @@ def list_extensions(self): response = self.compute_client.virtual_machine_extensions.list(resource_group_name=self.resource_group, vm_name=self.virtual_machine_name) self.log("Response : {0}".format(response)) - except Exception as e: + except ResourceNotFoundError as e: self.log('Could not get facts for Virtual Machine Extension.') if response is not None and response.value is not None: diff --git a/plugins/modules/azure_rm_virtualmachineimage_info.py b/plugins/modules/azure_rm_virtualmachineimage_info.py index 053158186..fc18f2dd2 100644 --- a/plugins/modules/azure_rm_virtualmachineimage_info.py +++ b/plugins/modules/azure_rm_virtualmachineimage_info.py @@ -109,7 +109,7 @@ ''' try: - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError except Exception: # This is handled in azure_rm_common pass @@ -186,7 +186,7 @@ def get_item(self): self.sku, top=1, orderby='name desc') - except Exception: + except ResourceNotFoundError: pass if self.version == 'latest': @@ -209,7 +209,7 @@ def list_images(self): self.publisher, self.offer, self.sku,) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Failed to list images: {0}".format(str(exc))) if response: @@ -224,7 +224,7 @@ def list_offers(self): try: response = self.compute_client.virtual_machine_images.list_offers(self.location, self.publisher) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Failed to list offers: {0}".format(str(exc))) if response: @@ -238,7 +238,7 @@ def list_publishers(self): results = [] try: response = self.compute_client.virtual_machine_images.list_publishers(self.location) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Failed to list publishers: {0}".format(str(exc))) if response: diff --git a/plugins/modules/azure_rm_virtualmachinescaleset.py b/plugins/modules/azure_rm_virtualmachinescaleset.py index 074b1224e..ac69b16c9 100644 --- a/plugins/modules/azure_rm_virtualmachinescaleset.py +++ b/plugins/modules/azure_rm_virtualmachinescaleset.py @@ -505,6 +505,7 @@ try: from msrestazure.azure_exceptions import CloudError from msrestazure.tools import parse_resource_id + from azure.core.exceptions import ResourceNotFoundError except ImportError: # This is handled in azure_rm_common @@ -864,7 +865,7 @@ def exec_module(self, **kwargs): results = dict() changed = True - except Exception: + except ResourceNotFoundError: self.log('Virtual machine scale set {0} does not exist'.format(self.name)) if self.state == 'present': self.log("CHANGED: virtual machine scale set {0} does not exist but state is 'present'.".format(self.name)) @@ -1117,21 +1118,21 @@ def get_vmss(self): try: vmss = self.compute_client.virtual_machine_scale_sets.get(self.resource_group, self.name) return vmss - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Error getting virtual machine scale set {0} - {1}".format(self.name, str(exc))) def get_virtual_network(self, name): try: vnet = self.network_client.virtual_networks.get(self.virtual_network_resource_group, name) return vnet - except Exception as exc: + except CloudError as exc: self.fail("Error fetching virtual network {0} - {1}".format(name, str(exc))) def get_subnet(self, vnet_name, subnet_name): self.log("Fetching subnet {0} in virtual network {1}".format(subnet_name, vnet_name)) try: subnet = self.network_client.subnets.get(self.virtual_network_resource_group, vnet_name, subnet_name) - except Exception as exc: + except CloudError as exc: self.fail("Error: fetching subnet {0} in virtual network {1} - {2}".format( subnet_name, vnet_name, @@ -1142,14 +1143,14 @@ def get_load_balancer(self, id): id_dict = parse_resource_id(id) try: return self.network_client.load_balancers.get(id_dict.get('resource_group', self.resource_group), id_dict.get('name')) - except Exception as exc: + except CloudError as exc: self.fail("Error fetching load balancer {0} - {1}".format(id, str(exc))) def get_application_gateway(self, id): id_dict = parse_resource_id(id) try: return self.network_client.application_gateways.get(id_dict.get('resource_group', self.resource_group), id_dict.get('name')) - except Exception as exc: + except CloudError as exc: self.fail("Error fetching application_gateway {0} - {1}".format(id, str(exc))) def serialize_vmss(self, vmss): @@ -1187,7 +1188,7 @@ def get_marketplace_image_version(self): self.image['publisher'], self.image['offer'], self.image['sku']) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Error fetching image {0} {1} {2} - {3}".format(self.image['publisher'], self.image['offer'], self.image['sku'], @@ -1210,7 +1211,7 @@ def get_custom_image_reference(self, name, resource_group=None): vm_images = self.compute_client.images.list_by_resource_group(resource_group) else: vm_images = self.compute_client.images.list() - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Error fetching custom images from subscription - {0}".format(str(exc))) for vm_image in vm_images: @@ -1235,7 +1236,7 @@ def vm_size_is_valid(self): ''' try: sizes = self.compute_client.virtual_machine_sizes.list(self.location) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Error retrieving available machine sizes - {0}".format(str(exc))) for size in sizes: if size.name == self.vm_size: diff --git a/plugins/modules/azure_rm_virtualmachinescaleset_info.py b/plugins/modules/azure_rm_virtualmachinescaleset_info.py index 676174ef4..49ea09c5c 100644 --- a/plugins/modules/azure_rm_virtualmachinescaleset_info.py +++ b/plugins/modules/azure_rm_virtualmachinescaleset_info.py @@ -246,7 +246,7 @@ import re try: - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError except Exception: # handled in azure_rm_common pass @@ -397,7 +397,7 @@ def get_item(self): try: item = self.compute_client.virtual_machine_scale_sets.get(self.resource_group, self.name) - except Exception: + except ResourceNotFoundError: pass if item and self.has_tags(item.tags, self.tags): @@ -412,7 +412,7 @@ def list_items(self): try: response = self.compute_client.virtual_machine_scale_sets.list(self.resource_group) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail('Failed to list all items - {0}'.format(str(exc))) results = [] diff --git a/plugins/modules/azure_rm_virtualmachinescalesetextension.py b/plugins/modules/azure_rm_virtualmachinescalesetextension.py index d74fe7248..eec58bcf1 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetextension.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetextension.py @@ -108,7 +108,7 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError except ImportError: # This is handled in azure_rm_common pass @@ -283,7 +283,7 @@ def get_vmssextension(self): try: response = self.compute_client.virtual_machine_scale_set_extensions.get(self.resource_group, self.vmss_name, self.name) return response.as_dict() - except Exception as e: + except ResourceNotFoundError as e: self.log('Did not find VMSS extension') return False diff --git a/plugins/modules/azure_rm_virtualmachinescalesetextension_info.py b/plugins/modules/azure_rm_virtualmachinescalesetextension_info.py index 6c42dba02..3c54de11a 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetextension_info.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetextension_info.py @@ -117,8 +117,8 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: - from msrestazure.azure_exceptions import CloudError from msrest.serialization import Model + from azure.core.exceptions import ResourceNotFoundError except ImportError: # This is handled in azure_rm_common pass @@ -174,7 +174,7 @@ def get_extensions(self): vm_scale_set_name=self.vmss_name, vmss_extension_name=self.name) self.log("Response : {0}".format(response)) - except Exception as e: + except ResourceNotFoundError as e: self.log('Could not get facts for Virtual Machine Extension.') if response: @@ -189,7 +189,7 @@ def list_extensions(self): response = self.compute_client.virtual_machine_scale_set_extensions.list(resource_group_name=self.resource_group, vm_scale_set_name=self.vmss_name) self.log("Response : {0}".format(response)) - except Exception as e: + except ResourceNotFoundError as e: self.log('Could not get facts for Virtual Machine Extension.') if response is not None: diff --git a/plugins/modules/azure_rm_virtualmachinescalesetinstance.py b/plugins/modules/azure_rm_virtualmachinescalesetinstance.py index 26fd1d595..54ed23b86 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetinstance.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetinstance.py @@ -98,7 +98,7 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError from azure.mgmt.compute import ComputeManagementClient from msrest.serialization import Model except ImportError: @@ -214,7 +214,7 @@ def get(self): vm_scale_set_name=self.vmss_name, instance_id=self.instance_id) self.log("Response : {0}".format(response)) - except Exception as e: + except ResourceNotFoundError as e: self.log('Could not get facts for Virtual Machine Scale Set VM.') if response: diff --git a/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py b/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py index cb72ed84b..b34d832d8 100644 --- a/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py +++ b/plugins/modules/azure_rm_virtualmachinescalesetinstance_info.py @@ -115,9 +115,9 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: - from msrestazure.azure_exceptions import CloudError from azure.mgmt.compute import ComputeManagementClient from msrest.serialization import Model + from azure.core.exceptions import ResourceNotFoundError except ImportError: # This is handled in azure_rm_common pass @@ -181,7 +181,7 @@ def get(self): vm_scale_set_name=self.vmss_name, instance_id=self.instance_id) self.log("Response : {0}".format(response)) - except Exception as e: + except ResourceNotFoundError as e: self.log('Could not get facts for Virtual Machine Scale Set VM.') if response and self.has_tags(response.tags, self.tags): @@ -195,7 +195,7 @@ def list(self): items = self.mgmt_client.virtual_machine_scale_set_vms.list(resource_group_name=self.resource_group, virtual_machine_scale_set_name=self.vmss_name) self.log("Response : {0}".format(items)) - except Exception as e: + except ResourceNotFoundError as e: self.log('Could not get facts for Virtual Machine ScaleSet VM.') results = [] diff --git a/plugins/modules/azure_rm_virtualmachinesize_info.py b/plugins/modules/azure_rm_virtualmachinesize_info.py index 2aaae5beb..a0fe189af 100644 --- a/plugins/modules/azure_rm_virtualmachinesize_info.py +++ b/plugins/modules/azure_rm_virtualmachinesize_info.py @@ -90,7 +90,7 @@ ''' try: - from msrestazure.azure_exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError except Exception: # This is handled in azure_rm_common pass @@ -135,7 +135,7 @@ def list_items_by_location(self): self.log('List items by location') try: items = self.compute_client.virtual_machine_sizes.list(location=self.location) - except Exception as exc: + except ResourceNotFoundError as exc: self.fail("Failed to list items - {0}".format(str(exc))) return [self.serialize_size(item) for item in items if self.name is None or self.name == item.name] From 1dce8f397b1bb6ed4df7ac842d2cfd2bf417e9ac Mon Sep 17 00:00:00 2001 From: Fred-sun <37327967+Fred-sun@users.noreply.github.com> Date: Tue, 8 Mar 2022 11:26:13 +0800 Subject: [PATCH 18/19] Merge dev to local branch (#10) * azure_rm_sqldatabase: parse datetime module arguments (#623) * rm_sqldatabase: parse datetime arguments * Remove unused sanity test exception on rm_sqldatabase module schema * Remove unused sanity test exception on rm_sqldatabase module schema bis * sqldatabase: import dateutil in try/except * Add dateutil install to test suite * sqldatabase_info: Add earliest_restore_date value to returned facts * sqldatabase: add point in time restore test * Conditionally call non MSI auth when interacting with keyvault (#770) * Added the VM status detection mechanism (#772) * Set the parameter to a random number * Update storage account name Update azure_rm_virtualmachine vars add new change add new change 02 add new change 03 add new change 05 add new change 06 add new change 08 add new change09 update new Update new 02 Improve code logic * fix a typo error. related to #757 (#769) * fix a typo error. related to #757 * remove unused line Co-authored-by: Daniele Marcocci * Update test region (#776) Co-authored-by: Max Co-authored-by: Daniele Marcocci Co-authored-by: Daniele Marcocci --- plugins/module_utils/azure_rm_common.py | 3 +- plugins/modules/azure_rm_keyvaultkey.py | 7 ++++ plugins/modules/azure_rm_keyvaultkey_info.py | 7 ++++ plugins/modules/azure_rm_keyvaultsecret.py | 7 ++++ .../modules/azure_rm_keyvaultsecret_info.py | 7 ++++ plugins/modules/azure_rm_sqldatabase.py | 15 +++++-- plugins/modules/azure_rm_sqldatabase_info.py | 9 +++- plugins/modules/azure_rm_virtualmachine.py | 14 ++++++- .../azure_rm_containerinstance/tasks/main.yml | 26 +++++++----- .../azure_rm_cosmosdbaccount/tasks/main.yml | 6 +-- .../targets/azure_rm_gallery/tasks/main.yml | 12 +++--- .../targets/azure_rm_sqlserver/tasks/main.yml | 42 +++++++++++++++++++ .../inventory_azure/playbooks/vars.yml | 2 +- tests/sanity/ignore-2.10.txt | 1 - tests/sanity/ignore-2.11.txt | 1 - tests/sanity/ignore-2.12.txt | 1 - tests/utils/ado/ado.sh | 1 + 17 files changed, 129 insertions(+), 32 deletions(-) diff --git a/plugins/module_utils/azure_rm_common.py b/plugins/module_utils/azure_rm_common.py index c9ee7efe2..18bcaca7f 100644 --- a/plugins/module_utils/azure_rm_common.py +++ b/plugins/module_utils/azure_rm_common.py @@ -1503,7 +1503,7 @@ def __init__(self, auth_source=None, profile=None, subscription_id=None, client_ if self.credentials.get('credentials') is not None: # AzureCLI credentials self.azure_credentials = self.credentials['credentials'] - self.azure_credential_track2 = self.credentials['credential'] + self.azure_credential_track2 = self.credentials['credentials'] elif self.credentials.get('client_id') is not None and \ self.credentials.get('secret') is not None and \ self.credentials.get('tenant') is not None: @@ -1619,7 +1619,6 @@ def _get_azure_cli_credentials(self, subscription_id=None, resource=None): cli_credentials = { 'credentials': credentials, - 'credential': credentials, 'subscription_id': subscription_id, 'cloud_environment': cloud_environment } diff --git a/plugins/modules/azure_rm_keyvaultkey.py b/plugins/modules/azure_rm_keyvaultkey.py index 3156c7e22..9034a1abe 100644 --- a/plugins/modules/azure_rm_keyvaultkey.py +++ b/plugins/modules/azure_rm_keyvaultkey.py @@ -185,6 +185,13 @@ def get_keyvault_client(self): return KeyVaultClient(credentials) except Exception: self.log("Get KeyVaultClient from service principal") + else: + try: + self.log("Get KeyVaultClient from MSI") + credentials = MSIAuthentication(resource='https://vault.azure.net') + return KeyVaultClient(credentials) + except Exception: + self.log("Get KeyVaultClient from service principal") # Create KeyVault Client using KeyVault auth class and auth_callback def auth_callback(server, resource, scope): diff --git a/plugins/modules/azure_rm_keyvaultkey_info.py b/plugins/modules/azure_rm_keyvaultkey_info.py index 840b4e703..e763ce5fd 100644 --- a/plugins/modules/azure_rm_keyvaultkey_info.py +++ b/plugins/modules/azure_rm_keyvaultkey_info.py @@ -320,6 +320,13 @@ def get_keyvault_client(self): return KeyVaultClient(credentials) except Exception: self.log("Get KeyVaultClient from service principal") + else: + try: + self.log("Get KeyVaultClient from MSI") + credentials = MSIAuthentication(resource='https://vault.azure.net') + return KeyVaultClient(credentials) + except Exception: + self.log("Get KeyVaultClient from service principal") # Create KeyVault Client using KeyVault auth class and auth_callback def auth_callback(server, resource, scope): diff --git a/plugins/modules/azure_rm_keyvaultsecret.py b/plugins/modules/azure_rm_keyvaultsecret.py index 9f877addd..0cc681477 100644 --- a/plugins/modules/azure_rm_keyvaultsecret.py +++ b/plugins/modules/azure_rm_keyvaultsecret.py @@ -207,6 +207,13 @@ def get_keyvault_client(self): return KeyVaultClient(credentials) except Exception: self.log("Get KeyVaultClient from service principal") + else: + try: + self.log("Get KeyVaultClient from MSI") + credentials = MSIAuthentication(resource='https://vault.azure.net') + return KeyVaultClient(credentials) + except Exception: + self.log("Get KeyVaultClient from service principal") # Create KeyVault Client using KeyVault auth class and auth_callback def auth_callback(server, resource, scope): diff --git a/plugins/modules/azure_rm_keyvaultsecret_info.py b/plugins/modules/azure_rm_keyvaultsecret_info.py index d5e73574b..9f1a87877 100644 --- a/plugins/modules/azure_rm_keyvaultsecret_info.py +++ b/plugins/modules/azure_rm_keyvaultsecret_info.py @@ -273,6 +273,13 @@ def get_keyvault_client(self): return KeyVaultClient(credentials) except Exception: self.log("Get KeyVaultClient from service principal") + else: + try: + self.log("Get KeyVaultClient from MSI") + credentials = MSIAuthentication(resource='https://vault.azure.net') + return KeyVaultClient(credentials) + except Exception: + self.log("Get KeyVaultClient from service principal") # Create KeyVault Client using KeyVault auth class and auth_callback def auth_callback(server, resource, scope): diff --git a/plugins/modules/azure_rm_sqldatabase.py b/plugins/modules/azure_rm_sqldatabase.py index 23fc96f88..f315fcc66 100644 --- a/plugins/modules/azure_rm_sqldatabase.py +++ b/plugins/modules/azure_rm_sqldatabase.py @@ -226,6 +226,7 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase, format_resource_id try: + import dateutil.parser from msrestazure.azure_exceptions import CloudError from msrest.polling import LROPoller from azure.mgmt.sql import SqlManagementClient @@ -308,10 +309,10 @@ def __init__(self): type='str' ), source_database_deletion_date=dict( - type='datetime' + type='str' ), restore_point_in_time=dict( - type='datetime' + type='str' ), recovery_services_recovery_point_resource_id=dict( type='str' @@ -393,9 +394,15 @@ def exec_module(self, **kwargs): elif key == "source_database_id": self.parameters["source_database_id"] = kwargs[key] elif key == "source_database_deletion_date": - self.parameters["source_database_deletion_date"] = kwargs[key] + try: + self.parameters["source_database_deletion_date"] = dateutil.parser.parse(kwargs[key]) + except dateutil.parser._parser.ParserError: + self.fail("Error parsing date from source_database_deletion_date: {0}".format(kwargs[key])) elif key == "restore_point_in_time": - self.parameters["restore_point_in_time"] = kwargs[key] + try: + self.parameters["restore_point_in_time"] = dateutil.parser.parse(kwargs[key]) + except dateutil.parser._parser.ParserError: + self.fail("Error parsing date from restore_point_in_time: {0}".format(kwargs[key])) elif key == "recovery_services_recovery_point_resource_id": self.parameters["recovery_services_recovery_point_resource_id"] = kwargs[key] elif key == "edition": diff --git a/plugins/modules/azure_rm_sqldatabase_info.py b/plugins/modules/azure_rm_sqldatabase_info.py index 17db95b84..374fc9841 100644 --- a/plugins/modules/azure_rm_sqldatabase_info.py +++ b/plugins/modules/azure_rm_sqldatabase_info.py @@ -141,6 +141,12 @@ returned: always type: bool sample: true + earliest_restore_date: + description: + - The earliest restore point available for the SQL Database. + returned: always + type: str + sample: '2021-09-01T00:59:59.000Z' ''' from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase @@ -270,7 +276,8 @@ def format_item(self, item): 'kind': d.get('kind', None), 'collation': d.get('collation', None), 'status': d.get('status', None), - 'zone_redundant': d.get('zone_redundant', None) + 'zone_redundant': d.get('zone_redundant', None), + 'earliest_restore_date': d.get('earliest_restore_date', None) } return d diff --git a/plugins/modules/azure_rm_virtualmachine.py b/plugins/modules/azure_rm_virtualmachine.py index ae6e0ef7b..93dacecf4 100644 --- a/plugins/modules/azure_rm_virtualmachine.py +++ b/plugins/modules/azure_rm_virtualmachine.py @@ -809,6 +809,7 @@ import base64 import random import re +import time try: from azure.core.exceptions import ResourceNotFoundError @@ -1109,7 +1110,18 @@ def exec_module(self, **kwargs): try: self.log("Fetching virtual machine {0}".format(self.name)) vm = self.compute_client.virtual_machines.get(self.resource_group, self.name, expand='instanceview') - self.check_provisioning_state(vm, self.state) + retry_count = 0 + while True: + if retry_count == 10: + self.fail("Error {0} has a provisioning state of Updating. Expecting state to be Successed.".format(self.name)) + + if vm.provisioning_state == 'Updating': + retry_count = retry_count + 1 + time.sleep(300) + vm = self.compute_client.virtual_machines.get(self.resource_group, self.name, expand='instanceview') + else: + break + vm_dict = self.serialize_vm(vm) if self.state == 'present': diff --git a/tests/integration/targets/azure_rm_containerinstance/tasks/main.yml b/tests/integration/targets/azure_rm_containerinstance/tasks/main.yml index 4851c045e..8d7a6e62b 100644 --- a/tests/integration/targets/azure_rm_containerinstance/tasks/main.yml +++ b/tests/integration/targets/azure_rm_containerinstance/tasks/main.yml @@ -1,7 +1,11 @@ +- name: Set Container Instance Names + set_fact: + rpfx: "{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}" + - name: Create sample container instance azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}" + name: "aci{{ rpfx }}" os_type: linux ip_address: public location: eastus @@ -28,7 +32,7 @@ - name: Create sample container instance -- same parameters azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}" + name: "aci{{ rpfx }}" os_type: linux ip_address: public location: eastus @@ -51,7 +55,7 @@ - name: Create sample container instance -- force update azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}" + name: "aci{{ rpfx }}" os_type: linux ip_address: public location: eastus @@ -76,7 +80,7 @@ - name: Create second container instance for testing purposes azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}sec" + name: "aci{{ rpfx }}sec" os_type: linux ip_address: public dns_name_label: mydnslabel{{ resource_group | hash('md5') | truncate(7, True, '') }} @@ -99,7 +103,7 @@ - name: Gather facts for single Container Instance azure_rm_containerinstance_info: resource_group: "{{ resource_group }}" - name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}sec" + name: "aci{{ rpfx }}sec" register: output - debug: @@ -146,7 +150,7 @@ - name: Create sample container instance with volume azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}thi" + name: "aci{{ rpfx }}thi" os_type: linux ip_address: public location: eastus @@ -185,7 +189,7 @@ - name: Gather facts for Container Instance azure_rm_containerinstance_info: resource_group: "{{ resource_group }}" - name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}thi" + name: "aci{{ rpfx }}thi" register: output ignore_errors: True @@ -213,7 +217,7 @@ - name: Remove container instance azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}thi" + name: "aci{{ rpfx }}thi" os_type: linux ip_address: public location: eastus @@ -242,7 +246,7 @@ - name: Remove container instance azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}" + name: "aci{{ rpfx }}" os_type: linux ip_address: public location: eastus @@ -266,7 +270,7 @@ - name: Remove container instance azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}sec" + name: "aci{{ rpfx }}sec" os_type: linux ip_address: public location: eastus @@ -284,7 +288,7 @@ - name: Remove container instance again azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}" + name: "aci{{ rpfx }}" os_type: linux ip_address: public location: eastus diff --git a/tests/integration/targets/azure_rm_cosmosdbaccount/tasks/main.yml b/tests/integration/targets/azure_rm_cosmosdbaccount/tasks/main.yml index 7c548bdd4..be2e573f0 100644 --- a/tests/integration/targets/azure_rm_cosmosdbaccount/tasks/main.yml +++ b/tests/integration/targets/azure_rm_cosmosdbaccount/tasks/main.yml @@ -120,12 +120,12 @@ azure_rm_cosmosdbaccount: resource_group: "{{ resource_group_secondary }}" name: "{{ db2name }}" - location: westus + location: eastasia kind: global_document_db geo_rep_locations: - - name: southcentralus + - name: eastasia failover_priority: 0 - - name: eastus2 + - name: westus failover_priority: 1 database_account_offer_type: Standard is_virtual_network_filter_enabled: yes diff --git a/tests/integration/targets/azure_rm_gallery/tasks/main.yml b/tests/integration/targets/azure_rm_gallery/tasks/main.yml index d70104563..4d71b6f5c 100644 --- a/tests/integration/targets/azure_rm_gallery/tasks/main.yml +++ b/tests/integration/targets/azure_rm_gallery/tasks/main.yml @@ -6,28 +6,28 @@ - name: Create virtual network azure_rm_virtualnetwork: resource_group: "{{ resource_group }}" - name: testVnet + name: "testVnet{{ rpfx }}" address_prefixes: "10.0.0.0/16" - name: Add subnet azure_rm_subnet: resource_group: "{{ resource_group }}" - name: testSubnet + name: "testSubnet{{ rpfx }}" address_prefix: "10.0.1.0/24" - virtual_network: testVnet + virtual_network: "testVnet{{ rpfx }}" - name: Create public IP address azure_rm_publicipaddress: resource_group: "{{ resource_group }}" allocation_method: Static - name: testPublicIP + name: "testPublicIP{{ rpfx }}" - name: Create virtual network inteface cards for VM A and B azure_rm_networkinterface: resource_group: "{{ resource_group }}" name: "vmforimage{{ rpfx }}nic" - virtual_network: testVnet - subnet: testSubnet + virtual_network: "testVnet{{ rpfx }}" + subnet: "testSubnet{{ rpfx }}" - name: Create VM azure_rm_virtualmachine: diff --git a/tests/integration/targets/azure_rm_sqlserver/tasks/main.yml b/tests/integration/targets/azure_rm_sqlserver/tasks/main.yml index d18d92702..7a6575d9b 100644 --- a/tests/integration/targets/azure_rm_sqlserver/tasks/main.yml +++ b/tests/integration/targets/azure_rm_sqlserver/tasks/main.yml @@ -143,6 +143,48 @@ - output.changed == false - output.status == 'Online' +# test database point in time restore +- name: Gather facts SQL Database and wait for restore point + azure_rm_sqldatabase_info: + resource_group: "{{ resource_group }}" + server_name: sqlsrv{{ random_postfix }} + name: database{{ random_postfix }} + register: output + until: output.databases[0].earliest_restore_date != None + retries: 10 + delay: 20 +- name: Assert that it can be restored from + assert: + that: + - output.databases[0].id != None + - output.databases[0].earliest_restore_date != None + +- name: Create second SQL Database, restoring from the previous Database + azure_rm_sqldatabase: + resource_group: "{{ resource_group }}" + create_mode: point_in_time_restore + restore_point_in_time: "{{ output.databases[0].earliest_restore_date }}" + source_database_id: "{{ output.databases[0].id }}" + server_name: sqlsrv{{ random_postfix }} + name: database{{ random_postfix }}PITR + register: output +- name: Assert the state has changed + assert: + that: + - output.changed + +- name: Delete instance of SQL Database Point in time recovery + azure_rm_sqldatabase: + resource_group: "{{ resource_group }}" + server_name: sqlsrv{{ random_postfix }} + name: database{{ random_postfix }}PITR + state: absent + register: output +- name: Assert the state has changed + assert: + that: + - output.changed + # test database facter: - name: Create second SQL Database azure_rm_sqldatabase: diff --git a/tests/integration/targets/inventory_azure/playbooks/vars.yml b/tests/integration/targets/inventory_azure/playbooks/vars.yml index c2aa787df..dc6bbe080 100644 --- a/tests/integration/targets/inventory_azure/playbooks/vars.yml +++ b/tests/integration/targets/inventory_azure/playbooks/vars.yml @@ -11,4 +11,4 @@ security_group: "{{ 'sg' ~ uid_short }}" public_ip_name: "{{ 'ip' ~ uid_short }}" interface_name: "{{ 'int' ~ uid_short }}" network: 10.42.0.0/24 -subnet: 10.42.0.0/28 \ No newline at end of file +subnet: 10.42.0.0/28 diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index a8d4d398b..f7c936331 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -254,7 +254,6 @@ plugins/modules/azure_rm_servicebussaspolicy.py validate-modules:doc-required-mi plugins/modules/azure_rm_snapshot.py validate-modules:doc-required-mismatch plugins/modules/azure_rm_snapshot.py validate-modules:invalid-ansiblemodule-schema plugins/modules/azure_rm_sqldatabase.py validate-modules:parameter-type-not-in-doc -plugins/modules/azure_rm_sqldatabase.py validate-modules:invalid-ansiblemodule-schema plugins/modules/azure_rm_sqldatabase_info.py validate-modules:parameter-type-not-in-doc plugins/modules/azure_rm_sqldatabase_info.py validate-modules:parameter-list-no-elements plugins/modules/azure_rm_sqlfirewallrule.py validate-modules:parameter-type-not-in-doc diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index a8d4d398b..f7c936331 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -254,7 +254,6 @@ plugins/modules/azure_rm_servicebussaspolicy.py validate-modules:doc-required-mi plugins/modules/azure_rm_snapshot.py validate-modules:doc-required-mismatch plugins/modules/azure_rm_snapshot.py validate-modules:invalid-ansiblemodule-schema plugins/modules/azure_rm_sqldatabase.py validate-modules:parameter-type-not-in-doc -plugins/modules/azure_rm_sqldatabase.py validate-modules:invalid-ansiblemodule-schema plugins/modules/azure_rm_sqldatabase_info.py validate-modules:parameter-type-not-in-doc plugins/modules/azure_rm_sqldatabase_info.py validate-modules:parameter-list-no-elements plugins/modules/azure_rm_sqlfirewallrule.py validate-modules:parameter-type-not-in-doc diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index a8d4d398b..f7c936331 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -254,7 +254,6 @@ plugins/modules/azure_rm_servicebussaspolicy.py validate-modules:doc-required-mi plugins/modules/azure_rm_snapshot.py validate-modules:doc-required-mismatch plugins/modules/azure_rm_snapshot.py validate-modules:invalid-ansiblemodule-schema plugins/modules/azure_rm_sqldatabase.py validate-modules:parameter-type-not-in-doc -plugins/modules/azure_rm_sqldatabase.py validate-modules:invalid-ansiblemodule-schema plugins/modules/azure_rm_sqldatabase_info.py validate-modules:parameter-type-not-in-doc plugins/modules/azure_rm_sqldatabase_info.py validate-modules:parameter-list-no-elements plugins/modules/azure_rm_sqlfirewallrule.py validate-modules:parameter-type-not-in-doc diff --git a/tests/utils/ado/ado.sh b/tests/utils/ado/ado.sh index 4d666dced..5693444c7 100755 --- a/tests/utils/ado/ado.sh +++ b/tests/utils/ado/ado.sh @@ -18,6 +18,7 @@ else sudo apt install software-properties-common sudo add-apt-repository ppa:deadsnakes/ppa sudo apt install python"$2" -y + sudo apt install python3-dateutil sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python"$2" 1 fi From ec503d2ff3e3b8120ffcf57ced47ae50d022e881 Mon Sep 17 00:00:00 2001 From: Fred-sun <37327967+Fred-sun@users.noreply.github.com> Date: Tue, 8 Mar 2022 14:07:48 +0800 Subject: [PATCH 19/19] Revert "Merge dev to local branch (#10)" (#11) This reverts commit 1dce8f397b1bb6ed4df7ac842d2cfd2bf417e9ac. --- plugins/module_utils/azure_rm_common.py | 3 +- plugins/modules/azure_rm_keyvaultkey.py | 7 ---- plugins/modules/azure_rm_keyvaultkey_info.py | 7 ---- plugins/modules/azure_rm_keyvaultsecret.py | 7 ---- .../modules/azure_rm_keyvaultsecret_info.py | 7 ---- plugins/modules/azure_rm_sqldatabase.py | 15 ++----- plugins/modules/azure_rm_sqldatabase_info.py | 9 +--- plugins/modules/azure_rm_virtualmachine.py | 14 +------ .../azure_rm_containerinstance/tasks/main.yml | 26 +++++------- .../azure_rm_cosmosdbaccount/tasks/main.yml | 6 +-- .../targets/azure_rm_gallery/tasks/main.yml | 12 +++--- .../targets/azure_rm_sqlserver/tasks/main.yml | 42 ------------------- .../inventory_azure/playbooks/vars.yml | 2 +- tests/sanity/ignore-2.10.txt | 1 + tests/sanity/ignore-2.11.txt | 1 + tests/sanity/ignore-2.12.txt | 1 + tests/utils/ado/ado.sh | 1 - 17 files changed, 32 insertions(+), 129 deletions(-) diff --git a/plugins/module_utils/azure_rm_common.py b/plugins/module_utils/azure_rm_common.py index 18bcaca7f..c9ee7efe2 100644 --- a/plugins/module_utils/azure_rm_common.py +++ b/plugins/module_utils/azure_rm_common.py @@ -1503,7 +1503,7 @@ def __init__(self, auth_source=None, profile=None, subscription_id=None, client_ if self.credentials.get('credentials') is not None: # AzureCLI credentials self.azure_credentials = self.credentials['credentials'] - self.azure_credential_track2 = self.credentials['credentials'] + self.azure_credential_track2 = self.credentials['credential'] elif self.credentials.get('client_id') is not None and \ self.credentials.get('secret') is not None and \ self.credentials.get('tenant') is not None: @@ -1619,6 +1619,7 @@ def _get_azure_cli_credentials(self, subscription_id=None, resource=None): cli_credentials = { 'credentials': credentials, + 'credential': credentials, 'subscription_id': subscription_id, 'cloud_environment': cloud_environment } diff --git a/plugins/modules/azure_rm_keyvaultkey.py b/plugins/modules/azure_rm_keyvaultkey.py index 9034a1abe..3156c7e22 100644 --- a/plugins/modules/azure_rm_keyvaultkey.py +++ b/plugins/modules/azure_rm_keyvaultkey.py @@ -185,13 +185,6 @@ def get_keyvault_client(self): return KeyVaultClient(credentials) except Exception: self.log("Get KeyVaultClient from service principal") - else: - try: - self.log("Get KeyVaultClient from MSI") - credentials = MSIAuthentication(resource='https://vault.azure.net') - return KeyVaultClient(credentials) - except Exception: - self.log("Get KeyVaultClient from service principal") # Create KeyVault Client using KeyVault auth class and auth_callback def auth_callback(server, resource, scope): diff --git a/plugins/modules/azure_rm_keyvaultkey_info.py b/plugins/modules/azure_rm_keyvaultkey_info.py index e763ce5fd..840b4e703 100644 --- a/plugins/modules/azure_rm_keyvaultkey_info.py +++ b/plugins/modules/azure_rm_keyvaultkey_info.py @@ -320,13 +320,6 @@ def get_keyvault_client(self): return KeyVaultClient(credentials) except Exception: self.log("Get KeyVaultClient from service principal") - else: - try: - self.log("Get KeyVaultClient from MSI") - credentials = MSIAuthentication(resource='https://vault.azure.net') - return KeyVaultClient(credentials) - except Exception: - self.log("Get KeyVaultClient from service principal") # Create KeyVault Client using KeyVault auth class and auth_callback def auth_callback(server, resource, scope): diff --git a/plugins/modules/azure_rm_keyvaultsecret.py b/plugins/modules/azure_rm_keyvaultsecret.py index 0cc681477..9f877addd 100644 --- a/plugins/modules/azure_rm_keyvaultsecret.py +++ b/plugins/modules/azure_rm_keyvaultsecret.py @@ -207,13 +207,6 @@ def get_keyvault_client(self): return KeyVaultClient(credentials) except Exception: self.log("Get KeyVaultClient from service principal") - else: - try: - self.log("Get KeyVaultClient from MSI") - credentials = MSIAuthentication(resource='https://vault.azure.net') - return KeyVaultClient(credentials) - except Exception: - self.log("Get KeyVaultClient from service principal") # Create KeyVault Client using KeyVault auth class and auth_callback def auth_callback(server, resource, scope): diff --git a/plugins/modules/azure_rm_keyvaultsecret_info.py b/plugins/modules/azure_rm_keyvaultsecret_info.py index 9f1a87877..d5e73574b 100644 --- a/plugins/modules/azure_rm_keyvaultsecret_info.py +++ b/plugins/modules/azure_rm_keyvaultsecret_info.py @@ -273,13 +273,6 @@ def get_keyvault_client(self): return KeyVaultClient(credentials) except Exception: self.log("Get KeyVaultClient from service principal") - else: - try: - self.log("Get KeyVaultClient from MSI") - credentials = MSIAuthentication(resource='https://vault.azure.net') - return KeyVaultClient(credentials) - except Exception: - self.log("Get KeyVaultClient from service principal") # Create KeyVault Client using KeyVault auth class and auth_callback def auth_callback(server, resource, scope): diff --git a/plugins/modules/azure_rm_sqldatabase.py b/plugins/modules/azure_rm_sqldatabase.py index f315fcc66..23fc96f88 100644 --- a/plugins/modules/azure_rm_sqldatabase.py +++ b/plugins/modules/azure_rm_sqldatabase.py @@ -226,7 +226,6 @@ from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase, format_resource_id try: - import dateutil.parser from msrestazure.azure_exceptions import CloudError from msrest.polling import LROPoller from azure.mgmt.sql import SqlManagementClient @@ -309,10 +308,10 @@ def __init__(self): type='str' ), source_database_deletion_date=dict( - type='str' + type='datetime' ), restore_point_in_time=dict( - type='str' + type='datetime' ), recovery_services_recovery_point_resource_id=dict( type='str' @@ -394,15 +393,9 @@ def exec_module(self, **kwargs): elif key == "source_database_id": self.parameters["source_database_id"] = kwargs[key] elif key == "source_database_deletion_date": - try: - self.parameters["source_database_deletion_date"] = dateutil.parser.parse(kwargs[key]) - except dateutil.parser._parser.ParserError: - self.fail("Error parsing date from source_database_deletion_date: {0}".format(kwargs[key])) + self.parameters["source_database_deletion_date"] = kwargs[key] elif key == "restore_point_in_time": - try: - self.parameters["restore_point_in_time"] = dateutil.parser.parse(kwargs[key]) - except dateutil.parser._parser.ParserError: - self.fail("Error parsing date from restore_point_in_time: {0}".format(kwargs[key])) + self.parameters["restore_point_in_time"] = kwargs[key] elif key == "recovery_services_recovery_point_resource_id": self.parameters["recovery_services_recovery_point_resource_id"] = kwargs[key] elif key == "edition": diff --git a/plugins/modules/azure_rm_sqldatabase_info.py b/plugins/modules/azure_rm_sqldatabase_info.py index 374fc9841..17db95b84 100644 --- a/plugins/modules/azure_rm_sqldatabase_info.py +++ b/plugins/modules/azure_rm_sqldatabase_info.py @@ -141,12 +141,6 @@ returned: always type: bool sample: true - earliest_restore_date: - description: - - The earliest restore point available for the SQL Database. - returned: always - type: str - sample: '2021-09-01T00:59:59.000Z' ''' from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase @@ -276,8 +270,7 @@ def format_item(self, item): 'kind': d.get('kind', None), 'collation': d.get('collation', None), 'status': d.get('status', None), - 'zone_redundant': d.get('zone_redundant', None), - 'earliest_restore_date': d.get('earliest_restore_date', None) + 'zone_redundant': d.get('zone_redundant', None) } return d diff --git a/plugins/modules/azure_rm_virtualmachine.py b/plugins/modules/azure_rm_virtualmachine.py index 93dacecf4..ae6e0ef7b 100644 --- a/plugins/modules/azure_rm_virtualmachine.py +++ b/plugins/modules/azure_rm_virtualmachine.py @@ -809,7 +809,6 @@ import base64 import random import re -import time try: from azure.core.exceptions import ResourceNotFoundError @@ -1110,18 +1109,7 @@ def exec_module(self, **kwargs): try: self.log("Fetching virtual machine {0}".format(self.name)) vm = self.compute_client.virtual_machines.get(self.resource_group, self.name, expand='instanceview') - retry_count = 0 - while True: - if retry_count == 10: - self.fail("Error {0} has a provisioning state of Updating. Expecting state to be Successed.".format(self.name)) - - if vm.provisioning_state == 'Updating': - retry_count = retry_count + 1 - time.sleep(300) - vm = self.compute_client.virtual_machines.get(self.resource_group, self.name, expand='instanceview') - else: - break - + self.check_provisioning_state(vm, self.state) vm_dict = self.serialize_vm(vm) if self.state == 'present': diff --git a/tests/integration/targets/azure_rm_containerinstance/tasks/main.yml b/tests/integration/targets/azure_rm_containerinstance/tasks/main.yml index 8d7a6e62b..4851c045e 100644 --- a/tests/integration/targets/azure_rm_containerinstance/tasks/main.yml +++ b/tests/integration/targets/azure_rm_containerinstance/tasks/main.yml @@ -1,11 +1,7 @@ -- name: Set Container Instance Names - set_fact: - rpfx: "{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}" - - name: Create sample container instance azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ rpfx }}" + name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}" os_type: linux ip_address: public location: eastus @@ -32,7 +28,7 @@ - name: Create sample container instance -- same parameters azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ rpfx }}" + name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}" os_type: linux ip_address: public location: eastus @@ -55,7 +51,7 @@ - name: Create sample container instance -- force update azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ rpfx }}" + name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}" os_type: linux ip_address: public location: eastus @@ -80,7 +76,7 @@ - name: Create second container instance for testing purposes azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ rpfx }}sec" + name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}sec" os_type: linux ip_address: public dns_name_label: mydnslabel{{ resource_group | hash('md5') | truncate(7, True, '') }} @@ -103,7 +99,7 @@ - name: Gather facts for single Container Instance azure_rm_containerinstance_info: resource_group: "{{ resource_group }}" - name: "aci{{ rpfx }}sec" + name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}sec" register: output - debug: @@ -150,7 +146,7 @@ - name: Create sample container instance with volume azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ rpfx }}thi" + name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}thi" os_type: linux ip_address: public location: eastus @@ -189,7 +185,7 @@ - name: Gather facts for Container Instance azure_rm_containerinstance_info: resource_group: "{{ resource_group }}" - name: "aci{{ rpfx }}thi" + name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}thi" register: output ignore_errors: True @@ -217,7 +213,7 @@ - name: Remove container instance azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ rpfx }}thi" + name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}thi" os_type: linux ip_address: public location: eastus @@ -246,7 +242,7 @@ - name: Remove container instance azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ rpfx }}" + name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}" os_type: linux ip_address: public location: eastus @@ -270,7 +266,7 @@ - name: Remove container instance azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ rpfx }}sec" + name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}sec" os_type: linux ip_address: public location: eastus @@ -288,7 +284,7 @@ - name: Remove container instance again azure_rm_containerinstance: resource_group: "{{ resource_group }}" - name: "aci{{ rpfx }}" + name: "aci{{ resource_group | hash('md5') | truncate(7, True, '') }}" os_type: linux ip_address: public location: eastus diff --git a/tests/integration/targets/azure_rm_cosmosdbaccount/tasks/main.yml b/tests/integration/targets/azure_rm_cosmosdbaccount/tasks/main.yml index be2e573f0..7c548bdd4 100644 --- a/tests/integration/targets/azure_rm_cosmosdbaccount/tasks/main.yml +++ b/tests/integration/targets/azure_rm_cosmosdbaccount/tasks/main.yml @@ -120,12 +120,12 @@ azure_rm_cosmosdbaccount: resource_group: "{{ resource_group_secondary }}" name: "{{ db2name }}" - location: eastasia + location: westus kind: global_document_db geo_rep_locations: - - name: eastasia + - name: southcentralus failover_priority: 0 - - name: westus + - name: eastus2 failover_priority: 1 database_account_offer_type: Standard is_virtual_network_filter_enabled: yes diff --git a/tests/integration/targets/azure_rm_gallery/tasks/main.yml b/tests/integration/targets/azure_rm_gallery/tasks/main.yml index 4d71b6f5c..d70104563 100644 --- a/tests/integration/targets/azure_rm_gallery/tasks/main.yml +++ b/tests/integration/targets/azure_rm_gallery/tasks/main.yml @@ -6,28 +6,28 @@ - name: Create virtual network azure_rm_virtualnetwork: resource_group: "{{ resource_group }}" - name: "testVnet{{ rpfx }}" + name: testVnet address_prefixes: "10.0.0.0/16" - name: Add subnet azure_rm_subnet: resource_group: "{{ resource_group }}" - name: "testSubnet{{ rpfx }}" + name: testSubnet address_prefix: "10.0.1.0/24" - virtual_network: "testVnet{{ rpfx }}" + virtual_network: testVnet - name: Create public IP address azure_rm_publicipaddress: resource_group: "{{ resource_group }}" allocation_method: Static - name: "testPublicIP{{ rpfx }}" + name: testPublicIP - name: Create virtual network inteface cards for VM A and B azure_rm_networkinterface: resource_group: "{{ resource_group }}" name: "vmforimage{{ rpfx }}nic" - virtual_network: "testVnet{{ rpfx }}" - subnet: "testSubnet{{ rpfx }}" + virtual_network: testVnet + subnet: testSubnet - name: Create VM azure_rm_virtualmachine: diff --git a/tests/integration/targets/azure_rm_sqlserver/tasks/main.yml b/tests/integration/targets/azure_rm_sqlserver/tasks/main.yml index 7a6575d9b..d18d92702 100644 --- a/tests/integration/targets/azure_rm_sqlserver/tasks/main.yml +++ b/tests/integration/targets/azure_rm_sqlserver/tasks/main.yml @@ -143,48 +143,6 @@ - output.changed == false - output.status == 'Online' -# test database point in time restore -- name: Gather facts SQL Database and wait for restore point - azure_rm_sqldatabase_info: - resource_group: "{{ resource_group }}" - server_name: sqlsrv{{ random_postfix }} - name: database{{ random_postfix }} - register: output - until: output.databases[0].earliest_restore_date != None - retries: 10 - delay: 20 -- name: Assert that it can be restored from - assert: - that: - - output.databases[0].id != None - - output.databases[0].earliest_restore_date != None - -- name: Create second SQL Database, restoring from the previous Database - azure_rm_sqldatabase: - resource_group: "{{ resource_group }}" - create_mode: point_in_time_restore - restore_point_in_time: "{{ output.databases[0].earliest_restore_date }}" - source_database_id: "{{ output.databases[0].id }}" - server_name: sqlsrv{{ random_postfix }} - name: database{{ random_postfix }}PITR - register: output -- name: Assert the state has changed - assert: - that: - - output.changed - -- name: Delete instance of SQL Database Point in time recovery - azure_rm_sqldatabase: - resource_group: "{{ resource_group }}" - server_name: sqlsrv{{ random_postfix }} - name: database{{ random_postfix }}PITR - state: absent - register: output -- name: Assert the state has changed - assert: - that: - - output.changed - # test database facter: - name: Create second SQL Database azure_rm_sqldatabase: diff --git a/tests/integration/targets/inventory_azure/playbooks/vars.yml b/tests/integration/targets/inventory_azure/playbooks/vars.yml index dc6bbe080..c2aa787df 100644 --- a/tests/integration/targets/inventory_azure/playbooks/vars.yml +++ b/tests/integration/targets/inventory_azure/playbooks/vars.yml @@ -11,4 +11,4 @@ security_group: "{{ 'sg' ~ uid_short }}" public_ip_name: "{{ 'ip' ~ uid_short }}" interface_name: "{{ 'int' ~ uid_short }}" network: 10.42.0.0/24 -subnet: 10.42.0.0/28 +subnet: 10.42.0.0/28 \ No newline at end of file diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index f7c936331..a8d4d398b 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -254,6 +254,7 @@ plugins/modules/azure_rm_servicebussaspolicy.py validate-modules:doc-required-mi plugins/modules/azure_rm_snapshot.py validate-modules:doc-required-mismatch plugins/modules/azure_rm_snapshot.py validate-modules:invalid-ansiblemodule-schema plugins/modules/azure_rm_sqldatabase.py validate-modules:parameter-type-not-in-doc +plugins/modules/azure_rm_sqldatabase.py validate-modules:invalid-ansiblemodule-schema plugins/modules/azure_rm_sqldatabase_info.py validate-modules:parameter-type-not-in-doc plugins/modules/azure_rm_sqldatabase_info.py validate-modules:parameter-list-no-elements plugins/modules/azure_rm_sqlfirewallrule.py validate-modules:parameter-type-not-in-doc diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index f7c936331..a8d4d398b 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -254,6 +254,7 @@ plugins/modules/azure_rm_servicebussaspolicy.py validate-modules:doc-required-mi plugins/modules/azure_rm_snapshot.py validate-modules:doc-required-mismatch plugins/modules/azure_rm_snapshot.py validate-modules:invalid-ansiblemodule-schema plugins/modules/azure_rm_sqldatabase.py validate-modules:parameter-type-not-in-doc +plugins/modules/azure_rm_sqldatabase.py validate-modules:invalid-ansiblemodule-schema plugins/modules/azure_rm_sqldatabase_info.py validate-modules:parameter-type-not-in-doc plugins/modules/azure_rm_sqldatabase_info.py validate-modules:parameter-list-no-elements plugins/modules/azure_rm_sqlfirewallrule.py validate-modules:parameter-type-not-in-doc diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index f7c936331..a8d4d398b 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -254,6 +254,7 @@ plugins/modules/azure_rm_servicebussaspolicy.py validate-modules:doc-required-mi plugins/modules/azure_rm_snapshot.py validate-modules:doc-required-mismatch plugins/modules/azure_rm_snapshot.py validate-modules:invalid-ansiblemodule-schema plugins/modules/azure_rm_sqldatabase.py validate-modules:parameter-type-not-in-doc +plugins/modules/azure_rm_sqldatabase.py validate-modules:invalid-ansiblemodule-schema plugins/modules/azure_rm_sqldatabase_info.py validate-modules:parameter-type-not-in-doc plugins/modules/azure_rm_sqldatabase_info.py validate-modules:parameter-list-no-elements plugins/modules/azure_rm_sqlfirewallrule.py validate-modules:parameter-type-not-in-doc diff --git a/tests/utils/ado/ado.sh b/tests/utils/ado/ado.sh index 5693444c7..4d666dced 100755 --- a/tests/utils/ado/ado.sh +++ b/tests/utils/ado/ado.sh @@ -18,7 +18,6 @@ else sudo apt install software-properties-common sudo add-apt-repository ppa:deadsnakes/ppa sudo apt install python"$2" -y - sudo apt install python3-dateutil sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python"$2" 1 fi