Skip to content

Commit

Permalink
Fixed pylint issues for some modules (#43)
Browse files Browse the repository at this point in the history
* Added fix download module

It will allow the user to download fixes from EFD portal.

Signed-off-by: schamola <[email protected]>

* Minor changes in fix download

Signed-off-by: schamola <[email protected]>

* Modified it for using round

Signed-off-by: schamola <[email protected]>

* Added playbook for End-to-end updation of VIOS

This will allow users to automate the whole process of updation of VIOS (Downloading fix and updation)

Signed-off-by: schamola <[email protected]>

* Added playbook for viosbr and end-to-end updation

Signed-off-by: schamola <[email protected]>

* Fixed pylint issues for some modules

Signed-off-by: schamola <[email protected]>

* Modified for pylint issues and documentation

Signed-off-by: schamola <[email protected]>

---------

Signed-off-by: schamola <[email protected]>
  • Loading branch information
schamola authored Nov 24, 2023
1 parent b402547 commit 8dce303
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 35 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
50 changes: 42 additions & 8 deletions plugins/modules/mapping_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,13 @@

ioscli_cmd = '/usr/ios/cli/ioscli'
delimiter = ',' # Delimiter to use for lsmap -fmt

results = dict(
changed=False,
cmd='',
msg='',
stdout='',
stderr='',
)

def vscsi_mappings(module, mappings):
"""
Expand All @@ -594,7 +600,11 @@ 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)

results['msg'] = f'lsmap failed rc={ret}'
results['stdout'] = stdout
results['stderr'] = stderr
module.fail_json(**results)

# List of fields returned by lsmap:
# svsa:physloc:clientid(:vtd:status:lun:backing:bdphysloc:mirrored)+
Expand Down Expand Up @@ -647,7 +657,11 @@ 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)

results['msg'] = f'lsmap failed rc={ret}'
results['stdout'] = stdout
results['stderr'] = stderr
module.fail_json(**results)

# 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 +711,11 @@ 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)

results['msg'] = f'lsmap failed rc={ret}'
results['stdout'] = stdout
results['stderr'] = stderr
module.fail_json(**results)

# List of fields returned by lsmap -net:
# svea:physloc:sea:backing:status:bdphysloc
Expand Down Expand Up @@ -743,7 +761,11 @@ 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)

results['msg'] = f'lsmap failed rc={ret}'
results['stdout'] = stdout
results['stderr'] = stderr
module.fail_json(**results)

# List of fields returned by lsmap -vnic:
# name:physloc:clntid:clntname:clntos:backing:status:bdphysloc:clntdev:clntphysloc
Expand Down Expand Up @@ -791,7 +813,11 @@ 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)

results['msg'] = f'lsmap failed rc={ret}'
results['stdout'] = stdout
results['stderr'] = stderr
module.fail_json(**results)

# List of fields returned by lsmap -ams:
# paging:streamid:clientid:status:redundancy:backing:poolid:vasi:pager:vbsd
Expand Down Expand Up @@ -839,7 +865,11 @@ 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)

results['msg'] = f'lsmap failed rc={ret}'
results['stdout'] = stdout
results['stderr'] = stderr
module.fail_json(**results)

# List of fields returned by lsmap -suspend:
# svsa:state:clientname:streamid:clientid(:vtd:status:lun:backing:bdphysloc:mirrored)+
Expand Down Expand Up @@ -903,7 +933,11 @@ 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)

results['msg'] = f'lsmap failed rc={ret}'
results['stdout'] = stdout
results['stderr'] = stderr
module.fail_json(**results)

# List of fields returned by lsmap -clustername:
# physloc:clientid:vtd:lun:backing
Expand Down
9 changes: 5 additions & 4 deletions plugins/modules/updateios.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
notes:
- A fix pack or service pack cannot be applied if the VIOS partition is part
of a shared storage pool and the cluster node state is UP.
- remove_outdated_filesets action is supported from VIOS version 3.1.2.40 onwards
'''

EXAMPLES = r'''
Expand Down Expand Up @@ -151,13 +152,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 +234,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 8dce303

Please sign in to comment.