From 99aedb316e3c9491e4d752d1bbc49b6496a7e627 Mon Sep 17 00:00:00 2001 From: Vijay Avuthu Date: Mon, 18 Dec 2017 15:57:44 +0530 Subject: Adding AFR self heal daemon test cases Gave meaningful names to functions Returning -1 if there is no process running Replace numbers with words Rewording the msg "More than 1 or 0 self heal daemon" Review Comments incorporated Change-Id: If424a6f78536279c178ee45d62099fd8f63421dd Signed-off-by: Vijay Avuthu --- .../glustolibs/gluster/gluster_init.py | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'glustolibs-gluster/glustolibs/gluster/gluster_init.py') diff --git a/glustolibs-gluster/glustolibs/gluster/gluster_init.py b/glustolibs-gluster/glustolibs/gluster/gluster_init.py index d45a186d0..5d08acd0e 100644 --- a/glustolibs-gluster/glustolibs/gluster/gluster_init.py +++ b/glustolibs-gluster/glustolibs/gluster/gluster_init.py @@ -167,3 +167,58 @@ def env_setup_servers(servers): return False return True + + +def get_glusterd_pids(nodes): + """ + Checks if glusterd process is running and + return the process id's in dictionary format + + Args: + nodes ( str|list ) : Node/Nodes of the cluster + + Returns: + tuple : Tuple containing two elements (ret, gluster_pids). + The first element 'ret' is of type 'bool', True if only if + glusterd is running on all the nodes in the list and each + node contains only one instance of glusterd running. + False otherwise. + + The second element 'glusterd_pids' is of type dictonary and + it contains the process ID's for glusterd. + + """ + glusterd_pids = {} + _rc = True + if isinstance(nodes, str): + nodes = [nodes] + + cmd = "pidof glusterd" + g.log.info("Executing cmd: %s on node %s" % (cmd, nodes)) + results = g.run_parallel(nodes, cmd) + for node in results: + ret, out, err = results[node] + if ret == 0: + if len(out.strip().split("\n")) == 1: + if not out.strip(): + g.log.error("NO glusterd process found " + "on node %s" % node) + _rc = False + glusterd_pids[node] = ['-1'] + else: + g.log.info("glusterd process with " + "pid %s found on %s", + out.strip().split("\n"), node) + glusterd_pids[node] = (out.strip().split("\n")) + else: + g.log.error("More than One glusterd process " + "found on node %s" % node) + _rc = False + glusterd_pids[node] = out + else: + g.log.error("Not able to get glusterd process " + "from node %s" % node) + _rc = False + glusterd_pids[node] = ['-1'] + + return _rc, glusterd_pids -- cgit