Fix coding style

This commit is contained in:
Thomas Gebert 2024-12-10 09:47:04 +01:00
parent f72fabaae7
commit 1cde979a3d

View File

@ -11,42 +11,38 @@ import sys
################################################################################ ################################################################################
# Global variables and defaults # Global variables and defaults
################################################################################ ################################################################################
iointerfaces_allowed = [ iointerfaces_allowed = ['async',
'async', 'cached',
'cached', 'direct',
'direct', 'sync',
'sync', 'dsync']
'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 # Global functions
################################################################################ ################################################################################
# Function to run the shell command and capture outputs and returncode # Function to run the shell command and capture outputs and returncode
def capture_ioping_results(): def capture_ioping_results():
if ioping_arguments['location'] == '':
return 1, '', 'No ioping_locationectory given.'
if ioping_arguments['location'] == '': cmd = '%s %s --count %s --interval %s %s' % (ioping_arguments['cmd'],
return 1, '', 'No ioping_locationectory given.' ioping_arguments['options'],
ioping_arguments['count'],
cmd = '%s %s --count %s --interval %s %s' % (ioping_arguments['cmd'], ioping_arguments['interval'],
ioping_arguments['options'], ioping_arguments['location'])
ioping_arguments['count'], ioping_arguments['cmd'] = cmd
ioping_arguments['interval'], ioping_output = subprocess.run(cmd.split(),
ioping_arguments['location'])
ioping_arguments['cmd'] = cmd
ioping_output = subprocess.run(cmd.split(),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
encoding='utf-8') 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 # Function to output the ioping capture on an interactive shell
@ -58,6 +54,7 @@ def ioping_output_shell():
print(stdout) print(stdout)
else: else:
print(stderr) print(stderr)
return returncode return returncode
@ -69,18 +66,16 @@ def ioping_output_telegraf():
print(stderr) print(stderr)
return returncode return returncode
ioping_statistic_keys = [ ioping_statistic_keys = ['statistics_count',
'statistics_count', 'runtime',
'runtime', 'iops',
'iops', 'transfer_speed',
'transfer_speed', 'min_request_time',
'min_request_time', 'avg_request_time',
'avg_request_time', 'max_request_time',
'max_request_time', 'std_deviation_request_time',
'std_deviation_request_time', 'total_requests',
'total_requests', 'total_running_time']
'total_running_time'
]
try: try:
ioping_statistics = dict(zip(ioping_statistic_keys, stdout.split())) ioping_statistics = dict(zip(ioping_statistic_keys, stdout.split()))
@ -96,24 +91,24 @@ def ioping_output_telegraf():
def get_parser(): def get_parser():
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-c', '--count', parser.add_argument('-c', '--count',
help = 'stop after <count> requests', help = 'stop after <count> requests',
default = '10') default = '10')
parser.add_argument('-i', '--interval', parser.add_argument('-i', '--interval',
help = 'interval between requests', help = 'interval between requests',
default = '1s') default = '1s')
parser.add_argument('-l', '--location', parser.add_argument('-l', '--location',
help = 'directory|file|device to test. Best would be a directory to not shred anything accidentially', help = 'directory|file|device to test. Best would be a directory to not shred anything accidentially',
default = '/tmp') default = '/tmp')
parser.add_argument('-m', '--mode', parser.add_argument('-m', '--mode',
help = 'Which output to use: shell|telegraf', help = 'Which output to use: shell|telegraf',
default = 'telegraf') default = 'telegraf')
parser.add_argument('-n', '--iointerface', parser.add_argument('-n', '--iointerface',
help = 'Which ionterface to use: async|cached|direct|sync|dsync', help = 'Which ionterface to use: async|cached|direct|sync|dsync',
default = '') default = '')
parser.add_argument('-w', '--read-write', parser.add_argument('-w', '--read-write',
help = 'Use read-write test instead of read.', help = 'Use read-write test instead of read.',
action = 'store_true', action = 'store_true',
default = 'False') default = 'False')
return parser return parser
@ -131,7 +126,6 @@ def main():
if args.iointerface in iointerfaces_allowed: if args.iointerface in iointerfaces_allowed:
ioping_arguments['options'] += '--%s ' % args.iointerface ioping_arguments['options'] += '--%s ' % args.iointerface
if args.mode == 'shell': if args.mode == 'shell':
returncode = ioping_output_shell() returncode = ioping_output_shell()
elif args.mode == 'telegraf': elif args.mode == 'telegraf':