|
|
cb8e9e |
From 64cfd2d7b3be3e79420c455273aa27b847e6fd83 Mon Sep 17 00:00:00 2001
|
|
|
cb8e9e |
From: Avra Sengupta <asengupt@redhat.com>
|
|
|
cb8e9e |
Date: Wed, 5 Aug 2015 13:49:41 +0530
|
|
|
cb8e9e |
Subject: [PATCH 291/304] snapshot/scheduler: Check if volume exists before adding/editing schedules
|
|
|
cb8e9e |
|
|
|
cb8e9e |
Before adding or editing a scheduler, check if the volume name provided
|
|
|
cb8e9e |
in the schedule, exists in the cluster or not.
|
|
|
cb8e9e |
|
|
|
cb8e9e |
Added return code VOLUME_DOES_NOT_EXIST(17) for the same.
|
|
|
cb8e9e |
|
|
|
cb8e9e |
Change-Id: Ia3fe3cc1e1568ddd10f9193bbf40a098f0fe990a
|
|
|
cb8e9e |
BUG: 1245924
|
|
|
cb8e9e |
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
|
|
|
cb8e9e |
Reviewed-on: http://review.gluster.org/11830
|
|
|
cb8e9e |
Tested-by: NetBSD Build System <jenkins@build.gluster.org>
|
|
|
cb8e9e |
Reviewed-by: mohammed rafi kc <rkavunga@redhat.com>
|
|
|
cb8e9e |
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
|
|
|
cb8e9e |
Reviewed-on: https://code.engineering.redhat.com/gerrit/56047
|
|
|
cb8e9e |
Tested-by: Rajesh Joseph <rjoseph@redhat.com>
|
|
|
cb8e9e |
---
|
|
|
cb8e9e |
extras/snap_scheduler/snap_scheduler.py | 88 +++++++++++++++++++++++-------
|
|
|
cb8e9e |
1 files changed, 67 insertions(+), 21 deletions(-)
|
|
|
cb8e9e |
|
|
|
cb8e9e |
diff --git a/extras/snap_scheduler/snap_scheduler.py b/extras/snap_scheduler/snap_scheduler.py
|
|
|
cb8e9e |
index f9cfc9e..af092e2 100755
|
|
|
cb8e9e |
--- a/extras/snap_scheduler/snap_scheduler.py
|
|
|
cb8e9e |
+++ b/extras/snap_scheduler/snap_scheduler.py
|
|
|
cb8e9e |
@@ -53,6 +53,7 @@ INVALID_JOBNAME = 13
|
|
|
cb8e9e |
INVALID_VOLNAME = 14
|
|
|
cb8e9e |
INVALID_SCHEDULE = 15
|
|
|
cb8e9e |
INVALID_ARG = 16
|
|
|
cb8e9e |
+VOLUME_DOES_NOT_EXIST = 17
|
|
|
cb8e9e |
|
|
|
cb8e9e |
def output(msg):
|
|
|
cb8e9e |
print("%s: %s" % (SCRIPT_NAME, msg))
|
|
|
cb8e9e |
@@ -324,6 +325,34 @@ def update_current_scheduler(data):
|
|
|
cb8e9e |
return ret
|
|
|
cb8e9e |
|
|
|
cb8e9e |
|
|
|
cb8e9e |
+def isVolumePresent(volname):
|
|
|
cb8e9e |
+ success = False
|
|
|
cb8e9e |
+ if volname == "":
|
|
|
cb8e9e |
+ log.debug("No volname given")
|
|
|
cb8e9e |
+ return success
|
|
|
cb8e9e |
+
|
|
|
cb8e9e |
+ cli = ["gluster",
|
|
|
cb8e9e |
+ "volume",
|
|
|
cb8e9e |
+ "info",
|
|
|
cb8e9e |
+ volname]
|
|
|
cb8e9e |
+ log.debug("Running command '%s'", " ".join(cli))
|
|
|
cb8e9e |
+
|
|
|
cb8e9e |
+ p = subprocess.Popen(cli, stdout=subprocess.PIPE,
|
|
|
cb8e9e |
+ stderr=subprocess.PIPE)
|
|
|
cb8e9e |
+ out, err = p.communicate()
|
|
|
cb8e9e |
+ rv = p.returncode
|
|
|
cb8e9e |
+
|
|
|
cb8e9e |
+ log.debug("Command '%s' returned '%d'", " ".join(cli), rv)
|
|
|
cb8e9e |
+
|
|
|
cb8e9e |
+ if rv:
|
|
|
cb8e9e |
+ log.error("Command output:")
|
|
|
cb8e9e |
+ log.error(err)
|
|
|
cb8e9e |
+ else:
|
|
|
cb8e9e |
+ success = True;
|
|
|
cb8e9e |
+
|
|
|
cb8e9e |
+ return success
|
|
|
cb8e9e |
+
|
|
|
cb8e9e |
+
|
|
|
cb8e9e |
def add_schedules(jobname, schedule, volname):
|
|
|
cb8e9e |
log.info("Adding snapshot schedules.")
|
|
|
cb8e9e |
ret = load_tasks_from_file()
|
|
|
cb8e9e |
@@ -335,22 +364,31 @@ def add_schedules(jobname, schedule, volname):
|
|
|
cb8e9e |
output(print_str)
|
|
|
cb8e9e |
ret = JOB_ALREADY_EXISTS
|
|
|
cb8e9e |
else:
|
|
|
cb8e9e |
- tasks[jobname] = schedule + ":" + volname
|
|
|
cb8e9e |
- ret = write_tasks_to_file()
|
|
|
cb8e9e |
- if ret == 0:
|
|
|
cb8e9e |
- # Create a LOCK_FILE for the job
|
|
|
cb8e9e |
- job_lockfile = LOCK_FILE_DIR + jobname
|
|
|
cb8e9e |
- try:
|
|
|
cb8e9e |
- f = os.open(job_lockfile, os.O_CREAT | os.O_NONBLOCK, 0644)
|
|
|
cb8e9e |
- os.close(f)
|
|
|
cb8e9e |
- except OSError 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 added snapshot schedule %s" % jobname)
|
|
|
cb8e9e |
- output("Successfully added snapshot schedule")
|
|
|
cb8e9e |
- ret = 0
|
|
|
cb8e9e |
+ if not isVolumePresent(volname):
|
|
|
cb8e9e |
+ print_str = ("Volume %s does not exist. Create %s and retry." %
|
|
|
cb8e9e |
+ (volname, volname))
|
|
|
cb8e9e |
+ log.error(print_str)
|
|
|
cb8e9e |
+ output(print_str)
|
|
|
cb8e9e |
+ ret = VOLUME_DOES_NOT_EXIST
|
|
|
cb8e9e |
+ else:
|
|
|
cb8e9e |
+ tasks[jobname] = schedule + ":" + volname
|
|
|
cb8e9e |
+ ret = write_tasks_to_file()
|
|
|
cb8e9e |
+ if ret == 0:
|
|
|
cb8e9e |
+ # Create a LOCK_FILE for the job
|
|
|
cb8e9e |
+ job_lockfile = LOCK_FILE_DIR + jobname
|
|
|
cb8e9e |
+ try:
|
|
|
cb8e9e |
+ f = os.open(job_lockfile, os.O_CREAT | os.O_NONBLOCK,
|
|
|
cb8e9e |
+ 0644)
|
|
|
cb8e9e |
+ os.close(f)
|
|
|
cb8e9e |
+ except OSError 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 added snapshot schedule %s" %
|
|
|
cb8e9e |
+ 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 |
@@ -401,11 +439,19 @@ def edit_schedules(jobname, schedule, volname):
|
|
|
cb8e9e |
ret = load_tasks_from_file()
|
|
|
cb8e9e |
if ret == 0:
|
|
|
cb8e9e |
if jobname in tasks:
|
|
|
cb8e9e |
- tasks[jobname] = schedule+":"+volname
|
|
|
cb8e9e |
- ret = write_tasks_to_file()
|
|
|
cb8e9e |
- if ret == 0:
|
|
|
cb8e9e |
- log.info("Successfully edited snapshot schedule %s" % jobname)
|
|
|
cb8e9e |
- output("Successfully edited snapshot schedule")
|
|
|
cb8e9e |
+ if not isVolumePresent(volname):
|
|
|
cb8e9e |
+ print_str = ("Volume %s does not exist. Create %s and retry." %
|
|
|
cb8e9e |
+ (volname, volname))
|
|
|
cb8e9e |
+ log.error(print_str)
|
|
|
cb8e9e |
+ output(print_str)
|
|
|
cb8e9e |
+ ret = VOLUME_DOES_NOT_EXIST
|
|
|
cb8e9e |
+ else:
|
|
|
cb8e9e |
+ tasks[jobname] = schedule+":"+volname
|
|
|
cb8e9e |
+ ret = write_tasks_to_file()
|
|
|
cb8e9e |
+ if ret == 0:
|
|
|
cb8e9e |
+ log.info("Successfully edited snapshot schedule %s" %
|
|
|
cb8e9e |
+ jobname)
|
|
|
cb8e9e |
+ output("Successfully edited snapshot schedule")
|
|
|
cb8e9e |
else:
|
|
|
cb8e9e |
print_str = ("Failed to edit %s. Error: No such "
|
|
|
cb8e9e |
"job scheduled" % jobname)
|
|
|
cb8e9e |
--
|
|
|
cb8e9e |
1.7.1
|
|
|
cb8e9e |
|