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
################################################################################
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 <count> requests',
default = '10')
help = 'stop after <count> 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':