From faf5077586ab5c631524a434533da4e46f25abae Mon Sep 17 00:00:00 2001 From: ShwethaHP Date: Fri, 15 Dec 2017 14:58:06 +0530 Subject: Adding functions for: 1. Waiting for all bricks to be online 2. Waiting for all self-heal-daemons to be online 3. Waiting for all volume processes to be online Change-Id: I01a8711838227eb167e69710ecbd3abd0fecb9e6 Signed-off-by: ShwethaHP --- .../glustolibs/gluster/brick_libs.py | 39 +++++++++++++++++++ glustolibs-gluster/glustolibs/gluster/heal_libs.py | 36 ++++++++++++++++++ .../glustolibs/gluster/volume_libs.py | 44 +++++++++++++++++++++- 3 files changed, 118 insertions(+), 1 deletion(-) (limited to 'glustolibs-gluster/glustolibs/gluster') diff --git a/glustolibs-gluster/glustolibs/gluster/brick_libs.py b/glustolibs-gluster/glustolibs/gluster/brick_libs.py index 6c32fe5b9..4d79703d0 100644 --- a/glustolibs-gluster/glustolibs/gluster/brick_libs.py +++ b/glustolibs-gluster/glustolibs/gluster/brick_libs.py @@ -812,3 +812,42 @@ def get_bricks_to_bring_offline_from_disperse_volume(subvols_list, list_of_bricks_to_bring_offline.extend(bricks_to_bring_offline) return list_of_bricks_to_bring_offline + + +def wait_for_bricks_to_be_online(mnode, volname, timeout=300): + """Waits for the bricks to be online until timeout + + Args: + mnode (str): Node on which commands will be executed. + volname (str): Name of the volume. + + Kwargs: + timeout (int): timeout value in seconds to wait for bricks to be + online + + Returns: + True if all bricks are online within timeout, False otherwise + """ + all_bricks = get_all_bricks(mnode, volname) + if not all_bricks: + return False + + counter = 0 + flag = 0 + while counter < timeout: + status = are_bricks_online(mnode, volname, all_bricks) + + if status: + flag = 1 + break + if not status: + time.sleep(10) + counter = counter + 10 + + if not flag: + g.log.error("All Bricks of the volume '%s' are not online " + "even after %d minutes", (volname, timeout/60.0)) + return False + else: + g.log.info("All Bricks of the volume '%s' are online ", volname) + return True diff --git a/glustolibs-gluster/glustolibs/gluster/heal_libs.py b/glustolibs-gluster/glustolibs/gluster/heal_libs.py index 10707df63..5ccb4b2b4 100644 --- a/glustolibs-gluster/glustolibs/gluster/heal_libs.py +++ b/glustolibs-gluster/glustolibs/gluster/heal_libs.py @@ -269,3 +269,39 @@ def get_unhealed_entries_info(volname, mnode=''): False otherwise """ return True + + +def wait_for_self_heal_daemons_to_be_online(mnode, volname, timeout=300): + """Waits for the volume self-heal-daemons to be online until timeout + + Args: + mnode (str): Node on which commands will be executed. + volname (str): Name of the volume. + + Kwargs: + timeout (int): timeout value in seconds to wait for self-heal-daemons + to be online. + + Returns: + True if all self-heal-daemons are online within timeout, + False otherwise + """ + counter = 0 + flag = 0 + while counter < timeout: + status = are_all_self_heal_daemons_are_online(mnode, volname) + if status: + flag = 1 + break + if not status: + time.sleep(10) + counter = counter + 10 + + if not flag: + g.log.error("All self-heal-daemons of the volume '%s' are not online " + "even after %d minutes", (volname, timeout/60.0)) + return False + else: + g.log.info("All self-heal-daemons of the volume '%s' are online ", + volname) + return True diff --git a/glustolibs-gluster/glustolibs/gluster/volume_libs.py b/glustolibs-gluster/glustolibs/gluster/volume_libs.py index c62839778..5b668350e 100644 --- a/glustolibs-gluster/glustolibs/gluster/volume_libs.py +++ b/glustolibs-gluster/glustolibs/gluster/volume_libs.py @@ -37,7 +37,9 @@ from glustolibs.gluster.quota_ops import (enable_quota, set_quota_limit_usage, is_quota_enabled) from glustolibs.gluster.uss_ops import enable_uss, is_uss_enabled from glustolibs.gluster.snap_ops import snap_delete_by_volumename -from glustolibs.gluster.heal_libs import are_all_self_heal_daemons_are_online +from glustolibs.gluster.heal_libs import ( + are_all_self_heal_daemons_are_online, + wait_for_self_heal_daemons_to_be_online) from glustolibs.gluster.brick_ops import add_brick, remove_brick, replace_brick @@ -1827,3 +1829,43 @@ def get_client_quorum_info(mnode, volname): ['quorum_count']) = quorum_count return client_quorum_dict + + +def wait_for_volume_process_to_be_online(mnode, volname, timeout=300): + """Waits for the volume's processes to be online until timeout + + Args: + mnode (str): Node on which commands will be executed. + volname (str): Name of the volume. + + Kwargs: + timeout (int): timeout value in seconds to wait for all volume + processes to be online. + + Returns: + True if the volume's processes are online within timeout, + False otherwise + """ + # Adding import here to avoid cyclic imports + from glustolibs.gluster.brick_libs import wait_for_bricks_to_be_online + + # Wait for bricks to be online + bricks_online_status = wait_for_bricks_to_be_online(mnode, volname, + timeout) + if bricks_online_status is False: + g.log.error("Failed to wait for the volume '%s' processes " + "to be online", volname) + return False + + # Wait for self-heal-daemons to be online + self_heal_daemon_online_status = ( + wait_for_self_heal_daemons_to_be_online(mnode, volname, timeout)) + if self_heal_daemon_online_status is False: + g.log.error("Failed to wait for the volume '%s' processes " + "to be online", volname) + return False + + # TODO: Add any process checks here + + g.log.info("Volume '%s' processes are all online", volname) + return True -- cgit