From d0b7400c0819b6e94f7f161304fd993d4a393b30 Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Fri, 11 May 2018 14:39:35 -0700 Subject: [PATCH] scripts: Make fio.py python3 compatible Fix deprecated print statements and properly encode strings for file and process communications. Change-Id: I896c9dd7b9b15be8684af267066dae8ca8df4f62 Signed-off-by: Seth Howell Reviewed-on: https://review.gerrithub.io/410949 Reviewed-by: Jim Harris Reviewed-by: Daniel Verkamp Tested-by: SPDK Automated Test System --- scripts/fio.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/fio.py b/scripts/fio.py index 4316f7e67..992a9f353 100755 --- a/scripts/fio.py +++ b/scripts/fio.py @@ -37,7 +37,7 @@ filename=%(device)s def interrupt_handler(signum, frame): fio.terminate() - print "FIO terminated" + print("FIO terminated") sys.exit(0) @@ -45,11 +45,11 @@ def main(): global fio if (len(sys.argv) < 5): - print "usage:" - print " " + sys.argv[0] + " " - print "advanced usage:" - print "If you want to run fio with verify, please add verify string after runtime." - print "Currently fio.py only support write rw randwrite randrw with verify enabled." + print("usage:") + print(" " + sys.argv[0] + " ") + print("advanced usage:") + print("If you want to run fio with verify, please add verify string after runtime.") + print("Currently fio.py only support write rw randwrite randrw with verify enabled.") sys.exit(1) io_size = int(sys.argv[1]) @@ -62,7 +62,7 @@ def main(): verify = False devices = get_target_devices() - print "Found devices: ", devices + print("Found devices: ", devices) configure_devices(devices) fio_executable = '/usr/bin/fio' @@ -72,17 +72,17 @@ def main(): signal.signal(signal.SIGTERM, interrupt_handler) signal.signal(signal.SIGINT, interrupt_handler) fio = Popen([fio_executable, '-'], stdin=PIPE) - fio.communicate(create_fio_config(io_size, queue_depth, device_paths, test_type, runtime, verify)) + fio.communicate(create_fio_config(io_size, queue_depth, device_paths, test_type, runtime, verify).encode()) fio.stdin.close() rc = fio.wait() - print "FIO completed with code %d\n" % rc + print("FIO completed with code %d\n" % rc) sys.stdout.flush() sys.exit(rc) def get_target_devices(): output = check_output('iscsiadm -m session -P 3', shell=True) - return re.findall("Attached scsi disk (sd[a-z]+)", output) + return re.findall("Attached scsi disk (sd[a-z]+)", output.decode("ascii")) def create_fio_config(size, q_depth, devices, test, run_time, verify): @@ -101,7 +101,7 @@ def set_device_parameter(devices, filename_template, value): for dev in devices: filename = filename_template % dev f = open(filename, 'r+b') - f.write(value) + f.write(value.encode()) f.close() @@ -117,9 +117,9 @@ def configure_devices(devices): except IOError: qd = qd - 1 if qd == 0: - print "Could not set block device queue depths." + print("Could not set block device queue depths.") else: - print "Requested queue_depth {} but only {} is supported.".format(str(requested_qd), str(qd)) + print("Requested queue_depth {} but only {} is supported.".format(str(requested_qd), str(qd))) set_device_parameter(devices, "/sys/block/%s/queue/scheduler", "noop")