Commit d0b7400c authored by Seth Howell's avatar Seth Howell Committed by Daniel Verkamp
Browse files

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: default avatarSeth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/410949


Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
parent 61770b52
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -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] + " <io_size> <queue_depth> <test_type> <runtime>"
        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] + " <io_size> <queue_depth> <test_type> <runtime>")
        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")