From 1d0ff4497fa3df2f4acebbc0eef044fb122b64d9 Mon Sep 17 00:00:00 2001 From: sayaleeraut Date: Tue, 11 Aug 2020 22:46:11 +0530 Subject: [LibFix] Add encoding type to get_fattr() Currently the get_fattr() function returns the xattr value in the hex encoding format. Adding the option to add/specify other encoding types, i.e. text and base64, where hex will be the default encoding format. Reason - When the xattrs are custom set through mountpoint, it becomes easier to test if the value is correct by using the "text" encoding. Example - >>> ret = get_fattr(host, fqpath, fattr) >>> print ret 0x414243 >>> ret = get_fattr(host, fqpath, fattr, encode="text") >>> print ret "ABC" The value "ABC" is easily readable as opposed to 0x414243 when performing a test. Change-Id: Ie2377b924816ebab0a2af116d82600e01f03d61f Signed-off-by: sayaleeraut --- glustolibs-gluster/glustolibs/gluster/glusterfile.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'glustolibs-gluster') diff --git a/glustolibs-gluster/glustolibs/gluster/glusterfile.py b/glustolibs-gluster/glustolibs/gluster/glusterfile.py index 32068d9f4..86383e800 100755 --- a/glustolibs-gluster/glustolibs/gluster/glusterfile.py +++ b/glustolibs-gluster/glustolibs/gluster/glusterfile.py @@ -97,22 +97,24 @@ def get_mountpoint(host, fqpath): return None -def get_fattr(host, fqpath, fattr): +def get_fattr(host, fqpath, fattr, encode="hex"): """getfattr for filepath on remote system Args: host (str): The hostname/ip of the remote system. fqpath (str): The fully-qualified path to the file. fattr (str): name of the fattr to retrieve - + Kwargs: + encode(str): The supported types of encoding are + [hex|text|base64] + Defaults to hex type of encoding Returns: getfattr result on success. None on fail. """ - command = ("getfattr --absolute-names -e hex " + command = ("getfattr --absolute-names -e '%s' " "-n '%s' %s" % - (fattr, fqpath)) + (encode, fattr, fqpath)) rcode, rout, rerr = g.run(host, command) - if not rcode: return rout.strip().split('=')[1] -- cgit