Qtree was not idempotent (#58596)

* fixes

* fixes
This commit is contained in:
Chris Archibald 2019-07-10 17:18:18 -07:00 committed by Jake Jackson
parent fd9b52f305
commit ee24e6c5be
2 changed files with 28 additions and 39 deletions

View file

@ -35,26 +35,31 @@ options:
description: description:
- The name of the qtree to manage. - The name of the qtree to manage.
required: true required: true
type: str
from_name: from_name:
description: description:
- Name of the qtree to be renamed. - Name of the qtree to be renamed.
version_added: '2.7' version_added: '2.7'
type: str
flexvol_name: flexvol_name:
description: description:
- The name of the FlexVol the qtree should exist on. Required when C(state=present). - The name of the FlexVol the qtree should exist on. Required when C(state=present).
required: true required: true
type: str
vserver: vserver:
description: description:
- The name of the vserver to use. - The name of the vserver to use.
required: true required: true
type: str
export_policy: export_policy:
description: description:
- The name of the export policy to apply. - The name of the export policy to apply.
version_added: '2.9' version_added: '2.9'
type: str
security_style: security_style:
description: description:
@ -72,6 +77,7 @@ options:
description: description:
- File permissions bits of the qtree. - File permissions bits of the qtree.
version_added: '2.9' version_added: '2.9'
type: str
''' '''
@ -81,6 +87,10 @@ EXAMPLES = """
state: present state: present
name: ansibleQTree name: ansibleQTree
flexvol_name: ansibleVolume flexvol_name: ansibleVolume
export_policy: policyName
security_style: mixed
oplocks: disabled
unix_permissions:
vserver: ansibleVServer vserver: ansibleVServer
hostname: "{{ netapp_hostname }}" hostname: "{{ netapp_hostname }}"
username: "{{ netapp_username }}" username: "{{ netapp_username }}"
@ -169,7 +179,7 @@ class NetAppOntapQTree(object):
qtree_list_iter.add_child_elem(query) qtree_list_iter.add_child_elem(query)
result = self.server.invoke_successfully(qtree_list_iter, result = self.server.invoke_successfully(qtree_list_iter,
enable_tunneling=True) enable_tunneling=True)
return_q = False return_q = None
if (result.get_child_by_name('num-records') and if (result.get_child_by_name('num-records') and
int(result.get_child_content('num-records')) >= 1): int(result.get_child_content('num-records')) >= 1):
return_q = {'export_policy': result['attributes-list']['qtree-info']['export-policy'], return_q = {'export_policy': result['attributes-list']['qtree-info']['export-policy'],
@ -259,48 +269,28 @@ class NetAppOntapQTree(object):
def apply(self): def apply(self):
'''Call create/delete/modify/rename operations''' '''Call create/delete/modify/rename operations'''
# changed = False
# rename_qtree = False
# modified_qtree = None
changed, rename_qtree, modified_qtree = False, False, None
netapp_utils.ems_log_event("na_ontap_qtree", self.server) netapp_utils.ems_log_event("na_ontap_qtree", self.server)
qtree_detail = self.get_qtree() current = self.get_qtree()
if qtree_detail: rename, cd_action, modify = None, None, None
# delete or modify qtree
if self.parameters['state'] == 'absent': # delete
changed = True
else:
modified_qtree = self.na_helper.get_modified_attributes(
qtree_detail, self.parameters)
if modified_qtree is not None:
changed = True
elif self.parameters['state'] == 'present':
# create or rename qtree
if self.parameters.get('from_name'): if self.parameters.get('from_name'):
if self.get_qtree(self.parameters['from_name']) is None: rename = self.na_helper.is_rename_action(self.get_qtree(self.parameters['from_name']), current)
self.module.fail_json(
msg="Error renaming qtree %s: does not exists"
% self.parameters['from_name'])
else: else:
changed = True cd_action = self.na_helper.get_cd_action(current, self.parameters)
rename_qtree = True if cd_action is None and self.parameters['state'] == 'present':
else: modify = self.na_helper.get_modified_attributes(current, self.parameters)
changed = True if self.na_helper.changed:
if changed:
if self.module.check_mode: if self.module.check_mode:
pass pass
else: else:
if self.parameters['state'] == 'present': if rename:
if rename_qtree:
self.rename_qtree() self.rename_qtree()
elif modified_qtree: if cd_action == 'create':
self.modify_qtree()
else:
self.create_qtree() self.create_qtree()
elif self.parameters['state'] == 'absent': elif cd_action == 'delete':
self.delete_qtree() self.delete_qtree()
elif modify:
self.module.exit_json(changed=changed) self.modify_qtree()
self.module.exit_json(changed=self.na_helper.changed)
def main(): def main():

View file

@ -3436,7 +3436,6 @@ lib/ansible/modules/storage/netapp/na_ontap_nvme_subsystem.py E337
lib/ansible/modules/storage/netapp/na_ontap_portset.py E337 lib/ansible/modules/storage/netapp/na_ontap_portset.py E337
lib/ansible/modules/storage/netapp/na_ontap_portset.py E338 lib/ansible/modules/storage/netapp/na_ontap_portset.py E338
lib/ansible/modules/storage/netapp/na_ontap_qos_policy_group.py E337 lib/ansible/modules/storage/netapp/na_ontap_qos_policy_group.py E337
lib/ansible/modules/storage/netapp/na_ontap_qtree.py E337
lib/ansible/modules/storage/netapp/na_ontap_qtree.py E338 lib/ansible/modules/storage/netapp/na_ontap_qtree.py E338
lib/ansible/modules/storage/netapp/na_ontap_security_key_manager.py E337 lib/ansible/modules/storage/netapp/na_ontap_security_key_manager.py E337
lib/ansible/modules/storage/netapp/na_ontap_security_key_manager.py E338 lib/ansible/modules/storage/netapp/na_ontap_security_key_manager.py E338