From 3464b5c67607b31a6c259ff80e4cb194e0248d09 Mon Sep 17 00:00:00 2001 From: kshithijiyer Date: Tue, 4 Feb 2020 12:27:00 +0530 Subject: [lib] Adding collect_bricks_arequal() to lib_utils.py Adding function collect_bricks_arequal() to lib_utils.py to collect arequal-checksum on all the bricks of all the nodes used to create a volume using the below command: ``` arequal-checksum -p -i .glusterfs -i .landfill -i .trashcan ``` Usage: ``` >>> all_bricks = get_all_bricks(self.mnode, self.volname) >>> ret, arequal = collect_bricks_arequal(all_bricks) >>> ret True ``` Change-Id: Id42615469be18d84e5691c982369634c436ed0cf Signed-off-by: kshithijiyer --- glustolibs-gluster/glustolibs/gluster/lib_utils.py | 48 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'glustolibs-gluster/glustolibs/gluster') diff --git a/glustolibs-gluster/glustolibs/gluster/lib_utils.py b/glustolibs-gluster/glustolibs/gluster/lib_utils.py index e1a9182aa..2c0dda3dd 100755 --- a/glustolibs-gluster/glustolibs/gluster/lib_utils.py +++ b/glustolibs-gluster/glustolibs/gluster/lib_utils.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (C) 2015-2016 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 @@ -1183,3 +1183,49 @@ def is_passwordless_ssh_configured(fromnode, tonode, username): (fromnode, tonode, username)) return False return True + + +def collect_bricks_arequal(bricks_list): + """Collects arequal for all bricks in list + + Args: + bricks_list (list): List of bricks. + Example: + bricks_list = 'gluster.blr.cluster.com:/bricks/brick1/vol' + + Returns: + tuple(bool, list): + On success returns (True, list of arequal-checksums of each brick) + On failure returns (False, list of arequal-checksums of each brick) + arequal-checksum for a brick would be 'None' when failed to + collect arequal for that brick. + + Example: + >>> all_bricks = get_all_bricks(self.mnode, self.volname) + >>> ret, arequal = collect_bricks_arequal(all_bricks) + >>> ret + True + """ + # Converting a bricks_list to list if not. + if not isinstance(bricks_list, list): + bricks_list = [bricks_list] + + return_code, arequal_list = True, [] + for brick in bricks_list: + + # Running arequal-checksum on the brick. + node, brick_path = brick.split(':') + cmd = ('arequal-checksum -p {} -i .glusterfs -i .landfill -i .trashcan' + .format(brick_path)) + ret, arequal, _ = g.run(node, cmd) + + # Generating list accordingly + if ret: + g.log.error('Failed to get arequal on brick %s', brick) + return_code = False + arequal_list.append(None) + else: + g.log.info('Successfully calculated arequal for brick %s', brick) + arequal_list.append(arequal) + + return (return_code, arequal_list) -- cgit