From 48ffad26ed842bfaca84a4fa0c09cdd9b62867aa Mon Sep 17 00:00:00 2001 From: Taseer Ahmed Date: Thu, 19 Jul 2018 10:26:56 +0500 Subject: [PATCH] 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 --- library/odl_usermod.py | 6 ++++++ 1 file changed, 6 insertions(+) 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: -- 2.36.6