Deal with corner cases in custom module 19/74219/1
authorTaseer Ahmed <taseer94@gmail.com>
Thu, 19 Jul 2018 05:26:56 +0000 (10:26 +0500)
committerTaseer Ahmed <taseer94@gmail.com>
Thu, 19 Jul 2018 05:26:56 +0000 (10:26 +0500)
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 <taseer94@gmail.com>
library/odl_usermod.py

index c5a1223b588852e4debbeb23c23d0503d8433ad2..8ce0956ad4cab56711d2cf584d6f4c3372a271d5 100644 (file)
@@ -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: