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