summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkshithijiyer <kshithij.ki@gmail.com>2020-08-10 14:44:12 +0530
committerBala Konda Reddy M <bala12352@gmail.com>2020-08-11 05:11:42 +0000
commitd4ee7ad936e45019275e536f0041addee54812c4 (patch)
treed05e8fa7db63beeb4f5e2799079ae9a804df957a
parent859fe721ae12b4d4eeb342954805ce2b51120d7e (diff)
[Libfix] Fix UnicodeDecodeError in get_fattr()
Problem: Some testcases fail with UnicodeDecodeError when the framework is run using python3. This happens becuase the get_fattr() command returns non-unicode output which leads to data.decode() used in subprocess.Popen to fail. This isn't the case in python2 as it doesn't bother about encoding and dumps whatever is the output back to the management node. ``` gfid = get_fattr(brick_tuple[0], brick_path + '/' + direc, 'trusted.gfid') /root/glusto-tests/tests/functional/dht/test_dht_create_dir.py:127: /usr/local/lib/python3.8/site-packages/glustolibs_gluster-0.22-py3.8.egg/glustolibs/gluster/glusterfile.py:113: in get_fattr rcode, rout, rerr = g.run(host, command) /usr/local/lib/python3.8/site-packages/glusto-0.72-py3.8.egg/glusto/connectible.py:132: in run stdout, stderr = proc.communicate() /usr/lib64/python3.8/subprocess.py:1024: in communicate stdout, stderr = self._communicate(input, endtime, timeout) /usr/lib64/python3.8/subprocess.py:1904: in _communicate stdout = self._translate_newlines(stdout, self = <subprocess.Popen object at 0x7f22b4e2f490>, data = b'\xber\t\nO\xebO\xee\xa4\x9c\xc4L\xac\x1cj\xd5', encoding = 'UTF-8', errors = 'strict' def _translate_newlines(self, data, encoding, errors): data = data.decode(encoding, errors) E UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbe in position 0: invalid start byte /usr/lib64/python3.8/subprocess.py:901: UnicodeDecodeError ``` Solution: Change get_fattr() command to return xattr value in hex to avoid UnicodeDecodeError error from Popen. Fixes: https://github.com/gluster/glusto-tests/issues/24 Change-Id: I8c4786c882adf6079404b97eca2c399535db068f Signed-off-by: kshithijiyer <kshithij.ki@gmail.com>
-rwxr-xr-xglustolibs-gluster/glustolibs/gluster/glusterfile.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/glusterfile.py b/glustolibs-gluster/glustolibs/gluster/glusterfile.py
index 7cb961c03..32068d9f4 100755
--- a/glustolibs-gluster/glustolibs/gluster/glusterfile.py
+++ b/glustolibs-gluster/glustolibs/gluster/glusterfile.py
@@ -108,12 +108,13 @@ def get_fattr(host, fqpath, fattr):
Returns:
getfattr result on success. None on fail.
"""
- command = ("getfattr --absolute-names --only-values -n '%s' %s" %
+ command = ("getfattr --absolute-names -e hex "
+ "-n '%s' %s" %
(fattr, fqpath))
rcode, rout, rerr = g.run(host, command)
- if rcode == 0:
- return rout.strip()
+ if not rcode:
+ return rout.strip().split('=')[1]
g.log.error('getfattr failed: %s' % rerr)
return None