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