From a8a5940f9a203541ef6d4968e3ad5ff49082fb73 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Fri, 14 Jul 2023 18:44:51 +0800 Subject: [PATCH 1/7] Add new parameters to azure_rm_storageshare.py --- plugins/modules/azure_rm_storageshare.py | 36 +++++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/plugins/modules/azure_rm_storageshare.py b/plugins/modules/azure_rm_storageshare.py index e4749b87a..da010e087 100644 --- a/plugins/modules/azure_rm_storageshare.py +++ b/plugins/modules/azure_rm_storageshare.py @@ -57,7 +57,23 @@ - The maximum size of the file share, in gigabytes. Must be greater than 0, and less than or equal to 5TB (5120). For large file shares, the maximum size is 102400. By default 102400 type: int - + enabled_protocols: + description: + - The authentication protocol that is used for the file share. + - Can only be specified when creating a share. + type: str + choices: + - SMB + - NFS + root_squash: + description: + - The property is for NFS share only. + - The default is C(NoRootSquash). + type: str + choices: + - NoRootSquash + - RootSquash + - AllSquash extends_documentation_fragment: - azure.azcollection.azure @@ -184,6 +200,8 @@ def __init__(self): choices=['TransactionOptimized', 'Hot', 'Cool', 'Premium']), quota=dict(type='int', default=None), metadata=dict(type='dict', default=None), + root_squash=dict(type='str', choices=['NoRootSquash', 'RootSquash', 'AllSquash']), + enabled_protocols=dict(type='str', choices=['SMB', 'NFS']), ) self.results = dict( changed=False, @@ -196,6 +214,8 @@ def __init__(self): self.state = None self.quota = None self.metadata = None + self.root_squash = None + self.enabled_protocols = None self.to_do = Actions.NoAction @@ -259,7 +279,9 @@ def update_needed(self, old_response): ''' return ((self.access_tier is not None) and (self.access_tier != old_response.get('access_tier')) or (self.quota is not None) and (self.quota != old_response.get('share_quota')) or - (self.metadata is not None) and (self.metadata != old_response.get('metadata'))) + (self.metadata is not None) and (self.metadata != old_response.get('metadata')) or + (self.root_squash is not None) and (self.root_squash !=old_response.get('root_squash')) or + (self.enabled_protocols is not None) and (self.enabled_protocols != old_response.get('enabled_protocols'))) def get_share(self): ''' @@ -294,6 +316,8 @@ def storage_share_to_dict(self, storage_share): share_quota=storage_share.share_quota, access_tier=storage_share.access_tier, access_tier_change_time=storage_share.access_tier_change_time, + root_squash=storage_share.root_squash, + enabled_protocols=storage_share.enabled_protocols ) def create_storage_share(self): @@ -308,7 +332,9 @@ def create_storage_share(self): share_name=self.name, file_share=dict(access_tier=self.access_tier, share_quota=self.quota, - metadata=self.metadata)) + metadata=self.metadata, + root_squash=self.root_squash, + enabled_protocols=self.enabled_protocols)) except Exception as e: self.fail("Error creating file share {0} : {1}".format(self.name, str(e))) return self.get_share() @@ -323,7 +349,9 @@ def update_storage_share(self, old_responce): file_share_details = dict( access_tier=self.access_tier if self.access_tier else old_responce.get('access_tier'), share_quota=self.quota if self.quota else old_responce.get('share_quota'), - metadata=self.metadata if self.metadata else old_responce.get('metadata') + metadata=self.metadata if self.metadata else old_responce.get('metadata'), + enabled_protocols=self.enabled_protocols if self.enabled_protocols else oold_responce.get('enabled_protocols'), + root_squash=self.root_squash if self.root_squash else old_responce.get('self.root_squash') ) try: self.storage_client.file_shares.update(resource_group_name=self.resource_group, From 127555a3be53dbf03458d5de6a4ab15bba5f7451 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Mon, 17 Jul 2023 16:21:06 +0800 Subject: [PATCH 2/7] Add test case --- plugins/modules/azure_rm_storageshare.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/modules/azure_rm_storageshare.py b/plugins/modules/azure_rm_storageshare.py index da010e087..1cceaca1e 100644 --- a/plugins/modules/azure_rm_storageshare.py +++ b/plugins/modules/azure_rm_storageshare.py @@ -96,6 +96,15 @@ key1: value1 key2: value2 +- name: Create share with enalbed protocols + azure_rm_storageshare: + name: "{{ share_name }}" + resource_group: "{{ resource_group }}" + account_name: "{{ storage_account }}" + access_tier: "{{ access_tier }}" + root_squash: RootSquash + enabled_protocols: NFS + - name: Delete storage share azure_rm_storageshare: name: testShare From 495b91a25e47e2937d0b58181ecdf9b3ceb61004 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Mon, 17 Jul 2023 17:06:59 +0800 Subject: [PATCH 3/7] Fix sanity fail --- plugins/modules/azure_rm_storageshare.py | 4 +- .../azure_rm_storageshare/tasks/main.yml | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/plugins/modules/azure_rm_storageshare.py b/plugins/modules/azure_rm_storageshare.py index 1cceaca1e..747a24ac0 100644 --- a/plugins/modules/azure_rm_storageshare.py +++ b/plugins/modules/azure_rm_storageshare.py @@ -289,7 +289,7 @@ def update_needed(self, old_response): return ((self.access_tier is not None) and (self.access_tier != old_response.get('access_tier')) or (self.quota is not None) and (self.quota != old_response.get('share_quota')) or (self.metadata is not None) and (self.metadata != old_response.get('metadata')) or - (self.root_squash is not None) and (self.root_squash !=old_response.get('root_squash')) or + (self.root_squash is not None) and (self.root_squash != old_response.get('root_squash')) or (self.enabled_protocols is not None) and (self.enabled_protocols != old_response.get('enabled_protocols'))) def get_share(self): @@ -359,7 +359,7 @@ def update_storage_share(self, old_responce): access_tier=self.access_tier if self.access_tier else old_responce.get('access_tier'), share_quota=self.quota if self.quota else old_responce.get('share_quota'), metadata=self.metadata if self.metadata else old_responce.get('metadata'), - enabled_protocols=self.enabled_protocols if self.enabled_protocols else oold_responce.get('enabled_protocols'), + enabled_protocols=self.enabled_protocols if self.enabled_protocols else old_responce.get('enabled_protocols'), root_squash=self.root_squash if self.root_squash else old_responce.get('self.root_squash') ) try: diff --git a/tests/integration/targets/azure_rm_storageshare/tasks/main.yml b/tests/integration/targets/azure_rm_storageshare/tasks/main.yml index ffe672d4d..3d902fe27 100644 --- a/tests/integration/targets/azure_rm_storageshare/tasks/main.yml +++ b/tests/integration/targets/azure_rm_storageshare/tasks/main.yml @@ -107,12 +107,55 @@ - share_facts.storageshares.id is defined - share_facts.storageshares.etag is defined +- name: Create secondary storage account + azure_rm_storageaccount: + resource_group: "{{ resource_group }}" + name: "{{ storage_account }}02" + account_type: Premium_LRS + kind: FileStorage + large_file_shares_state: Enabled + +- name: Create share with enabled protocols + azure_rm_storageshare: + name: "{{ share_name }}02" + resource_group: "{{ resource_group }}" + account_name: "{{ storage_account }}02" + access_tier: Premium + root_squash: RootSquash + enabled_protocols: NFS + register: create_output + +- name: Assert create success + assert: + that: + - create_output.changed + +- name: Get share details + azure_rm_storageshare_info: + name: "{{ share_name }}02" + resource_group: "{{ resource_group }}" + account_name: "{{ storage_account }}02" + register: share_facts + +- name: Assert the facts + assert: + that: + - share_facts.storageshares.root_squash == 'RootSquash' + - share_facts.storageshares.enabled_protocols == 'NFS' + - name: Delete share azure_rm_storageshare: name: "{{ share_name }}" resource_group: "{{ resource_group }}" account_name: "{{ storage_account }}" state: absent + +- name: Delete share + azure_rm_storageshare: + name: "{{ share_name }}02" + resource_group: "{{ resource_group }}" + account_name: "{{ storage_account }}02" + state: absent register: delete_output - name: Pause for 3 minutes to waiting delete @@ -124,3 +167,9 @@ resource_group: "{{ resource_group }}" name: "{{ storage_account }}" state: absent + +- name: Delete storage account + azure_rm_storageaccount: + resource_group: "{{ resource_group }}" + name: "{{ storage_account }}02" + state: absent From c1465a33c74fcaa578b5be155149638097f3958a Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Mon, 17 Jul 2023 17:47:27 +0800 Subject: [PATCH 4/7] small change --- tests/integration/targets/azure_rm_storageshare/tasks/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/targets/azure_rm_storageshare/tasks/main.yml b/tests/integration/targets/azure_rm_storageshare/tasks/main.yml index 3d902fe27..ae4efbc3f 100644 --- a/tests/integration/targets/azure_rm_storageshare/tasks/main.yml +++ b/tests/integration/targets/azure_rm_storageshare/tasks/main.yml @@ -113,7 +113,6 @@ name: "{{ storage_account }}02" account_type: Premium_LRS kind: FileStorage - large_file_shares_state: Enabled - name: Create share with enabled protocols azure_rm_storageshare: From a807795cb8f80379965300b406136c5b012a5539 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Mon, 17 Jul 2023 18:09:37 +0800 Subject: [PATCH 5/7] small change 02 --- .../azure_rm_storageshare/tasks/main.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/integration/targets/azure_rm_storageshare/tasks/main.yml b/tests/integration/targets/azure_rm_storageshare/tasks/main.yml index ae4efbc3f..79aee4b85 100644 --- a/tests/integration/targets/azure_rm_storageshare/tasks/main.yml +++ b/tests/integration/targets/azure_rm_storageshare/tasks/main.yml @@ -1,7 +1,7 @@ --- - name: Set storage account name set_fact: - storage_account: "sb{{ resource_group | hash('md5') | truncate(22, True, '') }}" + storage_account: "s{{ resource_group | hash('md5') | truncate(22, True, '') }}" - name: Create storage account azure_rm_storageaccount: @@ -110,15 +110,15 @@ - name: Create secondary storage account azure_rm_storageaccount: resource_group: "{{ resource_group }}" - name: "{{ storage_account }}02" + name: "{{ storage_account }}2" account_type: Premium_LRS kind: FileStorage - name: Create share with enabled protocols azure_rm_storageshare: - name: "{{ share_name }}02" + name: "{{ share_name }}2" resource_group: "{{ resource_group }}" - account_name: "{{ storage_account }}02" + account_name: "{{ storage_account }}2" access_tier: Premium root_squash: RootSquash enabled_protocols: NFS @@ -131,9 +131,9 @@ - name: Get share details azure_rm_storageshare_info: - name: "{{ share_name }}02" + name: "{{ share_name }}2" resource_group: "{{ resource_group }}" - account_name: "{{ storage_account }}02" + account_name: "{{ storage_account }}2" register: share_facts - name: Assert the facts @@ -151,9 +151,9 @@ - name: Delete share azure_rm_storageshare: - name: "{{ share_name }}02" + name: "{{ share_name }}2" resource_group: "{{ resource_group }}" - account_name: "{{ storage_account }}02" + account_name: "{{ storage_account }}2" state: absent register: delete_output @@ -170,5 +170,5 @@ - name: Delete storage account azure_rm_storageaccount: resource_group: "{{ resource_group }}" - name: "{{ storage_account }}02" + name: "{{ storage_account }}2" state: absent From 3fe62abb547f3752f8318c56dd252ca6b48e9863 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Tue, 18 Jul 2023 14:19:38 +0800 Subject: [PATCH 6/7] remove test case --- .../azure_rm_storageshare/tasks/main.yml | 52 +------------------ 1 file changed, 2 insertions(+), 50 deletions(-) diff --git a/tests/integration/targets/azure_rm_storageshare/tasks/main.yml b/tests/integration/targets/azure_rm_storageshare/tasks/main.yml index 79aee4b85..fd506f38a 100644 --- a/tests/integration/targets/azure_rm_storageshare/tasks/main.yml +++ b/tests/integration/targets/azure_rm_storageshare/tasks/main.yml @@ -1,7 +1,7 @@ --- - name: Set storage account name set_fact: - storage_account: "s{{ resource_group | hash('md5') | truncate(22, True, '') }}" + storage_account: "sb{{ resource_group | hash('md5') | truncate(22, True, '') }}" - name: Create storage account azure_rm_storageaccount: @@ -107,55 +107,13 @@ - share_facts.storageshares.id is defined - share_facts.storageshares.etag is defined -- name: Create secondary storage account - azure_rm_storageaccount: - resource_group: "{{ resource_group }}" - name: "{{ storage_account }}2" - account_type: Premium_LRS - kind: FileStorage - -- name: Create share with enabled protocols - azure_rm_storageshare: - name: "{{ share_name }}2" - resource_group: "{{ resource_group }}" - account_name: "{{ storage_account }}2" - access_tier: Premium - root_squash: RootSquash - enabled_protocols: NFS - register: create_output - -- name: Assert create success - assert: - that: - - create_output.changed - -- name: Get share details - azure_rm_storageshare_info: - name: "{{ share_name }}2" - resource_group: "{{ resource_group }}" - account_name: "{{ storage_account }}2" - register: share_facts - -- name: Assert the facts - assert: - that: - - share_facts.storageshares.root_squash == 'RootSquash' - - share_facts.storageshares.enabled_protocols == 'NFS' - - name: Delete share azure_rm_storageshare: name: "{{ share_name }}" resource_group: "{{ resource_group }}" account_name: "{{ storage_account }}" state: absent - -- name: Delete share - azure_rm_storageshare: - name: "{{ share_name }}2" - resource_group: "{{ resource_group }}" - account_name: "{{ storage_account }}2" - state: absent - register: delete_output + register: delete_ouptut - name: Pause for 3 minutes to waiting delete pause: @@ -166,9 +124,3 @@ resource_group: "{{ resource_group }}" name: "{{ storage_account }}" state: absent - -- name: Delete storage account - azure_rm_storageaccount: - resource_group: "{{ resource_group }}" - name: "{{ storage_account }}2" - state: absent From 775324335f2c35aea4940496c6e8b65c9b4a1fb0 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Tue, 18 Jul 2023 14:20:54 +0800 Subject: [PATCH 7/7] small change --- tests/integration/targets/azure_rm_storageshare/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/azure_rm_storageshare/tasks/main.yml b/tests/integration/targets/azure_rm_storageshare/tasks/main.yml index fd506f38a..ffe672d4d 100644 --- a/tests/integration/targets/azure_rm_storageshare/tasks/main.yml +++ b/tests/integration/targets/azure_rm_storageshare/tasks/main.yml @@ -113,7 +113,7 @@ resource_group: "{{ resource_group }}" account_name: "{{ storage_account }}" state: absent - register: delete_ouptut + register: delete_output - name: Pause for 3 minutes to waiting delete pause: