Make na_ontap_user idempotent (#51509)

* changes to clusteR

* Revert "changes to clusteR"

This reverts commit 33ee1b71e4bc8435fb315762a871f8c4cb6c5f80.

* Fix Idempotent issue

* Fix author

* Fix author
pull/52519/head
Chris Archibald 6 years ago committed by John R Barker
parent 053081a8a0
commit bd8e75a67b

@ -1,6 +1,6 @@
#!/usr/bin/python
# (c) 2018, NetApp, Inc
# (c) 2018-2019, NetApp, Inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
@ -304,8 +304,10 @@ class NetAppOntapUser(object):
except netapp_utils.zapi.NaApiError as error:
if to_native(error.code) == '13114':
return False
else:
self.module.fail_json(msg='Error setting password for user %s: %s' % (self.parameters['name'], to_native(error)),
# if the user give the same password, instead of returning an error, return ok
if to_native(error.code) == '13214' and error.message.startswith('New password must be different than the old password.'):
return False
self.module.fail_json(msg='Error setting password for user %s: %s' % (self.parameters['name'], to_native(error)),
exception=traceback.format_exc())
self.server.set_vserver(None)
@ -324,7 +326,8 @@ class NetAppOntapUser(object):
if self.parameters.get('set_password') is not None:
self.na_helper.changed = True
current = self.get_user()
current['lock_user'] = self.na_helper.get_value_for_bool(True, current['lock_user'])
if current is not None:
current['lock_user'] = self.na_helper.get_value_for_bool(True, current['lock_user'])
modify = self.na_helper.get_modified_attributes(current, self.parameters)
if self.na_helper.changed:
@ -343,7 +346,8 @@ class NetAppOntapUser(object):
else:
self.unlock_given_user()
elif not create_delete_decision and self.parameters.get('set_password') is not None:
self.change_password()
# if change password return false nothing has changed so we need to set changed to False
self.na_helper.changed = self.change_password()
self.module.exit_json(changed=self.na_helper.changed)

@ -17,7 +17,7 @@ from ansible.modules.storage.netapp.na_ontap_user \
import NetAppOntapUser as my_module # module under test
if not netapp_utils.has_netapp_lib():
pytestmark = pytest.skip('skipping as missing required netapp_lib')
pytestmark = pytest.mark.skip('skipping as missing required netapp_lib')
def set_module_args(args):

Loading…
Cancel
Save