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