diff options
author | kshithijiyer <kshithij.ki@gmail.com> | 2020-02-04 12:27:00 +0530 |
---|---|---|
committer | kshithijiyer <kshithij.ki@gmail.com> | 2020-02-04 17:40:13 +0530 |
commit | 3464b5c67607b31a6c259ff80e4cb194e0248d09 (patch) | |
tree | 429608edb21fd6b2f3d7e5057006541664e5a2d3 /glustolibs-gluster | |
parent | b980012f601f3037c3927d7f22780a228a5efb10 (diff) |
[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 <BrickPath> -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 <kshithij.ki@gmail.com>
Diffstat (limited to 'glustolibs-gluster')
-rwxr-xr-x | glustolibs-gluster/glustolibs/gluster/lib_utils.py | 48 |
1 files changed, 47 insertions, 1 deletions
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. <http://www.redhat.com> +# Copyright (C) 2015-2020 Red Hat, Inc. <http://www.redhat.com> # # 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) |