From d4ee7ad936e45019275e536f0041addee54812c4 Mon Sep 17 00:00:00 2001 From: kshithijiyer Date: Mon, 10 Aug 2020 14:44:12 +0530 Subject: [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 = , 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 --- glustolibs-gluster/glustolibs/gluster/glusterfile.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'glustolibs-gluster/glustolibs') 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 -- cgit