From 7de00fc74625efe9a35d4a5ae1da02d9737b2763 Mon Sep 17 00:00:00 2001 From: sayaleeraut Date: Mon, 27 Jan 2020 16:54:58 +0530 Subject: [Lib] Add function get_volume_type() The function get_volume_type() will return the type of volume (as distributed/replicate/disperse/arbiter/distributed-replicated/ distributed-dispersed/distributed-arbiter) under test. Change-Id: Ib23ae1ad18ef65d0520fe041a5f80211030a034b Signed-off-by: sayaleeraut --- .../glustolibs/gluster/volume_libs.py | 36 +++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/glustolibs-gluster/glustolibs/gluster/volume_libs.py b/glustolibs-gluster/glustolibs/gluster/volume_libs.py index e5a4f4f1c..435ddcf43 100644 --- a/glustolibs-gluster/glustolibs/gluster/volume_libs.py +++ b/glustolibs-gluster/glustolibs/gluster/volume_libs.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2019 Red Hat, Inc. +# Copyright (C) 2015-2020 Red Hat, Inc. # # 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 @@ -2215,3 +2215,37 @@ def get_files_and_dirs_from_brick(brick_node, brick_path, brick_node, brick_path) result.extend(out.splitlines()) return result + + +def get_volume_type(brickdir_path): + """Checks for the type of volume under test. + + Args: + brickdir_path(str): The complete brick path. + (e.g., server1.example.com:/bricks/brick1) + + Returns: + volume type(str): The volume type in str. + NoneType : None on failure + """ + # Adding import here to avoid cyclic imports + from glustolibs.gluster.brick_libs import get_all_bricks + (host, _) = brickdir_path.split(':') + for volume in get_volume_list(host): + if brickdir_path in get_all_bricks(host, volume): + ret = get_volume_info(host, volume) + if ret is None: + g.log.error("Failed to get volume type for %s", volume) + return None + list_of_replica = ('Replicate', 'Distributed-Replicate') + if (ret[volume].get('typeStr') in list_of_replica and + int(ret[volume]['arbiterCount']) == 1): + if int(ret[volume]['distCount']) >= 2: + return 'Distributed-Arbiter' + else: + return 'Arbiter' + else: + return ret[volume].get('typeStr') + else: + g.log.info("Failed to find brick-path %s for vol %s", + brickdir_path, volume) -- cgit