diff options
Diffstat (limited to 'glustolibs-gluster/glustolibs/gluster/brickmux_ops.py')
-rwxr-xr-x | glustolibs-gluster/glustolibs/gluster/brickmux_ops.py | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/brickmux_ops.py b/glustolibs-gluster/glustolibs/gluster/brickmux_ops.py index 2fff05806..b56434741 100755 --- a/glustolibs-gluster/glustolibs/gluster/brickmux_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/brickmux_ops.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (C) 2017-2018 Red Hat, Inc. <http://www.redhat.com> +# Copyright (C) 2017-2020 Red Hat, Inc. <http://www.redhat.com> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -56,7 +56,7 @@ def is_brick_mux_enabled(mnode): elif get_brick_mux_status(mnode) in negative_states: return False else: - raise ValueError('Brick mux status % is incorrect', + raise ValueError('Brick mux status %s is incorrect', get_brick_mux_status(mnode)) @@ -119,21 +119,40 @@ def check_brick_pid_matches_glusterfsd_pid(mnode, volname): "of brick path %s", brick_node, brick_path) _rc = False - cmd = ("ps -eaf | grep glusterfsd | " - "grep %s.%s | grep -v 'grep %s.%s'" - % (volname, brick_node, - volname, brick_node)) + cmd = "pgrep -x glusterfsd" ret, pid, _ = g.run(brick_node, cmd) if ret != 0: g.log.error("Failed to run the command %s on " "node %s", cmd, brick_node) _rc = False - glusterfsd_pid = pid.split()[1] - if glusterfsd_pid != brick_pid: + else: + glusterfsd_pid = pid.split('\n')[:-1] + + if brick_pid not in glusterfsd_pid: g.log.error("Brick pid %s doesn't match glusterfsd " "pid %s of the node %s", brick_pid, glusterfsd_pid, brick_node) _rc = False return _rc + + +def get_brick_processes_count(mnode): + """ + Get the brick process count for a given node. + + Args: + mnode (str): Node on which brick process has to be counted. + + Returns: + int: Number of brick processes running on the node. + None: If the command fails to execute. + """ + ret, out, _ = g.run(mnode, "pgrep -x glusterfsd") + if not ret: + list_of_pids = out.split("\n") + list_of_pids.pop() + return len(list_of_pids) + else: + return None |