Skip to content

Commit

Permalink
RED-32089 when running python3, change bytes to strings
Browse files Browse the repository at this point in the history
(cherry picked from commit 67c62b3)
  • Loading branch information
Roey Prat committed Sep 26, 2019
1 parent 5e48803 commit 52aa177
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions log_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def collect_pods_logs():
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
# read one line a time - we do not want to read large files to memory
line = p.stdout.readline()
line = native_string(p.stdout.readline())
if line:
fp.write(line)
else:
Expand Down Expand Up @@ -259,6 +259,10 @@ def collect_helper(cmd, file_name, resource_name):
logger.info("Collected {}".format(resource_name))


def native_string(x):
return x if isinstance(x, str) else x.decode('utf-8', 'replace')


def run_shell_command(cmd):
"""
Returns a tuple of the shell exit code, output
Expand All @@ -272,7 +276,7 @@ def run_shell_command(cmd):
logger.warning("Failed in shell command: {}, output: {}".format(cmd, ex.output))
return ex.returncode, ex.output

return 0, output
return 0, native_string(output)


def run_kubectl_get(resource_type):
Expand Down

0 comments on commit 52aa177

Please sign in to comment.