From dc6f9571c10b29f17845a769168a1df6392f0019 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 14 Feb 2018 14:34:55 -0700 Subject: [PATCH] pep8: re-enable E302 (2 blank lines between functions) This isn't a significant effort to fix, so let's just enable it to move closer to the official Python PEP 8 guidelines. Fix up the existing instances where we didn't already have two lines between functions, and re-enable the pep8 warning. Change-Id: I9cf5e7e32b9c6dfedbd1b0f9bc92951cbb2c8a0d Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/399949 Reviewed-by: Jim Harris Tested-by: SPDK Automated Test System Reviewed-by: Shuhei Matsumoto --- autorun_post.py | 1 + scripts/check_format.sh | 1 - scripts/fio.py | 7 +++++++ scripts/perf/nvme/run_fio_test.py | 6 ++++++ scripts/rpc/app.py | 1 + scripts/rpc/bdev.py | 1 + scripts/rpc/vhost.py | 2 ++ test/iscsi_tgt/calsoft/calsoft.py | 3 +++ test/iscsi_tgt/rpc_config/rpc_config.py | 7 +++++++ test/lvol/test_cases.py | 3 +++ test/nvmf/fio/nvmf_fio.py | 7 +++++++ 11 files changed, 38 insertions(+), 1 deletion(-) diff --git a/autorun_post.py b/autorun_post.py index 7382bb7fef..13cb6d8e0b 100755 --- a/autorun_post.py +++ b/autorun_post.py @@ -7,6 +7,7 @@ import os import glob import re + def generateCoverageReport(output_dir, repo_dir): with open(os.path.join(output_dir, 'coverage.log'), 'w+') as log_file: coveragePath = os.path.join(output_dir, '**', 'cov_total.info') diff --git a/scripts/check_format.sh b/scripts/check_format.sh index 60eae94c2c..6959a579d5 100755 --- a/scripts/check_format.sh +++ b/scripts/check_format.sh @@ -103,7 +103,6 @@ rm -f scripts/posix.log if hash pep8; then echo -n "Checking Python style..." - PEP8_ARGS+=" --ignore=E302" # ignore 'E302 expected 2 blank lines, found 1' PEP8_ARGS+=" --max-line-length=140" error=0 diff --git a/scripts/fio.py b/scripts/fio.py index 35bc5f86d0..4316f7e671 100755 --- a/scripts/fio.py +++ b/scripts/fio.py @@ -34,11 +34,13 @@ filename=%(device)s """ + def interrupt_handler(signum, frame): fio.terminate() print "FIO terminated" sys.exit(0) + def main(): global fio @@ -77,10 +79,12 @@ def main(): 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) + def create_fio_config(size, q_depth, devices, test, run_time, verify): if not verify: verifyfio = "" @@ -92,6 +96,7 @@ def create_fio_config(size, q_depth, devices, test, run_time, verify): fiofile += fio_job_template % {"jobnumber": i, "device": dev} return fiofile + def set_device_parameter(devices, filename_template, value): for dev in devices: filename = filename_template % dev @@ -99,6 +104,7 @@ def set_device_parameter(devices, filename_template, value): f.write(value) f.close() + def configure_devices(devices): set_device_parameter(devices, "/sys/block/%s/queue/nomerges", "2") set_device_parameter(devices, "/sys/block/%s/queue/nr_requests", "128") @@ -116,5 +122,6 @@ def configure_devices(devices): print "Requested queue_depth {} but only {} is supported.".format(str(requested_qd), str(qd)) set_device_parameter(devices, "/sys/block/%s/queue/scheduler", "noop") + if __name__ == "__main__": main() diff --git a/scripts/perf/nvme/run_fio_test.py b/scripts/perf/nvme/run_fio_test.py index 8e72a07f2d..400e22c9fd 100755 --- a/scripts/perf/nvme/run_fio_test.py +++ b/scripts/perf/nvme/run_fio_test.py @@ -36,6 +36,7 @@ run_time = ['60'] # set iter_num = ['1', '2', '3'] to repeat each test 3 times iter_num = ['1'] + def run_fio(io_size_bytes, qd, rw_mix, cpu_mask, run_num, workload, run_time_sec): print "Running Test: IO Size=", io_size_bytes, " QD=", qd, " Mix=", rw_mix, "CPU Mask=", cpu_mask string = "s_" + str(io_size_bytes) + "_q_" + str(qd) + "_m_" + str(rw_mix) + "_c_" + str(cpu_mask) + "_run_" + str(run_num) @@ -51,6 +52,7 @@ def run_fio(io_size_bytes, qd, rw_mix, cpu_mask, run_num, workload, run_time_sec print "Finished Test: IO Size=", io_size_bytes, " QD=", qd, " Mix=", rw_mix, " CPU Mask=", cpu_mask return + def parse_results(io_size_bytes, qd, rw_mix, cpu_mask, run_num, workload, run_time_sec): results_array = [] @@ -107,20 +109,24 @@ def parse_results(io_size_bytes, qd, rw_mix, cpu_mask, run_num, workload, run_ti results_array = [] return + def get_nvme_devices_count(): output = check_output('lspci | grep -i Non | wc -l', shell=True) return int(output) + def get_nvme_devices_bdf(): output = check_output('lspci | grep -i Non | awk \'{print $1}\'', shell=True) output = output.split() return output + def add_filename_to_conf(conf_file_name, bdf): filestring = "filename=trtype=PCIe traddr=0000." + bdf.replace(":", ".") + " ns=1" with open(conf_file_name, "a") as conf_file: conf_file.write(filestring + "\n") + if len(sys.argv) != 4: print "usage: python ", sys.argv[0], " path_to_fio_conf path_to_ioengine num_ssds" sys.exit() diff --git a/scripts/rpc/app.py b/scripts/rpc/app.py index 0c9c2a1930..e7959ff60b 100755 --- a/scripts/rpc/app.py +++ b/scripts/rpc/app.py @@ -5,6 +5,7 @@ def kill_instance(args): params = {'sig_name': args.sig_name} args.client.call('kill_instance', params) + def context_switch_monitor(args): params = {} if args.enable: diff --git a/scripts/rpc/bdev.py b/scripts/rpc/bdev.py index fb5fcc014f..aa70fa3f3d 100755 --- a/scripts/rpc/bdev.py +++ b/scripts/rpc/bdev.py @@ -91,6 +91,7 @@ def bdev_inject_error(args): args.client.call('bdev_inject_error', params) + def apply_firmware(args): params = { 'filename': args.filename, diff --git a/scripts/rpc/vhost.py b/scripts/rpc/vhost.py index 55797b7ebb..84e06b996c 100755 --- a/scripts/rpc/vhost.py +++ b/scripts/rpc/vhost.py @@ -1,5 +1,6 @@ from client import print_dict, print_array, int_arg + def set_vhost_controller_coalescing(args): params = { 'ctrlr': args.ctrlr, @@ -8,6 +9,7 @@ def set_vhost_controller_coalescing(args): } args.client.call('set_vhost_controller_coalescing', params) + def construct_vhost_scsi_controller(args): params = {'ctrlr': args.ctrlr} diff --git a/test/iscsi_tgt/calsoft/calsoft.py b/test/iscsi_tgt/calsoft/calsoft.py index 62a5a6ba99..f2568ec9a7 100755 --- a/test/iscsi_tgt/calsoft/calsoft.py +++ b/test/iscsi_tgt/calsoft/calsoft.py @@ -32,6 +32,7 @@ known_failed_cases = ['tc_ffp_15_2', 'tc_ffp_29_2', 'tc_ffp_29_3', 'tc_err_3_4', 'tc_err_5_1', 'tc_login_3_1', 'tc_login_11_2', 'tc_login_11_4', 'tc_login_2_2'] + def run_case(case, result_list, log_dir_path): try: case_log = subprocess.check_output("{}/{}".format(CALSOFT_BIN_PATH, case), stderr=subprocess.STDOUT, shell=True) @@ -43,6 +44,7 @@ def run_case(case, result_list, log_dir_path): with open(log_dir_path + case + '.txt', 'w') as f: f.write(case_log) + def main(): if not os.path.exists(CALSOFT_BIN_PATH): print "The Calsoft test suite is not available on this machine." @@ -106,5 +108,6 @@ def main(): failed = 1 exit(failed) + if __name__ == '__main__': main() diff --git a/test/iscsi_tgt/rpc_config/rpc_config.py b/test/iscsi_tgt/rpc_config/rpc_config.py index 396b0bbb71..d27cc51fdf 100755 --- a/test/iscsi_tgt/rpc_config/rpc_config.py +++ b/test/iscsi_tgt/rpc_config/rpc_config.py @@ -78,6 +78,7 @@ def verify_trace_flag_rpc_methods(rpc_py, rpc_param): print "verify_trace_flag_rpc_methods passed" + def verify_iscsi_connection_rpc_methods(rpc_py): rpc = spdk_rpc(rpc_py) output = rpc.get_iscsi_connections() @@ -121,6 +122,7 @@ def verify_iscsi_connection_rpc_methods(rpc_py): print "verify_iscsi_connection_rpc_methods passed" + def verify_scsi_devices_rpc_methods(rpc_py): rpc = spdk_rpc(rpc_py) output = rpc.get_scsi_devices() @@ -357,6 +359,7 @@ def verify_target_nodes_rpc_methods(rpc_py, rpc_param): print "verify_target_nodes_rpc_methods passed." + def verify_get_interfaces(rpc_py): rpc = spdk_rpc(rpc_py) nics = json.loads(rpc.get_interfaces()) @@ -366,6 +369,7 @@ def verify_get_interfaces(rpc_py): verify(nics_names == ifcfg_nics, 1, "get_interfaces returned {}".format(nics)) print "verify_get_interfaces passed." + def help_get_interface_ip_list(rpc_py, nic_name): rpc = spdk_rpc(rpc_py) nics = json.loads(rpc.get_interfaces()) @@ -374,6 +378,7 @@ def help_get_interface_ip_list(rpc_py, nic_name): "Nic name: {} is not found in {}".format(nic_name, [x["name"] for x in nics])) return nic[0]["ip_addr"] + def verify_add_delete_ip_address(rpc_py): rpc = spdk_rpc(rpc_py) nics = json.loads(rpc.get_interfaces()) @@ -408,6 +413,7 @@ def verify_add_delete_ip_address(rpc_py): (faked_ip, x["name"])) print "verify_add_delete_ip_address passed." + def verify_add_nvme_bdev_rpc_methods(rpc_py): rpc = spdk_rpc(rpc_py) test_pass = 0 @@ -429,6 +435,7 @@ def verify_add_nvme_bdev_rpc_methods(rpc_py): verify(test_pass == 1, 1, "add nvme device passed second time") print "verify_add_nvme_bdev_rpc_methods passed." + if __name__ == "__main__": rpc_py = sys.argv[1] diff --git a/test/lvol/test_cases.py b/test/lvol/test_cases.py index c41a79fc78..80bd3b3e8d 100644 --- a/test/lvol/test_cases.py +++ b/test/lvol/test_cases.py @@ -16,6 +16,7 @@ from uuid import uuid4 MEGABYTE = 1024 * 1024 + def test_counter(): ''' :return: the number of tests @@ -68,10 +69,12 @@ def header(num): print("Test Name: {name}".format(name=test_name[num])) print("========================================================") + def footer(num): print("Test Case {num}: END\n".format(num=num)) print("========================================================") + class TestCases(object): def __init__(self, rpc_py, total_size, block_size, cluster_size, base_dir_path, app_path): diff --git a/test/nvmf/fio/nvmf_fio.py b/test/nvmf/fio/nvmf_fio.py index 0beac00702..2484c18978 100755 --- a/test/nvmf/fio/nvmf_fio.py +++ b/test/nvmf/fio/nvmf_fio.py @@ -34,11 +34,13 @@ filename=%(device)s """ + def interrupt_handler(signum, frame): fio.terminate() print "FIO terminated" sys.exit(0) + def main(): global fio @@ -78,10 +80,12 @@ def main(): sys.stdout.flush() sys.exit(rc) + def get_target_devices(): output = check_output('lsblk -l -o NAME', shell=True) return re.findall("(nvme[0-9]+n[0-9]+)\n", output) + def create_fio_config(size, q_depth, devices, test, run_time, verify): if not verify: verifyfio = "" @@ -93,6 +97,7 @@ def create_fio_config(size, q_depth, devices, test, run_time, verify): fiofile += fio_job_template % {"jobnumber": i, "device": dev} return fiofile + def set_device_parameter(devices, filename_template, value): for dev in devices: filename = filename_template % dev @@ -100,6 +105,7 @@ def set_device_parameter(devices, filename_template, value): f.write(value) f.close() + def configure_devices(devices): set_device_parameter(devices, "/sys/block/%s/queue/nomerges", "2") set_device_parameter(devices, "/sys/block/%s/queue/nr_requests", "128") @@ -117,5 +123,6 @@ def configure_devices(devices): print "Requested queue_depth {} but only {} is supported.".format(str(requested_qd), str(qd)) set_device_parameter(devices, "/sys/block/%s/queue/scheduler", "noop") + if __name__ == "__main__": main()