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