cb8e9e
From 475b0ff983f3eece51641bb49983295e54187599 Mon Sep 17 00:00:00 2001
cb8e9e
From: Avra Sengupta <asengupt@redhat.com>
cb8e9e
Date: Fri, 29 May 2015 18:11:01 +0530
cb8e9e
Subject: [PATCH 06/18] snapshot/scheduler: Return proper error code in case of
cb8e9e
 failure
cb8e9e
cb8e9e
    Backport of http://review.gluster.org/#/c/11005/
cb8e9e
cb8e9e
ENUM                              RETCODE     ERROR
cb8e9e
----------------------------------------------------------
cb8e9e
INTERNAL_ERROR                    2           Internal Error
cb8e9e
SHARED_STORAGE_DIR_DOESNT_EXIST   3           Shared Storage Dir
cb8e9e
                                              does not exist
cb8e9e
SHARED_STORAGE_NOT_MOUNTED        4           Shared storage is not mounted
cb8e9e
ANOTHER_TRANSACTION_IN_PROGRESS   5           Another transaction is in progress
cb8e9e
INIT_FAILED                       6           Initialisation failed
cb8e9e
SCHEDULING_ALREADY_DISABLED       7           Scheduler is already disabled
cb8e9e
SCHEDULING_ALREADY_ENABLED        8           Scheduler is already enabled
cb8e9e
NODE_NOT_INITIALISED              9           Node not initialised
cb8e9e
ANOTHER_SCHEDULER_ACTIVE          10          Another scheduler is active
cb8e9e
JOB_ALREADY_EXISTS                11          Job already exists
cb8e9e
JOB_NOT_FOUND                     12          Job not found
cb8e9e
INVALID_JOBNAME                   13          Jobname is invalid
cb8e9e
INVALID_VOLNAME                   14          Volname is invalid
cb8e9e
INVALID_SCHEDULE                  15          Schedule is invalid
cb8e9e
INVALID_ARG                       16          Argument is invalid
cb8e9e
cb8e9e
Change-Id: Ia1da166659099f4c951fcdb4d755529e41167b80
cb8e9e
BUG: 1223206
cb8e9e
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
cb8e9e
Reviewed-on: https://code.engineering.redhat.com/gerrit/50090
cb8e9e
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
cb8e9e
Tested-by: Rajesh Joseph <rjoseph@redhat.com>
cb8e9e
---
cb8e9e
 extras/snap_scheduler/snap_scheduler.py | 142 ++++++++++++++++++--------------
cb8e9e
 1 file changed, 81 insertions(+), 61 deletions(-)
cb8e9e
cb8e9e
diff --git a/extras/snap_scheduler/snap_scheduler.py b/extras/snap_scheduler/snap_scheduler.py
cb8e9e
index e7c1791..1c5f938 100755
cb8e9e
--- a/extras/snap_scheduler/snap_scheduler.py
cb8e9e
+++ b/extras/snap_scheduler/snap_scheduler.py
cb8e9e
@@ -38,6 +38,21 @@ tasks = {}
cb8e9e
 longest_field = 12
cb8e9e
 current_scheduler = ""
cb8e9e
 
cb8e9e
+INTERNAL_ERROR = 2
cb8e9e
+SHARED_STORAGE_DIR_DOESNT_EXIST = 3
cb8e9e
+SHARED_STORAGE_NOT_MOUNTED = 4
cb8e9e
+ANOTHER_TRANSACTION_IN_PROGRESS = 5
cb8e9e
+INIT_FAILED = 6
cb8e9e
+SCHEDULING_ALREADY_DISABLED = 7
cb8e9e
+SCHEDULING_ALREADY_ENABLED = 8
cb8e9e
+NODE_NOT_INITIALISED = 9
cb8e9e
+ANOTHER_SCHEDULER_ACTIVE = 10
cb8e9e
+JOB_ALREADY_EXISTS = 11
cb8e9e
+JOB_NOT_FOUND = 12
cb8e9e
+INVALID_JOBNAME = 13
cb8e9e
+INVALID_VOLNAME = 14
cb8e9e
+INVALID_SCHEDULE = 15
cb8e9e
+INVALID_ARG = 16
cb8e9e
 
cb8e9e
 def output(msg):
cb8e9e
     print("%s: %s" % (SCRIPT_NAME, msg))
cb8e9e
@@ -66,7 +81,7 @@ def initLogger():
cb8e9e
 
cb8e9e
 
cb8e9e
 def scheduler_status():
cb8e9e
-    success = False
cb8e9e
+    ret = INTERNAL_ERROR
cb8e9e
     global scheduler_enabled
cb8e9e
     try:
cb8e9e
         f = os.path.realpath(GCRON_TASKS)
cb8e9e
@@ -76,33 +91,32 @@ def scheduler_status():
cb8e9e
         else:
cb8e9e
             log.info("Snapshot scheduler is currently enabled.")
cb8e9e
             scheduler_enabled = True
cb8e9e
-        success = True
cb8e9e
+        ret = 0
cb8e9e
     except:
cb8e9e
         log.error("Failed to enable snapshot scheduling. Error: "
cb8e9e
                   "Failed to check the status of %s.", GCRON_DISABLED)
cb8e9e
 
cb8e9e
-    return success
cb8e9e
+    return ret
cb8e9e
 
cb8e9e
 def enable_scheduler():
cb8e9e
     ret = scheduler_status()
cb8e9e
-    if ret:
cb8e9e
+    if ret == 0:
cb8e9e
         if not scheduler_enabled:
cb8e9e
 
cb8e9e
             # Check if another scheduler is active.
cb8e9e
             ret = get_current_scheduler()
cb8e9e
-            if ret:
cb8e9e
+            if ret == 0:
cb8e9e
                 if (current_scheduler != "none"):
cb8e9e
                     print_str = "Failed to enable snapshot scheduling. " \
cb8e9e
                                 "Error: Another scheduler is active."
cb8e9e
                     log.error(print_str)
cb8e9e
                     output(print_str)
cb8e9e
-                    ret = False
cb8e9e
+                    ret = ANOTHER_SCHEDULER_ACTIVE
cb8e9e
                     return ret
cb8e9e
             else:
cb8e9e
                 print_str = "Failed to get current scheduler info."
cb8e9e
                 log.error(print_str)
cb8e9e
                 output(print_str)
cb8e9e
-                ret = False
cb8e9e
                 return ret
cb8e9e
 
cb8e9e
             log.info("Enabling snapshot scheduler.")
cb8e9e
@@ -118,23 +132,24 @@ def enable_scheduler():
cb8e9e
                 except IOError as (errno, strerror):
cb8e9e
                     log.error("Failed to open %s. Error: %s.",
cb8e9e
                               GCRON_ENABLED, strerror)
cb8e9e
-                    ret = False
cb8e9e
+                    ret = INTERNAL_ERROR
cb8e9e
                     return ret
cb8e9e
                 os.symlink(GCRON_ENABLED, GCRON_TASKS)
cb8e9e
                 update_current_scheduler("cli")
cb8e9e
                 log.info("Snapshot scheduling is enabled")
cb8e9e
                 output("Snapshot scheduling is enabled")
cb8e9e
+                ret = 0
cb8e9e
             except IOError as (errno, strerror):
cb8e9e
                 print_str = "Failed to enable snapshot scheduling. Error: "+strerror
cb8e9e
                 log.error(print_str)
cb8e9e
                 output(print_str)
cb8e9e
-                ret = False
cb8e9e
+                ret = INTERNAL_ERROR
cb8e9e
         else:
cb8e9e
             print_str = "Failed to enable snapshot scheduling. " \
cb8e9e
                         "Error: Snapshot scheduling is already enabled."
cb8e9e
             log.error(print_str)
cb8e9e
             output(print_str)
cb8e9e
-            ret = False
cb8e9e
+            ret = SCHEDULING_ALREADY_ENABLED
cb8e9e
     else:
cb8e9e
         print_str = "Failed to enable snapshot scheduling. " \
cb8e9e
                     "Error: Failed to check scheduler status."
cb8e9e
@@ -146,14 +161,14 @@ def enable_scheduler():
cb8e9e
 
cb8e9e
 def disable_scheduler():
cb8e9e
     ret = scheduler_status()
cb8e9e
-    if ret:
cb8e9e
+    if ret == 0:
cb8e9e
         if scheduler_enabled:
cb8e9e
             log.info("Disabling snapshot scheduler.")
cb8e9e
             try:
cb8e9e
                 # Check if another scheduler is active. If not, then
cb8e9e
                 # update current scheduler to "none". Else do nothing.
cb8e9e
                 ret = get_current_scheduler()
cb8e9e
-                if ret:
cb8e9e
+                if ret == 0:
cb8e9e
                     if (current_scheduler == "cli"):
cb8e9e
                         update_current_scheduler("none")
cb8e9e
                 else:
cb8e9e
@@ -161,7 +176,6 @@ def disable_scheduler():
cb8e9e
                                 "Error: Failed to get current scheduler info."
cb8e9e
                     log.error(print_str)
cb8e9e
                     output(print_str)
cb8e9e
-                    ret = False
cb8e9e
                     return ret
cb8e9e
 
cb8e9e
                 if os.path.exists(GCRON_DISABLED):
cb8e9e
@@ -173,22 +187,24 @@ def disable_scheduler():
cb8e9e
                 os.symlink(GCRON_DISABLED, GCRON_TASKS)
cb8e9e
                 log.info("Snapshot scheduling is disabled")
cb8e9e
                 output("Snapshot scheduling is disabled")
cb8e9e
+                ret = 0
cb8e9e
             except IOError as (errno, strerror):
cb8e9e
                 print_str = "Failed to disable snapshot scheduling. Error: "+strerror
cb8e9e
                 log.error(print_str)
cb8e9e
                 output(print_str)
cb8e9e
-                ret = False
cb8e9e
+                ret = INTERNAL_ERROR
cb8e9e
         else:
cb8e9e
             print_str = "Failed to disable scheduling. " \
cb8e9e
                         "Error: Snapshot scheduling is already disabled."
cb8e9e
             log.error(print_str)
cb8e9e
             output(print_str)
cb8e9e
-            ret = False
cb8e9e
+            ret = SCHEDULING_ALREADY_DISABLED
cb8e9e
     else:
cb8e9e
         print_str = "Failed to disable snapshot scheduling. " \
cb8e9e
                     "Error: Failed to check scheduler status."
cb8e9e
         log.error(print_str)
cb8e9e
         output(print_str)
cb8e9e
+        ret = INTERNAL_ERROR
cb8e9e
 
cb8e9e
     return ret
cb8e9e
 
cb8e9e
@@ -211,10 +227,10 @@ def load_tasks_from_file():
cb8e9e
                                     len(schedule))
cb8e9e
                 tasks[jobname] = schedule+":"+volname
cb8e9e
             f.close()
cb8e9e
-        ret = True
cb8e9e
+        ret = 0
cb8e9e
     except IOError as (errno, strerror):
cb8e9e
         log.error("Failed to open %s. Error: %s.", GCRON_ENABLED, strerror)
cb8e9e
-        ret = False
cb8e9e
+        ret = INTERNAL_ERROR
cb8e9e
 
cb8e9e
     return ret
cb8e9e
 
cb8e9e
@@ -225,10 +241,10 @@ def get_current_scheduler():
cb8e9e
         with open(CURRENT_SCHEDULER, 'r') as f:
cb8e9e
             current_scheduler = f.readline().rstrip('\n')
cb8e9e
             f.close()
cb8e9e
-        ret = True
cb8e9e
+        ret = 0
cb8e9e
     except IOError as (errno, strerror):
cb8e9e
         log.error("Failed to open %s. Error: %s.", CURRENT_SCHEDULER, strerror)
cb8e9e
-        ret = False
cb8e9e
+        ret = INTERNAL_ERROR
cb8e9e
 
cb8e9e
     return ret
cb8e9e
 
cb8e9e
@@ -236,7 +252,7 @@ def get_current_scheduler():
cb8e9e
 def list_schedules():
cb8e9e
     log.info("Listing snapshot schedules.")
cb8e9e
     ret = load_tasks_from_file()
cb8e9e
-    if ret:
cb8e9e
+    if ret == 0:
cb8e9e
         if len(tasks) == 0:
cb8e9e
             output("No snapshots scheduled")
cb8e9e
         else:
cb8e9e
@@ -255,6 +271,7 @@ def list_schedules():
cb8e9e
                           longest_field + 5)
cb8e9e
                 operation = "Snapshot Create".ljust(longest_field+5)
cb8e9e
                 print(jobname+schedule+operation+volname)
cb8e9e
+            ret = 0
cb8e9e
     else:
cb8e9e
         print_str = "Failed to list snapshot schedules. " \
cb8e9e
                     "Error: Failed to load tasks from "+GCRON_ENABLED
cb8e9e
@@ -265,7 +282,6 @@ def list_schedules():
cb8e9e
 
cb8e9e
 
cb8e9e
 def write_tasks_to_file():
cb8e9e
-    ret = False
cb8e9e
     try:
cb8e9e
         with open(TMP_FILE, "w", 0644) as f:
cb8e9e
             # If tasks is empty, just create an empty tmp file
cb8e9e
@@ -282,16 +298,15 @@ def write_tasks_to_file():
cb8e9e
             f.close()
cb8e9e
     except IOError as (errno, strerror):
cb8e9e
         log.error("Failed to open %s. Error: %s.", TMP_FILE, strerror)
cb8e9e
-        ret = False
cb8e9e
+        ret = INTERNAL_ERROR
cb8e9e
         return ret
cb8e9e
 
cb8e9e
     shutil.move(TMP_FILE, GCRON_ENABLED)
cb8e9e
-    ret = True
cb8e9e
+    ret = 0
cb8e9e
 
cb8e9e
     return ret
cb8e9e
 
cb8e9e
 def update_current_scheduler(data):
cb8e9e
-    ret = False
cb8e9e
     try:
cb8e9e
         with open(TMP_FILE, "w", 0644) as f:
cb8e9e
             f.write("%s" % data)
cb8e9e
@@ -300,11 +315,11 @@ def update_current_scheduler(data):
cb8e9e
             f.close()
cb8e9e
     except IOError as (errno, strerror):
cb8e9e
         log.error("Failed to open %s. Error: %s.", TMP_FILE, strerror)
cb8e9e
-        ret = False
cb8e9e
+        ret = INTERNAL_ERROR
cb8e9e
         return ret
cb8e9e
 
cb8e9e
     shutil.move(TMP_FILE, CURRENT_SCHEDULER)
cb8e9e
-    ret = True
cb8e9e
+    ret = 0
cb8e9e
 
cb8e9e
     return ret
cb8e9e
 
cb8e9e
@@ -312,17 +327,17 @@ def update_current_scheduler(data):
cb8e9e
 def add_schedules(jobname, schedule, volname):
cb8e9e
     log.info("Adding snapshot schedules.")
cb8e9e
     ret = load_tasks_from_file()
cb8e9e
-    if ret:
cb8e9e
+    if ret == 0:
cb8e9e
         if jobname in tasks:
cb8e9e
             print_str = ("%s already exists in schedule. Use "
cb8e9e
                          "'edit' to modify %s" % (jobname, jobname))
cb8e9e
             log.error(print_str)
cb8e9e
             output(print_str)
cb8e9e
-            ret = False
cb8e9e
+            ret = JOB_ALREADY_EXISTS
cb8e9e
         else:
cb8e9e
             tasks[jobname] = schedule + ":" + volname
cb8e9e
             ret = write_tasks_to_file()
cb8e9e
-            if ret:
cb8e9e
+            if ret == 0:
cb8e9e
                 # Create a LOCK_FILE for the job
cb8e9e
                 job_lockfile = LOCK_FILE_DIR + jobname
cb8e9e
                 try:
cb8e9e
@@ -331,10 +346,11 @@ def add_schedules(jobname, schedule, volname):
cb8e9e
                 except IOError as (errno, strerror):
cb8e9e
                     log.error("Failed to open %s. Error: %s.",
cb8e9e
                               job_lockfile, strerror)
cb8e9e
-                    ret = False
cb8e9e
+                    ret = INTERNAL_ERROR
cb8e9e
                     return ret
cb8e9e
                 log.info("Successfully added snapshot schedule %s" % jobname)
cb8e9e
                 output("Successfully added snapshot schedule")
cb8e9e
+                ret = 0
cb8e9e
     else:
cb8e9e
         print_str = "Failed to add snapshot schedule. " \
cb8e9e
                     "Error: Failed to load tasks from "+GCRON_ENABLED
cb8e9e
@@ -347,11 +363,11 @@ def add_schedules(jobname, schedule, volname):
cb8e9e
 def delete_schedules(jobname):
cb8e9e
     log.info("Delete snapshot schedules.")
cb8e9e
     ret = load_tasks_from_file()
cb8e9e
-    if ret:
cb8e9e
+    if ret == 0:
cb8e9e
         if jobname in tasks:
cb8e9e
             del tasks[jobname]
cb8e9e
             ret = write_tasks_to_file()
cb8e9e
-            if ret:
cb8e9e
+            if ret == 0:
cb8e9e
                 # Delete the LOCK_FILE for the job
cb8e9e
                 job_lockfile = LOCK_FILE_DIR+jobname
cb8e9e
                 try:
cb8e9e
@@ -359,15 +375,18 @@ def delete_schedules(jobname):
cb8e9e
                 except IOError as (errno, strerror):
cb8e9e
                     log.error("Failed to open %s. Error: %s.",
cb8e9e
                               job_lockfile, strerror)
cb8e9e
+                    ret = INTERNAL_ERROR
cb8e9e
+                    return ret
cb8e9e
                 log.info("Successfully deleted snapshot schedule %s"
cb8e9e
                          % jobname)
cb8e9e
                 output("Successfully deleted snapshot schedule")
cb8e9e
+                ret = 0
cb8e9e
         else:
cb8e9e
             print_str = ("Failed to delete %s. Error: No such "
cb8e9e
                          "job scheduled" % jobname)
cb8e9e
             log.error(print_str)
cb8e9e
             output(print_str)
cb8e9e
-            ret = False
cb8e9e
+            ret = JOB_NOT_FOUND
cb8e9e
     else:
cb8e9e
         print_str = "Failed to delete snapshot schedule. " \
cb8e9e
                     "Error: Failed to load tasks from "+GCRON_ENABLED
cb8e9e
@@ -380,11 +399,11 @@ def delete_schedules(jobname):
cb8e9e
 def edit_schedules(jobname, schedule, volname):
cb8e9e
     log.info("Editing snapshot schedules.")
cb8e9e
     ret = load_tasks_from_file()
cb8e9e
-    if ret:
cb8e9e
+    if ret == 0:
cb8e9e
         if jobname in tasks:
cb8e9e
             tasks[jobname] = schedule+":"+volname
cb8e9e
             ret = write_tasks_to_file()
cb8e9e
-            if ret:
cb8e9e
+            if ret == 0:
cb8e9e
                 log.info("Successfully edited snapshot schedule %s" % jobname)
cb8e9e
                 output("Successfully edited snapshot schedule")
cb8e9e
         else:
cb8e9e
@@ -392,7 +411,7 @@ def edit_schedules(jobname, schedule, volname):
cb8e9e
                          "job scheduled" % jobname)
cb8e9e
             log.error(print_str)
cb8e9e
             output(print_str)
cb8e9e
-            ret = False
cb8e9e
+            ret = JOB_NOT_FOUND
cb8e9e
     else:
cb8e9e
         print_str = "Failed to edit snapshot schedule. " \
cb8e9e
                     "Error: Failed to load tasks from "+GCRON_ENABLED
cb8e9e
@@ -413,7 +432,7 @@ def initialise_scheduler():
cb8e9e
             f.close()
cb8e9e
     except IOError as (errno, strerror):
cb8e9e
         log.error("Failed to open /tmp/crontab. Error: %s.", strerror)
cb8e9e
-        ret = False
cb8e9e
+        ret = INIT_FAILED
cb8e9e
         return ret
cb8e9e
 
cb8e9e
     shutil.move("/tmp/crontab", GCRON_UPDATE_TASK)
cb8e9e
@@ -424,7 +443,7 @@ def initialise_scheduler():
cb8e9e
             f.close()
cb8e9e
         except IOError as (errno, strerror):
cb8e9e
             log.error("Failed to open %s. Error: %s.", GCRON_TASKS, strerror)
cb8e9e
-            ret = False
cb8e9e
+            ret = INIT_FAILED
cb8e9e
             return ret
cb8e9e
 
cb8e9e
     if os.path.lexists(GCRON_CROND_TASK):
cb8e9e
@@ -435,22 +454,22 @@ def initialise_scheduler():
cb8e9e
     log.info("Successfully inited snapshot scheduler for this node")
cb8e9e
     output("Successfully inited snapshot scheduler for this node")
cb8e9e
 
cb8e9e
-    ret = True
cb8e9e
+    ret = 0
cb8e9e
     return ret
cb8e9e
 
cb8e9e
 
cb8e9e
 def syntax_checker(args):
cb8e9e
-    ret = False
cb8e9e
-
cb8e9e
     if hasattr(args, 'jobname'):
cb8e9e
         if (len(args.jobname.split()) != 1):
cb8e9e
             output("Invalid Jobname. Jobname should not be empty and should not contain \" \" character.")
cb8e9e
+            ret = INVALID_JOBNAME
cb8e9e
             return ret
cb8e9e
         args.jobname=args.jobname.strip()
cb8e9e
 
cb8e9e
     if hasattr(args, 'volname'):
cb8e9e
         if (len(args.volname.split()) != 1):
cb8e9e
             output("Invalid Volname. Volname should not be empty and should not contain \" \" character.")
cb8e9e
+            ret = INVALID_VOLNAME
cb8e9e
             return ret
cb8e9e
         args.volname=args.volname.strip()
cb8e9e
 
cb8e9e
@@ -464,26 +483,25 @@ def syntax_checker(args):
cb8e9e
             print ("| | +-------- Day of the Month  (range: 1-31)")
cb8e9e
             print ("| +---------- Hour              (range: 0-23)")
cb8e9e
             print ("+------------ Minute            (range: 0-59)")
cb8e9e
+            ret = INVALID_SCHEDULE
cb8e9e
             return ret
cb8e9e
 
cb8e9e
-    ret = True
cb8e9e
+    ret = 0
cb8e9e
     return ret
cb8e9e
 
cb8e9e
 
cb8e9e
 def perform_operation(args):
cb8e9e
-    ret = False
cb8e9e
-
cb8e9e
     # Initialise snapshot scheduler on local node
cb8e9e
     if args.action == "init":
cb8e9e
         ret = initialise_scheduler()
cb8e9e
-        if not ret:
cb8e9e
+        if ret != 0:
cb8e9e
             output("Failed to initialise snapshot scheduling")
cb8e9e
         return ret
cb8e9e
 
cb8e9e
     # Disable snapshot scheduler
cb8e9e
     if args.action == "disable_force":
cb8e9e
         ret = disable_scheduler()
cb8e9e
-        if ret:
cb8e9e
+        if ret == 0:
cb8e9e
             subprocess.Popen(["touch", "-h", GCRON_TASKS])
cb8e9e
         return ret
cb8e9e
 
cb8e9e
@@ -495,12 +513,13 @@ def perform_operation(args):
cb8e9e
                      "the snap scheduler for the local node.")
cb8e9e
         log.error(print_str)
cb8e9e
         output(print_str)
cb8e9e
+        ret = NODE_NOT_INITIALISED
cb8e9e
         return ret
cb8e9e
 
cb8e9e
     # Check status of snapshot scheduler.
cb8e9e
     if args.action == "status":
cb8e9e
         ret = scheduler_status()
cb8e9e
-        if ret:
cb8e9e
+        if ret == 0:
cb8e9e
             if scheduler_enabled:
cb8e9e
                 output("Snapshot scheduling status: Enabled")
cb8e9e
             else:
cb8e9e
@@ -512,14 +531,14 @@ def perform_operation(args):
cb8e9e
     # Enable snapshot scheduler
cb8e9e
     if args.action == "enable":
cb8e9e
         ret = enable_scheduler()
cb8e9e
-        if ret:
cb8e9e
+        if ret == 0:
cb8e9e
             subprocess.Popen(["touch", "-h", GCRON_TASKS])
cb8e9e
         return ret
cb8e9e
 
cb8e9e
     # Disable snapshot scheduler
cb8e9e
     if args.action == "disable":
cb8e9e
         ret = disable_scheduler()
cb8e9e
-        if ret:
cb8e9e
+        if ret == 0:
cb8e9e
             subprocess.Popen(["touch", "-h", GCRON_TASKS])
cb8e9e
         return ret
cb8e9e
 
cb8e9e
@@ -531,33 +550,34 @@ def perform_operation(args):
cb8e9e
     # Add snapshot schedules
cb8e9e
     if args.action == "add":
cb8e9e
         ret = syntax_checker(args)
cb8e9e
-        if not ret:
cb8e9e
+        if ret != 0:
cb8e9e
             return ret
cb8e9e
         ret = add_schedules(args.jobname, args.schedule, args.volname)
cb8e9e
-        if ret:
cb8e9e
+        if ret == 0:
cb8e9e
             subprocess.Popen(["touch", "-h", GCRON_TASKS])
cb8e9e
         return ret
cb8e9e
 
cb8e9e
     # Delete snapshot schedules
cb8e9e
     if args.action == "delete":
cb8e9e
         ret = syntax_checker(args)
cb8e9e
-        if not ret:
cb8e9e
+        if ret != 0:
cb8e9e
             return ret
cb8e9e
         ret = delete_schedules(args.jobname)
cb8e9e
-        if ret:
cb8e9e
+        if ret == 0:
cb8e9e
             subprocess.Popen(["touch", "-h", GCRON_TASKS])
cb8e9e
         return ret
cb8e9e
 
cb8e9e
     # Edit snapshot schedules
cb8e9e
     if args.action == "edit":
cb8e9e
         ret = syntax_checker(args)
cb8e9e
-        if not ret:
cb8e9e
+        if ret != 0:
cb8e9e
             return ret
cb8e9e
         ret = edit_schedules(args.jobname, args.schedule, args.volname)
cb8e9e
-        if ret:
cb8e9e
+        if ret == 0:
cb8e9e
             subprocess.Popen(["touch", "-h", GCRON_TASKS])
cb8e9e
         return ret
cb8e9e
 
cb8e9e
+    ret = INVALID_ARG
cb8e9e
     return ret
cb8e9e
 
cb8e9e
 
cb8e9e
@@ -601,11 +621,11 @@ def main():
cb8e9e
 
cb8e9e
     if not os.path.exists(SHARED_STORAGE_DIR):
cb8e9e
         output("Failed: "+SHARED_STORAGE_DIR+" does not exist.")
cb8e9e
-        return ret
cb8e9e
+        return SHARED_STORAGE_DIR_DOESNT_EXIST
cb8e9e
 
cb8e9e
     if not os.path.ismount(SHARED_STORAGE_DIR):
cb8e9e
         output("Failed: Shared storage is not mounted at "+SHARED_STORAGE_DIR)
cb8e9e
-        return ret
cb8e9e
+        return SHARED_STORAGE_NOT_MOUNTED
cb8e9e
 
cb8e9e
     if not os.path.exists(SHARED_STORAGE_DIR+"/snaps/"):
cb8e9e
         try:
cb8e9e
@@ -615,6 +635,7 @@ def main():
cb8e9e
                 log.error("Failed to create %s : %s", SHARED_STORAGE_DIR+"/snaps/", strerror)
cb8e9e
                 output("Failed to create %s. Error: %s"
cb8e9e
                        % (SHARED_STORAGE_DIR+"/snaps/", strerror))
cb8e9e
+                return INTERNAL_ERROR
cb8e9e
 
cb8e9e
     if not os.path.exists(GCRON_ENABLED):
cb8e9e
         f = os.open(GCRON_ENABLED, os.O_CREAT | os.O_NONBLOCK, 0644)
cb8e9e
@@ -628,6 +649,7 @@ def main():
cb8e9e
                 log.error("Failed to create %s : %s", LOCK_FILE_DIR, strerror)
cb8e9e
                 output("Failed to create %s. Error: %s"
cb8e9e
                        % (LOCK_FILE_DIR, strerror))
cb8e9e
+                return INTERNAL_ERROR
cb8e9e
 
cb8e9e
     if not os.path.exists(CURRENT_SCHEDULER):
cb8e9e
         update_current_scheduler("none")
cb8e9e
@@ -637,19 +659,17 @@ def main():
cb8e9e
         try:
cb8e9e
             fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
cb8e9e
             ret = perform_operation(args)
cb8e9e
-            if not ret:
cb8e9e
-                ret = 1
cb8e9e
-            else:
cb8e9e
-                ret = 0
cb8e9e
             fcntl.flock(f, fcntl.LOCK_UN)
cb8e9e
         except IOError as (errno, strerror):
cb8e9e
             log.info("%s is being processed by another agent.", LOCK_FILE)
cb8e9e
             output("Another snap_scheduler command is running. "
cb8e9e
                    "Please try again after some time.")
cb8e9e
+            return ANOTHER_TRANSACTION_IN_PROGRESS
cb8e9e
         os.close(f)
cb8e9e
     except IOError as (errno, strerror):
cb8e9e
         log.error("Failed to open %s : %s", LOCK_FILE, strerror)
cb8e9e
         output("Failed to open %s. Error: %s" % (LOCK_FILE, strerror))
cb8e9e
+        return INTERNAL_ERROR
cb8e9e
 
cb8e9e
     return ret
cb8e9e
 
cb8e9e
-- 
cb8e9e
1.9.3
cb8e9e