From 1a6c15c9d2721b94ebfa05e399dd3b7719d4843d Mon Sep 17 00:00:00 2001 From: Vinayak Papnoi Date: Mon, 20 Jan 2020 15:51:54 +0530 Subject: [lib] Add method to get list of snaps in .snaps This addition is to aid the test cases which validate the existence of snapshots under the '.snaps' directory. The existing method i.e. 'uss_list_snap' does not help in getting the list of snapshots and instead just recursively performs 'ls' under the .snaps directory. This method will return a list of directory names present under the '.snaps' directory. Change-Id: I808131788df975ca243ac5721713492422af0ab8 Signed-off-by: Vinayak Papnoi --- glustolibs-gluster/glustolibs/gluster/uss_ops.py | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/glustolibs-gluster/glustolibs/gluster/uss_ops.py b/glustolibs-gluster/glustolibs/gluster/uss_ops.py index a6f9b8f98..2df112d78 100644 --- a/glustolibs-gluster/glustolibs/gluster/uss_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/uss_ops.py @@ -154,6 +154,7 @@ def uss_list_snaps(client, mount): Args: client(str):client on which commands has to be executed mount(str): Mount points to be executed + Returns: tuple: Tuple containing three elements (ret, out, err). The first element 'ret' is of type 'int' and is the return value @@ -167,3 +168,29 @@ def uss_list_snaps(client, mount): """ cmd = "ls -R %s/.snaps" % (mount) return g.run(client, cmd) + + +def get_uss_list_snaps(client, mount): + """Fetches the list of snapshots under the .snaps directory + + Args: + client(str):client on which commands has to be executed + mount(str): Mount points to be executed + + Returns: + NoneType: If there are errors + list: List of snapshot names present under .snaps directory + + Examples: + >>> get_uss_list_snaps('abc.lab.eng.xyz.com', 'mountpoint') + ['snap1', 'snap2', 'snap3'] + + """ + cmd = "ls %s/.snaps" % (mount) + ret, out, _ = g.run(client, cmd) + if ret: + g.log.error(".snaps list returned error") + return None + + snap_dir_list = out.splitlines() + return snap_dir_list -- cgit