Skip to content

Commit

Permalink
Fixed pylint issues for some modules
Browse files Browse the repository at this point in the history
Signed-off-by: schamola <[email protected]>
  • Loading branch information
schamola committed Nov 23, 2023
1 parent df8d03a commit c5fc0a9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 34 deletions.
14 changes: 3 additions & 11 deletions plugins/modules/fix_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,16 +602,8 @@ def dictionary_to_json(dict_val, payload_type):
json_object (JSON) : JSON object containing all the attributes in JSON format.
'''

out_file = open("payloadfile.json", "w")

temp_out = open(payload_type, "w")

json.dump(dict_val, out_file, indent=4)

json.dump(dict_val, temp_out, indent=4)

out_file.close()
temp_out.close()
with open("payloadfile.json", "w", encoding="utf-8") as out_file:
json.dump(dict_val, out_file, indent=4)


def remove_json_file(module):
Expand Down Expand Up @@ -707,7 +699,7 @@ def get_URL(module):
URL.append(keys["url"])
size_of_file += keys['size']

if URL != []:
if URL:
return URL
else:
results['msg'] = "Could not retrieve the URLs."
Expand Down
14 changes: 7 additions & 7 deletions plugins/modules/mapping_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def vscsi_mappings(module, mappings):
if ret != 0:
if (ret == 10 or ret == 15) and module.params['component'] != 'vscsi':
return # E_NODEVPHYSLOC or E_NOTSVSA_S
module.fail_json(msg='lsmap failed rc=%d' % ret, stdout=stdout, stderr=stderr)
module.fail_json(msg=f'lsmap failed rc={ret}', stdout=stdout, stderr=stderr)

# List of fields returned by lsmap:
# svsa:physloc:clientid(:vtd:status:lun:backing:bdphysloc:mirrored)+
Expand Down Expand Up @@ -647,7 +647,7 @@ def npiv_mappings(module, mappings):
if ret != 0:
if (ret == 10 or ret == 63) and module.params['component'] != 'npiv':
return # E_NODEVPHYSLOC or E_NOTSVFCA_S
module.fail_json(msg='lsmap failed rc=%d' % ret, stdout=stdout, stderr=stderr)
module.fail_json(msg=f'lsmap failed rc={ret}', stdout=stdout, stderr=stderr)

# List of fields returned by lsmap -npiv:
# name:physloc:clntid:clntname:clntos:status:fc:fcphysloc:ports:flags:vfcclient:vfcclientdrc
Expand Down Expand Up @@ -697,7 +697,7 @@ def net_mappings(module, mappings):
if ret != 0:
if (ret == 10 or ret == 16) and module.params['component'] != 'net':
return # E_NODEVPHYSLOC or E_NOTSVEA_S
module.fail_json(msg='lsmap failed rc=%d' % ret, stdout=stdout, stderr=stderr)
module.fail_json(msg=f'lsmap failed rc={ret}', stdout=stdout, stderr=stderr)

# List of fields returned by lsmap -net:
# svea:physloc:sea:backing:status:bdphysloc
Expand Down Expand Up @@ -743,7 +743,7 @@ def vnic_mappings(module, mappings):
return # Ignore if lsmap -vnic option is not supported
if (ret == 10 or ret == 88) and module.params['component'] != 'vnic':
return # E_NODEVPHYSLOC or E_NOT_SVNIC_S
module.fail_json(msg='lsmap failed rc=%d' % ret, stdout=stdout, stderr=stderr)
module.fail_json(msg=f'lsmap failed rc={ret}', stdout=stdout, stderr=stderr)

# List of fields returned by lsmap -vnic:
# name:physloc:clntid:clntname:clntos:backing:status:bdphysloc:clntdev:clntphysloc
Expand Down Expand Up @@ -791,7 +791,7 @@ def ams_mappings(module, mappings):
if ret != 0:
if ret == 69 and module.params['component'] != 'ams':
return # E_NOTSVPD_S
module.fail_json(msg='lsmap failed rc=%d' % ret, stdout=stdout, stderr=stderr)
module.fail_json(msg=f'lsmap failed rc={ret}', stdout=stdout, stderr=stderr)

# List of fields returned by lsmap -ams:
# paging:streamid:clientid:status:redundancy:backing:poolid:vasi:pager:vbsd
Expand Down Expand Up @@ -839,7 +839,7 @@ def suspend_mappings(module, mappings):
if ret != 0:
if ret == 15 and module.params['component'] != 'suspend':
return # E_NOTSVSA_S
module.fail_json(msg='lsmap failed rc=%d' % ret, stdout=stdout, stderr=stderr)
module.fail_json(msg=f'lsmap failed rc={ret}', stdout=stdout, stderr=stderr)

# List of fields returned by lsmap -suspend:
# svsa:state:clientname:streamid:clientid(:vtd:status:lun:backing:bdphysloc:mirrored)+
Expand Down Expand Up @@ -903,7 +903,7 @@ def cluster_mappings(module, mappings):
if module.params['component'] != 'cluster':
mappings['cluster'][clustername]['errmsg'] = stderr
return
module.fail_json(msg='lsmap failed rc=%d' % ret, stdout=stdout, stderr=stderr)
module.fail_json(msg=f'lsmap failed rc={ret}', stdout=stdout, stderr=stderr)

# List of fields returned by lsmap -clustername:
# physloc:clientid:vtd:lun:backing
Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/updateios.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ def get_ioslevel(module):
if ret != 0:
results['stdout'] = stdout
results['stderr'] = stderr
results['msg'] = 'Could not retrieve ioslevel, return code {0}.'.format(ret)
results['msg'] = f'Could not retrieve ioslevel, return code {ret}.'
module.fail_json(**results)

ioslevel = stdout.split('\n')[0]

if not re.match(r"^\d+\.\d+\.\d+\.\d+$", ioslevel):
results['msg'] = 'Could not parse ioslevel output {0}.'.format(ioslevel)
results['msg'] = f'Could not parse ioslevel output {ioslevel}.'
module.fail_json(**results)

results['ioslevel'] = ioslevel
Expand Down Expand Up @@ -233,12 +233,12 @@ def main():
# It is better to call clstartstop from the playbook or from a role
# to remove the VIOS from the cluster before applying any update.

shcmd = "echo '{0}' | {1}".format(response, ' '.join(cmd))
shcmd = f"echo '{response}' | {' '.join(cmd)}"
ret, stdout, stderr = module.run_command(shcmd, use_unsafe_shell=True)
results['stdout'] = stdout
results['stderr'] = stderr
if ret != 0:
results['msg'] = 'Command \'{0}\' failed with return code {1}.'.format(shcmd, ret)
results['msg'] = f'Command \'{shcmd}\' failed with return code {ret}.'
module.fail_json(**results)

if action != 'list' and not module.check_mode:
Expand Down
16 changes: 8 additions & 8 deletions plugins/modules/viosbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,13 @@ def get_ioslevel(module):
if ret != 0:
results['stdout'] = stdout
results['stderr'] = stderr
results['msg'] = 'Could not retrieve ioslevel, return code {0}.'.format(ret)
results['msg'] = f'Could not retrieve ioslevel, return code {ret}.'
module.fail_json(**results)

ioslevel = stdout.split('\n')[0]

if not re.match(r"^\d+\.\d+\.\d+\.\d+$", ioslevel):
results['msg'] = 'Could not parse ioslevel output {0}.'.format(ioslevel)
results['msg'] = f'Could not parse ioslevel output {ioslevel}.'
module.fail_json(**results)

results['ioslevel'] = ioslevel
Expand All @@ -259,7 +259,7 @@ def viosbr_backup(module, params):
results['stdout'] = stdout
results['stderr'] = stderr
if ret != 0:
results['msg'] = 'Command \'{0}\' failed with return code {1}.'.format(' '.join(cmd), ret)
results['msg'] = f"Command \'{' '.join(cmd)}\' failed with return code {ret}."
module.fail_json(**results)

if not os.path.isabs(filename):
Expand Down Expand Up @@ -301,7 +301,7 @@ def viosbr_restore(module, params):
results['stdout'] = stdout
results['stderr'] = stderr
if ret != 0:
results['msg'] = 'Command \'{0}\' failed with return code {1}.'.format(' '.join(cmd), ret)
results['msg'] = f"Command \'{' '.join(cmd)}\' failed with return code {ret}."
module.fail_json(**results)

results['changed'] = True
Expand All @@ -322,7 +322,7 @@ def viosbr_recoverdb(module, params):
results['stdout'] = stdout
results['stderr'] = stderr
if ret != 0:
results['msg'] = 'Command \'{0}\' failed with return code {1}.'.format(' '.join(cmd), ret)
results['msg'] = f"Command \'{' '.join(cmd)}\' failed with return code {ret}."
module.fail_json(**results)

results['changed'] = True
Expand All @@ -340,7 +340,7 @@ def viosbr_migrate(module, params):
results['stdout'] = stdout
results['stderr'] = stderr
if ret != 0:
results['msg'] = 'Command \'{0}\' failed with return code {1}.'.format(' '.join(cmd), ret)
results['msg'] = f"Command \'{' '.join(cmd)}\' failed with return code {ret}."
module.fail_json(**results)

results['changed'] = True
Expand Down Expand Up @@ -370,7 +370,7 @@ def viosbr_list(module, params):
results['stdout'] = stdout
results['stderr'] = stderr
if ret != 0:
results['msg'] = 'Command \'{0}\' failed with return code {1}.'.format(' '.join(cmd), ret)
results['msg'] = f"Command \'{' '.join(cmd)}\' failed with return code {ret}."
module.fail_json(**results)

def viosbr_view(module, params):
Expand All @@ -389,7 +389,7 @@ def viosbr_view(module, params):
results['stdout'] = stdout
results['stderr'] = stderr
if ret != 0:
results['msg'] = 'Command \'{0}\' failed with return code {1}.'.format(' '.join(cmd), ret)
results['msg'] = f"Command \'{' '.join(cmd)}\' failed with return code {ret}."
module.fail_json(**results)


Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/viosecure.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def security_apply(module, params):
if ret != 0:
results['stdout'] = stdout
results['stderr'] = stderr
results['msg'] = 'Could not apply security rules, return code {0}.'.format(ret)
results['msg'] = f'Could not apply security rules, return code {ret}.'
module.fail_json(**results)


Expand Down Expand Up @@ -242,7 +242,7 @@ def firewall_view(module):
if ret != 0:
results['stdout'] = stdout
results['stderr'] = stderr
results['msg'] = 'Could not retrieve {0} rules, return code {1}'.format(ip, ret)
results['msg'] = f'Could not retrieve {ip} rules, return code {ret}'
module.fail_json(**results)
# First line indicates state ON or OFF
lines = stdout.split('\n')
Expand Down Expand Up @@ -317,7 +317,7 @@ def firewall_apply(module, params):
if ret != 0:
results['stdout'] = stdout
results['stderr'] = stderr
results['msg'] = 'Could not apply rule, return code {0}.'.format(ret)
results['msg'] = f'Could not apply rule, return code {ret}.'
module.fail_json(**results)

# Check if firewall needs to be activated/deactivated
Expand All @@ -334,7 +334,7 @@ def firewall_apply(module, params):
if ret != 0:
results['stdout'] = stdout
results['stderr'] = stderr
results['msg'] = 'Could not change firewall state, return code {0}.'.format(ret)
results['msg'] = f'Could not change firewall state, return code {ret}.'
module.fail_json(**results)


Expand Down

0 comments on commit c5fc0a9

Please sign in to comment.