7f4c2a
From 8679f961d15865230b648f5a2bce832c994f8a29 Mon Sep 17 00:00:00 2001
7f4c2a
From: Kotresh HR <khiremat@redhat.com>
7f4c2a
Date: Wed, 17 Jun 2015 17:05:22 +0530
7f4c2a
Subject: [PATCH 134/190] tools/glusterfind: Fail glusterfind creation if volume is offline
7f4c2a
7f4c2a
Following two fixes are done.
7f4c2a
7f4c2a
1. Fail glusterfind session creation if volume is not online
7f4c2a
   even before session directories are created. This avoids
7f4c2a
   'glusterfind list' to pick the session directories and show
7f4c2a
   status as 'Session Corrupted'.
7f4c2a
7f4c2a
2. Check of '!Started' instead of wether the volume is 'Stopped'.
7f4c2a
   It covers all the cases.
7f4c2a
7f4c2a
BUG: 1228598
7f4c2a
Change-Id: Ic4efcda6b620e7044d97a51c59d83103d88e55c8
7f4c2a
Reviewed-on: http://review.gluster.org/11278
7f4c2a
Reviewed-on: http://review.gluster.org/11322
7f4c2a
Reviewed-by: Aravinda VK <avishwan@redhat.com>
7f4c2a
Signed-off-by: Kotresh HR <khiremat@redhat.com>
7f4c2a
Reviewed-on: https://code.engineering.redhat.com/gerrit/51457
7f4c2a
Reviewed-by: Saravanakumar Arumugam <sarumuga@redhat.com>
7f4c2a
Reviewed-by: Venky Shankar <vshankar@redhat.com>
7f4c2a
Tested-by: Venky Shankar <vshankar@redhat.com>
7f4c2a
---
7f4c2a
 tools/glusterfind/src/main.py |   25 +++++++++++++++++--------
7f4c2a
 1 files changed, 17 insertions(+), 8 deletions(-)
7f4c2a
7f4c2a
diff --git a/tools/glusterfind/src/main.py b/tools/glusterfind/src/main.py
7f4c2a
index 29fa28b..8d32295 100644
7f4c2a
--- a/tools/glusterfind/src/main.py
7f4c2a
+++ b/tools/glusterfind/src/main.py
7f4c2a
@@ -31,7 +31,7 @@ ParseError = etree.ParseError if hasattr(etree, 'ParseError') else SyntaxError
7f4c2a
 
7f4c2a
 logger = logging.getLogger()
7f4c2a
 node_outfiles = []
7f4c2a
-vol_statusStr = "Stopped"
7f4c2a
+vol_statusStr = ""
7f4c2a
 
7f4c2a
 
7f4c2a
 class StoreAbsPath(Action):
7f4c2a
@@ -88,8 +88,8 @@ def run_cmd_nodes(task, args, **kwargs):
7f4c2a
                                     "tmp_output_%s" % num)
7f4c2a
 
7f4c2a
         if task == "pre":
7f4c2a
-            if vol_statusStr == "Stopped":
7f4c2a
-                fail("Volume %s is in stopped state" % args.volume,
7f4c2a
+            if vol_statusStr != "Started":
7f4c2a
+                fail("Volume %s is not online" % args.volume,
7f4c2a
                      logger=logger)
7f4c2a
 
7f4c2a
             # If Full backup is requested or start time is zero, use brickfind
7f4c2a
@@ -128,8 +128,8 @@ def run_cmd_nodes(task, args, **kwargs):
7f4c2a
                    args.session,
7f4c2a
                    args.volume] + (["--debug"] if args.debug else [])
7f4c2a
         elif task == "create":
7f4c2a
-            if vol_statusStr == "Stopped":
7f4c2a
-                fail("Volume %s is in stopped state" % args.volume,
7f4c2a
+            if vol_statusStr != "Started":
7f4c2a
+                fail("Volume %s is not online" % args.volume,
7f4c2a
                      logger=logger)
7f4c2a
 
7f4c2a
             # When glusterfind create, create session directory in
7f4c2a
@@ -324,9 +324,18 @@ def mode_create(session_dir, args):
7f4c2a
     logger.debug("Init is called - Session: %s, Volume: %s"
7f4c2a
                  % (args.session, args.volume))
7f4c2a
 
7f4c2a
-    execute(["gluster", "volume", "info", args.volume],
7f4c2a
-            exit_msg="Unable to get volume details",
7f4c2a
-            logger=logger)
7f4c2a
+    cmd = ["gluster", 'volume', 'info', args.volume, "--xml"]
7f4c2a
+    _, data, _ = execute(cmd,
7f4c2a
+                         exit_msg="Failed to Run Gluster Volume Info",
7f4c2a
+                         logger=logger)
7f4c2a
+    try:
7f4c2a
+        tree = etree.fromstring(data)
7f4c2a
+        statusStr = tree.find('volInfo/volumes/volume/statusStr').text
7f4c2a
+    except (ParseError, AttributeError) as e:
7f4c2a
+        fail("Invalid Volume: %s" % e, logger=logger)
7f4c2a
+
7f4c2a
+    if statusStr != "Started":
7f4c2a
+        fail("Volume %s is not online" % args.volume, logger=logger)
7f4c2a
 
7f4c2a
     mkdirp(session_dir, exit_on_err=True, logger=logger)
7f4c2a
     mkdirp(os.path.join(session_dir, args.volume), exit_on_err=True,
7f4c2a
-- 
7f4c2a
1.7.1
7f4c2a