gfs2_lockcapture: Fix condition where dlm lockspaces parsing failed
PATCH 1/1 gfs2_lockcapture: Fix condition where dlm lockspaces parsing failed
From: Shane Bradley <[email protected]>
The output of dlm_tool ls was not parsed correctly on dlm_tool version 3.0 or higher. The patch now parses correctly dlm_tool ls output from version 2.0 or higher.
Signed-off-by Shane Bradley <[email protected]>
--- gfs2/scripts/gfs2_lockcapture | 35 ++++++++++++++++++++++------------- 1 files changed, 22 insertions(+), 13 deletions(-)
gfs2/scripts/gfs2_lockcapture +22 -13
@@ -5,7 +5,7 @@ systems and DLM. @author : Shane Bradley @contact : sbradley at redhat.com - at version : 0.9 + at version : 0.95 @copyright : GPLv2 """ import sys
@@ -658,24 +658,25 @@ def getClusterNode(listOfGFS2Names): else: return None - -def getDLMToolDLMLockspaces(): +def parse_dlm_ls(dlm_ls): """ This function returns the names of all the dlm lockspace names found with the - command: "dlm_tool ls". + commands "dlm_tool ls" or "group_tool ls" output. @return: A list of all the dlm lockspace names. @rtype: Array """ dlmLockspaces = [] - stdout = runCommandOutput("dlm_tool", ["ls"]) - if (not stdout == None): - stdout = stdout.replace("dlm lockspaces\n", "") + if (not dlm_ls == None): + dlm_ls = dlm_ls.replace("dlm lockspaces\n", "") dlmToolLSKeys = ["name", "id", "flags", "change", "members"] # Split on newlines - stdoutSections = stdout.split("\n\n") - for section in stdoutSections: + dlm_lsSections = dlm_ls.split("\n\n") + for section in dlm_lsSections: # Create tmp map to hold data + if (section.startswith("fence domain")): + # Not concerned with fence information. + continue dlmToolLSMap = dict.fromkeys(dlmToolLSKeys) lines = section.split("\n") for line in lines:
@@ -699,9 +700,15 @@ def getGroupToolDLMLockspaces(): stdout = runCommandOutput("group_tool", ["ls"]) if (not stdout == None): lines = stdout.split("\n") - for line in lines: - if (line.startswith("dlm")): - dlmLockspaces.append(line.split()[2]) + if (len(lines) > 0): + if (lines[0].startswith("type")): + # Then running cman-2.0 + for line in lines: + if (line.startswith("dlm")): + dlmLockspaces.append(line.split()[2]) + else: + # Then running cman-3.0 and uses same sorta output as `dlm_tool ls`. + dlmLockspaces = parse_dlm_ls(stdout) return dlmLockspaces def getDLMLockspaces():
@@ -713,8 +720,10 @@ def getDLMLockspaces(): """ message = "Gathering the DLM Lockspace Names." logging.getLogger(MAIN_LOGGER_NAME).debug(message) - dlmLockspaces = getDLMToolDLMLockspaces() + dlmLockspaces = parse_dlm_ls(runCommandOutput("dlm_tool", ["ls"])) if (not len(dlmLockspaces) > 0): + message = "There was no dlm lockspaces found with the \"dlm_tool ls\" command. Trying with the \"group_tool ls\" command." + logging.getLogger(MAIN_LOGGER_NAME).debug(message) dlmLockspaces = getGroupToolDLMLockspaces() return dlmLockspaces
Signature · 1 line
1.7.1
PATCH 1/1 gfs2_lockcapture: Fix condition where dlm lockspaces parsing failed
Quoted 16 lines · sbradley at redhat.com
From: Shane Bradley <[email protected]>
The output of
dlm_tool lswas not parsed correctly ondlm_toolversion 3.0 or higher. The patch now parses correctlydlm_tool lsoutput from version 2.0 or higher.Signed-off-by Shane Bradley <[email protected]>--- gfs2/scripts/gfs2_lockcapture | 35 ++++++++++++++++++++++------------- 1 files changed, 22 insertions(+), 13 deletions(-)gfs2/scripts/gfs2_lockcapture +0
-0
gfs2/scripts/gfs2_lockcapture systems and DLM. · line 8
Quoted 5 lines
gfs2/scripts/gfs2_lockcapture +1
-1@@ -5,7 +5,7 @@ systems and DLM. @author : Shane Bradley @contact : sbradley at redhat.com - at version : 0.9 + at version : 0.95
Not 0.10?
Quoted 59 lines
gfs2/scripts/gfs2_lockcapture +18
-11@copyright : GPLv2 """ import sys@@ -658,24 +658,25 @@ def getClusterNode(listOfGFS2Names): else: return None - -def getDLMToolDLMLockspaces(): +def parse_dlm_ls(dlm_ls): """ This function returns the names of all the dlm lockspace names found with the - command: "dlm_tool ls". + commands "dlm_tool ls" or "group_tool ls" output. @return: A list of all the dlm lockspace names. @rtype: Array """ dlmLockspaces = [] - stdout = runCommandOutput("dlm_tool", ["ls"]) - if (not stdout == None): - stdout = stdout.replace("dlm lockspaces\n", "") + if (not dlm_ls == None): + dlm_ls = dlm_ls.replace("dlm lockspaces\n", "") dlmToolLSKeys = ["name", "id", "flags", "change", "members"] # Split on newlines - stdoutSections = stdout.split("\n\n") - for section in stdoutSections: + dlm_lsSections = dlm_ls.split("\n\n") + for section in dlm_lsSections: # Create tmp map to hold data + if (section.startswith("fence domain")): + # Not concerned with fence information. + continue dlmToolLSMap = dict.fromkeys(dlmToolLSKeys) lines = section.split("\n") for line in lines:@@ -699,9 +700,15 @@ def getGroupToolDLMLockspaces(): stdout = runCommandOutput("group_tool", ["ls"]) if (not stdout == None): lines = stdout.split("\n") - for line in lines: - if (line.startswith("dlm")): - dlmLockspaces.append(line.split()[2]) + if (len(lines) > 0): + if (lines[0].startswith("type")): + # Then running cman-2.0 + for line in lines: + if (line.startswith("dlm")): + dlmLockspaces.append(line.split()[2]) + else: + # Then running cman-3.0 and uses same sorta output as `dlm_tool ls`. + dlmLockspaces = parse_dlm_ls(stdout) return dlmLockspaces def getDLMLockspaces():@@ -713,8 +720,10 @@ def getDLMLockspaces(): """
gfs2/scripts/gfs2_lockcapture def getDLMLockspaces(): · line 729
Quoted 10 lines
gfs2/scripts/gfs2_lockcapture +3
-1message = "Gathering the DLM Lockspace Names." logging.getLogger(MAIN_LOGGER_NAME).debug(message) - dlmLockspaces = getDLMToolDLMLockspaces() + dlmLockspaces = parse_dlm_ls(runCommandOutput("dlm_tool", ["ls"])) if (not len(dlmLockspaces) > 0): + message = "There was no dlm lockspaces found with the \"dlm_tool ls\" command. Trying with the \"group_tool ls\" command." + logging.getLogger(MAIN_LOGGER_NAME).debug(message) dlmLockspaces = getGroupToolDLMLockspaces() return dlmLockspaces
Coding style aside, the patch looks fine to me.
Cheers,
Andy