From 1cde979a3df2aecf1baf7247bffefd8d70a214f3 Mon Sep 17 00:00:00 2001 From: Thomas Gebert Date: Tue, 10 Dec 2024 09:47:04 +0100 Subject: [PATCH] Fix coding style --- ioping/telegraf-ioping.py | 98 ++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 52 deletions(-) diff --git a/ioping/telegraf-ioping.py b/ioping/telegraf-ioping.py index 9838c3a..2682bf7 100644 --- a/ioping/telegraf-ioping.py +++ b/ioping/telegraf-ioping.py @@ -11,42 +11,38 @@ import sys ################################################################################ # Global variables and defaults ################################################################################ -iointerfaces_allowed = [ - 'async', - 'cached', - 'direct', - 'sync', - 'dsync' - ] +iointerfaces_allowed = ['async', + 'cached', + 'direct', + 'sync', + 'dsync'] + +ioping_arguments = {'location': '', + 'cmd': 'ioping --batch', + 'count': '10', + 'interval': '1s', + 'options': ''} -ioping_arguments = { - 'location': '', - 'cmd': 'ioping --batch', - 'count': '10', - 'interval': '1s', - 'options': '' - } ################################################################################ # Global functions ################################################################################ # Function to run the shell command and capture outputs and returncode def capture_ioping_results(): + if ioping_arguments['location'] == '': + return 1, '', 'No ioping_locationectory given.' - if ioping_arguments['location'] == '': - return 1, '', 'No ioping_locationectory given.' - - cmd = '%s %s --count %s --interval %s %s' % (ioping_arguments['cmd'], - ioping_arguments['options'], - ioping_arguments['count'], - ioping_arguments['interval'], - ioping_arguments['location']) - ioping_arguments['cmd'] = cmd - ioping_output = subprocess.run(cmd.split(), + cmd = '%s %s --count %s --interval %s %s' % (ioping_arguments['cmd'], + ioping_arguments['options'], + ioping_arguments['count'], + ioping_arguments['interval'], + ioping_arguments['location']) + ioping_arguments['cmd'] = cmd + ioping_output = subprocess.run(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8') - return ioping_output.returncode, ioping_output.stdout, ioping_output.stderr + return ioping_output.returncode, ioping_output.stdout, ioping_output.stderr # Function to output the ioping capture on an interactive shell @@ -58,6 +54,7 @@ def ioping_output_shell(): print(stdout) else: print(stderr) + return returncode @@ -69,18 +66,16 @@ def ioping_output_telegraf(): print(stderr) return returncode - ioping_statistic_keys = [ - 'statistics_count', - 'runtime', - 'iops', - 'transfer_speed', - 'min_request_time', - 'avg_request_time', - 'max_request_time', - 'std_deviation_request_time', - 'total_requests', - 'total_running_time' - ] + ioping_statistic_keys = ['statistics_count', + 'runtime', + 'iops', + 'transfer_speed', + 'min_request_time', + 'avg_request_time', + 'max_request_time', + 'std_deviation_request_time', + 'total_requests', + 'total_running_time'] try: ioping_statistics = dict(zip(ioping_statistic_keys, stdout.split())) @@ -96,24 +91,24 @@ def ioping_output_telegraf(): def get_parser(): parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-c', '--count', - help = 'stop after requests', - default = '10') + help = 'stop after requests', + default = '10') parser.add_argument('-i', '--interval', - help = 'interval between requests', - default = '1s') + help = 'interval between requests', + default = '1s') parser.add_argument('-l', '--location', - help = 'directory|file|device to test. Best would be a directory to not shred anything accidentially', - default = '/tmp') + help = 'directory|file|device to test. Best would be a directory to not shred anything accidentially', + default = '/tmp') parser.add_argument('-m', '--mode', - help = 'Which output to use: shell|telegraf', - default = 'telegraf') + help = 'Which output to use: shell|telegraf', + default = 'telegraf') parser.add_argument('-n', '--iointerface', - help = 'Which ionterface to use: async|cached|direct|sync|dsync', - default = '') + help = 'Which ionterface to use: async|cached|direct|sync|dsync', + default = '') parser.add_argument('-w', '--read-write', - help = 'Use read-write test instead of read.', - action = 'store_true', - default = 'False') + help = 'Use read-write test instead of read.', + action = 'store_true', + default = 'False') return parser @@ -131,7 +126,6 @@ def main(): if args.iointerface in iointerfaces_allowed: ioping_arguments['options'] += '--%s ' % args.iointerface - if args.mode == 'shell': returncode = ioping_output_shell() elif args.mode == 'telegraf': @@ -146,4 +140,4 @@ def main(): # Main main main ################################################################################ if __name__ == '__main__': - sys.exit(main()) \ No newline at end of file + sys.exit(main())