summaryrefslogtreecommitdiffstats
path: root/glustolibs-gluster/glustolibs/gluster
diff options
context:
space:
mode:
authorSri Vignesh <sselvan@redhat.com>2020-01-06 14:11:48 +0530
committerBala Konda Reddy M <bmekala@redhat.com>2020-01-21 09:43:29 +0000
commit674277c7c6e66f00bf15b50d223b7b2ec0b8675c (patch)
tree467175be2af08bbb18c3bdafabd02b7bfdee3f69 /glustolibs-gluster/glustolibs/gluster
parent1a6c15c9d2721b94ebfa05e399dd3b7719d4843d (diff)
[libfix][testfix] Add waiter function for glusterd and peer connected library files
Moving waiters from testcase and adding it as function in library in gluster_init and peer_ops. Change-Id: I5ab1e42a5a0366fadb399789da1c156d8d96ec18 Signed-off-by: Sri Vignesh <sselvan@redhat.com>
Diffstat (limited to 'glustolibs-gluster/glustolibs/gluster')
-rw-r--r--glustolibs-gluster/glustolibs/gluster/gluster_init.py29
-rw-r--r--glustolibs-gluster/glustolibs/gluster/peer_ops.py37
2 files changed, 62 insertions, 4 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/gluster_init.py b/glustolibs-gluster/glustolibs/gluster/gluster_init.py
index 7467479..0470467 100644
--- a/glustolibs-gluster/glustolibs/gluster/gluster_init.py
+++ b/glustolibs-gluster/glustolibs/gluster/gluster_init.py
@@ -19,6 +19,7 @@
Description: This file contains the methods for starting/stopping glusterd
and other initial gluster environment setup helpers.
"""
+from time import sleep
from glusto.core import Glusto as g
@@ -222,3 +223,31 @@ def get_glusterd_pids(nodes):
glusterd_pids[node] = ['-1']
return _rc, glusterd_pids
+
+
+def wait_for_glusterd_to_start(servers, glusterd_start_wait_timeout=80):
+ """Checks glusterd is running on nodes with timeout.
+
+ Args:
+ servers (str|list): A server|List of server hosts on which glusterd
+ status has to be checked.
+ glusterd_start_wait_timeout: timeout to retry glusterd running
+ check in node.
+
+ Returns:
+ bool : True if glusterd is running on servers.
+ False otherwise.
+
+ """
+ if not isinstance(servers, list):
+ servers = [servers]
+ count = 0
+ while count <= glusterd_start_wait_timeout:
+ ret = is_glusterd_running(servers)
+ if not ret:
+ g.log.info("glusterd is running on %s", servers)
+ return True
+ sleep(1)
+ count += 1
+ g.log.error("glusterd is not running on %s", servers)
+ return False
diff --git a/glustolibs-gluster/glustolibs/gluster/peer_ops.py b/glustolibs-gluster/glustolibs/gluster/peer_ops.py
index 988a13c..7027ce1 100644
--- a/glustolibs-gluster/glustolibs/gluster/peer_ops.py
+++ b/glustolibs-gluster/glustolibs/gluster/peer_ops.py
@@ -20,10 +20,10 @@
"""
-from glusto.core import Glusto as g
import re
-import time
import socket
+from time import sleep
+from glusto.core import Glusto as g
try:
import xml.etree.cElementTree as etree
except ImportError:
@@ -166,7 +166,7 @@ def peer_probe_servers(mnode, servers, validate=True, time_delay=10):
# Validating whether peer is in connected state after peer probe
if validate:
- time.sleep(time_delay)
+ sleep(time_delay)
if not is_peer_connected(mnode, servers):
g.log.error("Validation after peer probe failed.")
return False
@@ -212,7 +212,7 @@ def peer_detach_servers(mnode, servers, force=False, validate=True,
# Validating whether peer detach is successful
if validate:
- time.sleep(time_delay)
+ sleep(time_delay)
nodes_in_pool = nodes_from_pool_list(mnode)
rc = True
for server in servers:
@@ -421,3 +421,32 @@ def is_peer_connected(mnode, servers):
g.log.info("Servers: '%s' are all 'Peer in Cluster' and 'Connected' "
"state.", servers)
return True
+
+
+def wait_for_peers_to_connect(mnode, servers, wait_timeout=30):
+ """Checks nodes are peer connected with timeout.
+
+ Args:
+ mnode: node on which cmd has to be executed.
+ servers (str|list): A server|List of server hosts on which peer
+ status has to be checked.
+ wait_timeout: timeout to retry connected status check in node.
+
+ Returns:
+ bool : True if all the peers are connected.
+ False otherwise.
+
+ """
+ if not isinstance(servers, str):
+ servers = [servers]
+
+ count = 0
+ while count <= wait_timeout:
+ ret = is_peer_connected(mnode, servers)
+ if ret:
+ g.log.info("peers in connected state: %s", servers)
+ return True
+ sleep(1)
+ count += 1
+ g.log.error("Peers are not in connected state: %s", servers)
+ return False