From: Taseer Ahmed Date: Thu, 19 Jul 2018 05:26:56 +0000 (+0500) Subject: Deal with corner cases in custom module X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=48ffad26ed842bfaca84a4fa0c09cdd9b62867aa;p=integration%2Fpackaging%2Fansible-opendaylight.git Deal with corner cases in custom module Fails if username not provided when deleting the user, and fails if username or password not provided when creating the user. Change-Id: Id22c19af7507ecfb7487eaf3f2eb4208f032edcb JIRA: INTPAK-177 Signed-off-by: Taseer Ahmed --- diff --git a/library/odl_usermod.py b/library/odl_usermod.py index c5a1223..8ce0956 100644 --- a/library/odl_usermod.py +++ b/library/odl_usermod.py @@ -72,6 +72,9 @@ def main(): state = module.params['state'] if state == 'absent': + if not username: + module.exit_json(changed=False, failed=True, + msg="Username not provided") ls_users_cmd = build_cmd(module, "-l") (rc, out, err) = module.run_command(ls_users_cmd) if username in out: @@ -83,6 +86,9 @@ def main(): else: module.exit_json(changed=False, msg="No such user exists") elif state == 'present': + if not username or not password: + module.exit_json(changed=False, failed=True, + msg="Username or password not provided") ls_users_cmd = build_cmd(module, "-l") (rc, out, err) = module.run_command(ls_users_cmd) if rc is not None and rc != 0: