summaryrefslogtreecommitdiffstats
path: root/glustolibs-gluster/glustolibs
diff options
context:
space:
mode:
Diffstat (limited to 'glustolibs-gluster/glustolibs')
-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 7467479b4..047046737 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 988a13cb7..7027ce11f 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