snapshot/scheduler: Check the correctness of Jobname and Volname
authorAvra Sengupta <asengupt@redhat.com>
Mon, 6 Apr 2015 08:43:09 +0000 (14:13 +0530)
committerVijay Bellur <vbellur@redhat.com>
Tue, 7 Apr 2015 13:37:32 +0000 (06:37 -0700)
Check for the correctness of Jobname and Volname. They should
not be empty, and should contain only one word.

If this condition is met, the rest of the whitespaces are
also striped, before processing the command.

Change-Id: I2c9503ab86456e0f4b37e31d483ee8b2d0b0e1af
BUG: 1209120
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
Reviewed-on: http://review.gluster.org/10137
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Aravinda VK <avishwan@redhat.com>
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
extras/snap_scheduler/snap_scheduler.py

index fda0fd3310f3fc241b6cb4cb055a970173257565..65c89f1ee5bab98388fc25430caf989426e27f74 100755 (executable)
@@ -373,6 +373,24 @@ def initialise_scheduler():
     return ret
 
 
+def syntax_checker(args):
+    ret = False
+
+    if (len(args.jobname.split()) != 1):
+        output("Invalid Jobname. Jobname should not be empty and should not contain \" \" character.")
+        return ret
+
+    if (len(args.volname.split()) != 1):
+        output("Invalid Volname. Volname should not be empty and should not contain \" \" character.")
+        return ret
+
+    args.jobname=args.jobname.strip()
+    args.volname=args.volname.strip()
+
+    ret = True
+    return ret
+
+
 def perform_operation(args):
     ret = False
 
@@ -433,6 +451,9 @@ def perform_operation(args):
 
     # Add snapshot schedules
     if args.action == "add":
+        ret = syntax_checker(args)
+        if not ret:
+            return ret
         ret = add_schedules(args.jobname, args.schedule, args.volname)
         if not ret:
             output("Failed to add snapshot schedule")
@@ -442,6 +463,9 @@ def perform_operation(args):
 
     # Delete snapshot schedules
     if args.action == "delete":
+        ret = syntax_checker(args)
+        if not ret:
+            return ret
         ret = delete_schedules(args.jobname)
         if not ret:
             output("Failed to delete snapshot schedule")
@@ -451,6 +475,9 @@ def perform_operation(args):
 
     # Edit snapshot schedules
     if args.action == "edit":
+        ret = syntax_checker(args)
+        if not ret:
+            return ret
         ret = edit_schedules(args.jobname, args.schedule, args.volname)
         if not ret:
             output("Failed to edit snapshot schedule")