From 277d10417b35eb1050f701b110f4c9dff4526d7c Mon Sep 17 00:00:00 2001 From: Charles Short Date: Fri, 25 Jun 2021 11:46:31 -0400 Subject: [PATCH] Fix py3 issues - Update popen to use universal_newlines=True to enable newlines for calls that we parse or consume output for. Without universal_newlines=True, the output is treated as bytes under python3 which leads to issues later where we are using it as strings. - The division operator in Python 3 results in a float, not an integer like in Python 2. Use the truncation division operator instead. - Use python builtins since the behavior of round has changed between python2 and python3. (https://docs.python.org/3/whatsnew/3.0.html#builtins) Story: 2006796 Task: 42695 Signed-off-by: Charles Short Change-Id: I9c9a4fdfd8a65cf6a3034a2c80c3a620ab138d22 (cherry picked from commit 9ced50cf38df6166587a338765c92596d41a27a8) --- .../storage_topology/exec/storage_topology.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/storage-topology/storage-topology/storage_topology/exec/storage_topology.py b/tools/storage-topology/storage-topology/storage_topology/exec/storage_topology.py index b920aeb48..8c4aac4f2 100644 --- a/tools/storage-topology/storage-topology/storage_topology/exec/storage_topology.py +++ b/tools/storage-topology/storage-topology/storage_topology/exec/storage_topology.py @@ -29,6 +29,7 @@ import textwrap import keyring import subprocess import math +from builtins import round from prettytable import PrettyTable from cgtsclient.common import utils from cgtsclient import client as cgts_client @@ -145,7 +146,7 @@ def get_system_creds(): proc = subprocess.Popen(['bash', '-c', 'source /etc/platform/openrc && env'], - stdout=subprocess.PIPE) + stdout=subprocess.PIPE, universal_newlines=True) for line in proc.stdout: key, _, value = line.partition("=") @@ -180,7 +181,7 @@ def convert_to_readable_size(size, orig_unit='B'): if unitIndex > 5: unitIndex = 5 sizer = math.pow(1024, unitIndex) - newsize = round(size / sizer, 2) + newsize = round(size // sizer, 2) return "%s %s" % (newsize, units[unitIndex])