From f1f5782856d1790205383b992d415dc83f2c5225 Mon Sep 17 00:00:00 2001 From: Andrea Decorte Date: Wed, 18 May 2022 21:39:28 +0200 Subject: [PATCH] Add support for ZRS disks in virtualdisk and manageddisk modules --- plugins/modules/azure_rm_manageddisk.py | 8 +- plugins/modules/azure_rm_virtualmachine.py | 6 +- .../azure_rm_manageddisk/tasks/main.yml | 56 +++++++++++- .../azure_rm_virtualmachine/inventory.yml | 4 + .../targets/azure_rm_virtualmachine/main.yml | 2 +- .../tasks/azure_test_minimal_manageddisk.yml | 89 +++++++++++++++++++ 6 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 tests/integration/targets/azure_rm_virtualmachine/tasks/azure_test_minimal_manageddisk.yml diff --git a/plugins/modules/azure_rm_manageddisk.py b/plugins/modules/azure_rm_manageddisk.py index cef701b1e8..4c6dfe1fc5 100644 --- a/plugins/modules/azure_rm_manageddisk.py +++ b/plugins/modules/azure_rm_manageddisk.py @@ -47,13 +47,17 @@ - If not specified, the disk is created as C(Standard_LRS). - C(Standard_LRS) is for Standard HDD. - C(StandardSSD_LRS) (added in 2.8) is for Standard SSD. + - C(StandardSSD_ZRS) is for Standard SSD Zone-redundant. - C(Premium_LRS) is for Premium SSD. - - C(UltraSSD_LRS) (added in 2.8) is for Ultra SSD, which is in preview mode, and only available on select instance types. + - C(Premium_ZRS) is for Premium SSD Zone-redundant. + - C(UltraSSD_LRS) (added in 2.8) is for Ultra SSD, which is only available on select instance types. - See U(https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-types) for more information about disk types. choices: - Standard_LRS - StandardSSD_LRS + - StandardSSD_ZRS - Premium_LRS + - Premium_ZRS - UltraSSD_LRS create_option: description: @@ -275,7 +279,7 @@ def __init__(self): ), storage_account_type=dict( type='str', - choices=['Standard_LRS', 'StandardSSD_LRS', 'Premium_LRS', 'UltraSSD_LRS'] + choices=['Standard_LRS', 'StandardSSD_LRS', 'StandardSSD_ZRS', 'Premium_LRS', 'Premium_ZRS', 'UltraSSD_LRS'] ), create_option=dict( type='str', diff --git a/plugins/modules/azure_rm_virtualmachine.py b/plugins/modules/azure_rm_virtualmachine.py index 40e998b5a1..044ecc20df 100644 --- a/plugins/modules/azure_rm_virtualmachine.py +++ b/plugins/modules/azure_rm_virtualmachine.py @@ -182,7 +182,9 @@ choices: - Standard_LRS - StandardSSD_LRS + - StandardSSD_ZRS - Premium_LRS + - Premium_ZRS os_disk_name: description: - OS disk name. @@ -232,7 +234,9 @@ choices: - Standard_LRS - StandardSSD_LRS + - StandardSSD_ZRS - Premium_LRS + - Premium_ZRS storage_account_name: description: - Name of an existing storage account that supports creation of VHD blobs. @@ -879,7 +883,7 @@ def __init__(self): storage_blob_name=dict(type='str', aliases=['storage_blob']), os_disk_caching=dict(type='str', aliases=['disk_caching'], choices=['ReadOnly', 'ReadWrite']), os_disk_size_gb=dict(type='int'), - managed_disk_type=dict(type='str', choices=['Standard_LRS', 'StandardSSD_LRS', 'Premium_LRS']), + managed_disk_type=dict(type='str', choices=['Standard_LRS', 'StandardSSD_LRS', 'StandardSSD_ZRS', 'Premium_LRS', 'Premium_ZRS']), os_disk_name=dict(type='str'), proximity_placement_group=dict(type='dict', options=proximity_placement_group_spec), os_type=dict(type='str', choices=['Linux', 'Windows'], default='Linux'), diff --git a/tests/integration/targets/azure_rm_manageddisk/tasks/main.yml b/tests/integration/targets/azure_rm_manageddisk/tasks/main.yml index 3abaaefb63..426c8ba28f 100644 --- a/tests/integration/targets/azure_rm_manageddisk/tasks/main.yml +++ b/tests/integration/targets/azure_rm_manageddisk/tasks/main.yml @@ -135,7 +135,7 @@ azure_rm_manageddisk_info: resource_group: "{{ resource_group }}" name: "md{{ rpfx }}1" - register: output + register: output - assert: that: @@ -164,6 +164,60 @@ that: - not output.changed + - name: Update account_type + azure_rm_manageddisk: + resource_group: "{{ resource_group }}" + name: "md{{ rpfx }}1" + storage_account_type: "StandardSSD_ZRS" + disk_size_gb: 2 + register: output + + - assert: + that: + - output.changed + - output.state.storage_account_type == "StandardSSD_ZRS" + - output.state.disk_size_gb == 2 + + - name: Gather facts to one specific disk + azure_rm_manageddisk_info: + resource_group: "{{ resource_group }}" + name: "md{{ rpfx }}1" + register: output + + - assert: + that: + - "output.ansible_info.azure_managed_disk | length == 1" + - output.ansible_info.azure_managed_disk[0].storage_account_type == "StandardSSD_ZRS" + - output.ansible_info.azure_managed_disk[0].disk_size_gb == 2 + - "output.ansible_info.azure_managed_disk[0].os_type == 'linux'" + + - name: Update again account_type + azure_rm_manageddisk: + resource_group: "{{ resource_group }}" + name: "md{{ rpfx }}1" + storage_account_type: "Premium_ZRS" + disk_size_gb: 2 + register: output + + - assert: + that: + - output.changed + - output.state.storage_account_type == "Premium_ZRS" + - output.state.disk_size_gb == 2 + + - name: Gather facts to one specific disk + azure_rm_manageddisk_info: + resource_group: "{{ resource_group }}" + name: "md{{ rpfx }}1" + register: output + + - assert: + that: + - "output.ansible_info.azure_managed_disk | length == 1" + - output.ansible_info.azure_managed_disk[0].storage_account_type == "Premium_ZRS" + - output.ansible_info.azure_managed_disk[0].disk_size_gb == 2 + - "output.ansible_info.azure_managed_disk[0].os_type == 'linux'" + - name: Delete managed disk (Check Mode) azure_rm_manageddisk: resource_group: "{{ resource_group }}" diff --git a/tests/integration/targets/azure_rm_virtualmachine/inventory.yml b/tests/integration/targets/azure_rm_virtualmachine/inventory.yml index acd98ebf7f..6d9790a9b3 100644 --- a/tests/integration/targets/azure_rm_virtualmachine/inventory.yml +++ b/tests/integration/targets/azure_rm_virtualmachine/inventory.yml @@ -17,6 +17,10 @@ all: network: 10.42.3.0/24 subnet: 10.42.3.0/28 + azure_test_minimal_manageddisk: + network: 10.42.3.0/24 + subnet: 10.42.3.0/28 + azure_test_dual_nic: network: 10.42.4.0/24 subnet: 10.42.4.0/28 diff --git a/tests/integration/targets/azure_rm_virtualmachine/main.yml b/tests/integration/targets/azure_rm_virtualmachine/main.yml index 7722487bff..c9c9158c4e 100644 --- a/tests/integration/targets/azure_rm_virtualmachine/main.yml +++ b/tests/integration/targets/azure_rm_virtualmachine/main.yml @@ -1,4 +1,4 @@ -- name: Run Azurue VM tests in parallel +- name: Run Azure VM tests in parallel hosts: all gather_facts: no strategy: free diff --git a/tests/integration/targets/azure_rm_virtualmachine/tasks/azure_test_minimal_manageddisk.yml b/tests/integration/targets/azure_rm_virtualmachine/tasks/azure_test_minimal_manageddisk.yml new file mode 100644 index 0000000000..80be1f2dfe --- /dev/null +++ b/tests/integration/targets/azure_rm_virtualmachine/tasks/azure_test_minimal_manageddisk.yml @@ -0,0 +1,89 @@ +- include_tasks: setup.yml + +- name: Create minimal VM with defaults and a custom managed disk type + azure_rm_virtualmachine: + resource_group: "{{ resource_group }}" + name: "{{ vm_name }}" + admin_username: "testuser" + ssh_password_enabled: false + managed_disk_type: StandardSSD_ZRS + public_ip_allocation_method: Disabled + ssh_public_keys: + - path: /home/testuser/.ssh/authorized_keys + key_data: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfoYlIV4lTPZTv7hXaVwQQuqBgGs4yeNRX0SPo2+HQt9u4X7IGwrtXc0nEUm6LfaCikMH58bOL8f20NTGz285kxdFHZRcBXtqmnMz2rXwhK9gwq5h1khc+GzHtdcJXsGA4y0xuaNcidcg04jxAlN/06fwb/VYwwWTVbypNC0gpGEpWckCNm8vlDlA55sU5et0SZ+J0RKVvEaweUOeNbFZqckGPA384imfeYlADppK/7eAxqfBVadVvZG8IJk4yvATgaIENIFj2cXxqu2mQ/Bp5Wr45uApvJsFXmi+v/nkiOEV1QpLOnEwAZo6EfFS4CCQtsymxJCl1PxdJ5LD4ZOtP xiuxi.sun@qq.com" + vm_size: Standard_B1ms + virtual_network: "{{ network_name }}" + image: + offer: UbuntuServer + publisher: Canonical + sku: 16.04-LTS + version: latest + register: vm_output + +- name: Delete VM + azure_rm_virtualmachine: + resource_group: "{{ resource_group }}" + name: "{{ vm_name }}" + remove_on_absent: all_autocreated + state: absent + +- name: Query auto created NIC + azure_rm_networkinterface_info: + resource_group: "{{ resource_group }}" + name: "{{ vm_name }}01" + register: nic_result + +- name: Query auto created security group + azure_rm_securitygroup_info: + resource_group: "{{ resource_group }}" + name: "{{ vm_name }}01" + register: nsg_result + +- name: Query auto created disk + azure_rm_manageddisk_info: + resource_group: "{{ resource_group }}" + name: "{{ vm_name }}" + register: disk_result + +- name: Assert that disk was created with the right storage class + assert: + that: + - disk_result.ansible_info.azure_managed_disk[0].storage_account_type == "StandardSSD_ZRS" + +- name: Assert that autocreated resources were deleted + assert: + that: + - nic_result.networkinterfaces | length == 0 + - nsg_result.securitygroups | length == 0 + +- name: Destroy disk + azure_rm_manageddisk: + resource_group: "{{ resource_group }}" + name: "{{ vm_name }}" + state: absent + +- name: Destroy subnet + azure_rm_subnet: + resource_group: "{{ resource_group }}" + virtual_network: "{{ network_name }}" + name: "{{ subnet_name }}" + state: absent + +- name: Destroy virtual network + azure_rm_virtualnetwork: + resource_group: "{{ resource_group }}" + name: "{{ network_name }}" + state: absent + +- name: Destroy availability set + azure_rm_availabilityset: + resource_group: "{{ resource_group }}" + name: "{{ availability_set }}" + state: absent + +- name: Destroy storage account + azure_rm_storageaccount: + resource_group: "{{ resource_group }}" + name: "{{ storage_account }}" + force_delete_nonempty: yes + state: absent