e3c68b
From 1ca8a545833e0a6e674984245338b8675ddc58bc Mon Sep 17 00:00:00 2001
e3c68b
From: Kotresh HR <khiremat@redhat.com>
e3c68b
Date: Fri, 10 Jan 2020 16:48:14 +0530
e3c68b
Subject: [PATCH 348/349] glusterfind: Fix py2/py3 issues
e3c68b
e3c68b
1. In dictionary values(), returns list in py2 and not in py3.
e3c68b
   So explicitly convert it into list.
e3c68b
2. xattr module returns values in bytes. So explicitly convert
e3c68b
   them to str to work both with py2 and py3
e3c68b
e3c68b
Backport of:
e3c68b
 > Patch: https://review.gluster.org/23993
e3c68b
 > fixes: bz#1789439
e3c68b
 > Change-Id: I27a639cda4f7a4ece9744a97c3d16e247906bd94
e3c68b
 > Signed-off-by: Kotresh HR <khiremat@redhat.com>
e3c68b
e3c68b
BUG: 1789447
e3c68b
Change-Id: I27a639cda4f7a4ece9744a97c3d16e247906bd94
e3c68b
Signed-off-by: Kotresh HR <khiremat@redhat.com>
e3c68b
Reviewed-on: https://code.engineering.redhat.com/gerrit/189215
e3c68b
Reviewed-by: Shwetha Acharya <sacharya@redhat.com>
e3c68b
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e3c68b
Reviewed-by: Hari Gowtham Gopal <hgowtham@redhat.com>
e3c68b
Reviewed-by: Sunny Kumar <sunkumar@redhat.com>
e3c68b
---
e3c68b
 tools/glusterfind/src/changelog.py | 14 +++++++++-----
e3c68b
 tools/glusterfind/src/main.py      |  8 ++++----
e3c68b
 2 files changed, 13 insertions(+), 9 deletions(-)
e3c68b
e3c68b
diff --git a/tools/glusterfind/src/changelog.py b/tools/glusterfind/src/changelog.py
e3c68b
index d8f97e0..d972fb5 100644
e3c68b
--- a/tools/glusterfind/src/changelog.py
e3c68b
+++ b/tools/glusterfind/src/changelog.py
e3c68b
@@ -14,6 +14,7 @@ import sys
e3c68b
 import time
e3c68b
 import xattr
e3c68b
 import logging
e3c68b
+from gfind_py2py3 import bytearray_to_str
e3c68b
 from argparse import ArgumentParser, RawDescriptionHelpFormatter
e3c68b
 import hashlib
e3c68b
 try:
e3c68b
@@ -105,9 +106,10 @@ def populate_pgfid_and_inodegfid(brick, changelog_data):
e3c68b
                 changelog_data.inodegfid_add(os.stat(p).st_ino, gfid)
e3c68b
                 file_xattrs = xattr.list(p)
e3c68b
                 for x in file_xattrs:
e3c68b
-                    if x.startswith("trusted.pgfid."):
e3c68b
+                    x_str = bytearray_to_str(x)
e3c68b
+                    if x_str.startswith("trusted.pgfid."):
e3c68b
                         # PGFID in pgfid table
e3c68b
-                        changelog_data.pgfid_add(x.split(".")[-1])
e3c68b
+                        changelog_data.pgfid_add(x_str.split(".")[-1])
e3c68b
             except (IOError, OSError):
e3c68b
                 # All OS Errors ignored, since failures will be logged
e3c68b
                 # in End. All GFIDs present in gfidpath table
e3c68b
@@ -122,10 +124,12 @@ def enum_hard_links_using_gfid2path(brick, gfid, args):
e3c68b
         try:
e3c68b
             file_xattrs = xattr.list(p)
e3c68b
             for x in file_xattrs:
e3c68b
-                if x.startswith("trusted.gfid2path."):
e3c68b
+                x_str = bytearray_to_str(x)
e3c68b
+                if x_str.startswith("trusted.gfid2path."):
e3c68b
                     # get the value for the xattr i.e. <PGFID>/<BN>
e3c68b
-                    v = xattr.getxattr(p, x)
e3c68b
-                    pgfid, bn = v.split(os.sep)
e3c68b
+                    v = xattr.getxattr(p, x_str)
e3c68b
+                    v_str = bytearray_to_str(v)
e3c68b
+                    pgfid, bn = v_str.split(os.sep)
e3c68b
                     try:
e3c68b
                         path = symlink_gfid_to_path(brick, pgfid)
e3c68b
                         fullpath = os.path.join(path, bn)
e3c68b
diff --git a/tools/glusterfind/src/main.py b/tools/glusterfind/src/main.py
e3c68b
index fefe4a3..dfc9d07 100644
e3c68b
--- a/tools/glusterfind/src/main.py
e3c68b
+++ b/tools/glusterfind/src/main.py
e3c68b
@@ -633,7 +633,7 @@ def mode_query(session_dir, args):
e3c68b
     # Merger
e3c68b
     if args.full:
e3c68b
         if len(g_pid_nodefile_map) > 0:
e3c68b
-            cmd = ["sort", "-u"] + g_pid_nodefile_map.values() + \
e3c68b
+            cmd = ["sort", "-u"] + list(g_pid_nodefile_map.values()) + \
e3c68b
                   ["-o", args.outfile]
e3c68b
             execute(cmd,
e3c68b
                     exit_msg="Failed to merge output files "
e3c68b
@@ -645,7 +645,7 @@ def mode_query(session_dir, args):
e3c68b
         # Read each Changelogs db and generate finaldb
e3c68b
         create_file(args.outfile, exit_on_err=True, logger=logger)
e3c68b
         outfilemerger = OutputMerger(args.outfile + ".db",
e3c68b
-                                     g_pid_nodefile_map.values())
e3c68b
+                                     list(g_pid_nodefile_map.values()))
e3c68b
         write_output(args.outfile, outfilemerger, args.field_separator)
e3c68b
 
e3c68b
     try:
e3c68b
@@ -702,7 +702,7 @@ def mode_pre(session_dir, args):
e3c68b
     # Merger
e3c68b
     if args.full:
e3c68b
         if len(g_pid_nodefile_map) > 0:
e3c68b
-            cmd = ["sort", "-u"] + g_pid_nodefile_map.values() + \
e3c68b
+            cmd = ["sort", "-u"] + list(g_pid_nodefile_map.values()) + \
e3c68b
                   ["-o", args.outfile]
e3c68b
             execute(cmd,
e3c68b
                     exit_msg="Failed to merge output files "
e3c68b
@@ -714,7 +714,7 @@ def mode_pre(session_dir, args):
e3c68b
         # Read each Changelogs db and generate finaldb
e3c68b
         create_file(args.outfile, exit_on_err=True, logger=logger)
e3c68b
         outfilemerger = OutputMerger(args.outfile + ".db",
e3c68b
-                                     g_pid_nodefile_map.values())
e3c68b
+                                     list(g_pid_nodefile_map.values()))
e3c68b
         write_output(args.outfile, outfilemerger, args.field_separator)
e3c68b
 
e3c68b
     try:
e3c68b
-- 
e3c68b
1.8.3.1
e3c68b