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