Skip to content

Commit

Permalink
Fixed pylint issues (#44)
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]>

* Fixed pylint issues

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

* Fixed pylint issues

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

* Fixed flake8 issues

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

---------

Signed-off-by: schamola <[email protected]>
  • Loading branch information
schamola authored Nov 24, 2023
1 parent 8dce303 commit 1368299
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
56 changes: 26 additions & 30 deletions plugins/modules/alt_root_vg.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_pvs(module):
if ret != 0:
results['stdout'] = stdout
results['stderr'] = stderr
results['msg'] = 'Command \'{0}\' failed with return code {1}.'.format(' '.join(cmd), ret)
results['msg'] = f"Command \'{' '.join(cmd)}\' failed with return code {ret}."
return None

# NAME PVID VG STATUS
Expand All @@ -126,8 +126,8 @@ def get_pvs(module):
pvs[match_key.group(1)]['status'] = match_key.group(4)

module.debug('List of PVs:')
for key in pvs.keys():
module.debug(' pvs[{0}]: {1}'.format(key, pvs[key]))
for item in pvs.items():
module.debug(f' pvs[{item[0]}]: {item[1]}')

return pvs

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

# NAME PVID SIZE(megabytes)
Expand All @@ -159,8 +159,8 @@ def get_free_pvs(module):
free_pvs[match_key.group(1)]['size'] = int(match_key.group(3))

module.debug('List of available PVs:')
for key in free_pvs.keys():
module.debug(' free_pvs[{0}]: {1}'.format(key, free_pvs[key]))
for item in free_pvs.items():
module.debug(f' free_pvs[{item[0]}]: {item[1]}')

return free_pvs

Expand Down Expand Up @@ -191,7 +191,7 @@ def find_valid_altdisk(module, hdisks, rootvg_info, disk_size_policy, force):
break
if found_altdisk:
if not force:
results['msg'] = 'An alternate disk already exists on disk {0}'.format(found_altdisk)
results['msg'] = f'An alternate disk already exists on disk {found_altdisk}'
module.fail_json(**results)
# Clean existing altinst_rootvg
module.log('Removing altinst_rootvg')
Expand All @@ -201,21 +201,21 @@ def find_valid_altdisk(module, hdisks, rootvg_info, disk_size_policy, force):
if ret != 0:
results['stdout'] = stdout
results['stderr'] = stderr
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

for pv in pvs:
if pvs[pv]['vg'] == 'altinst_rootvg':
module.log('Clearing the owning VG from disk {0}'.format(pv))
module.log(f'Clearing the owning VG from disk {pv}')

cmd = ['/usr/sbin/chpv', '-C', pv]
ret, stdout, stderr = module.run_command(cmd)
if ret != 0:
results['stdout'] = stdout
results['stderr'] = stderr
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)

pvs = get_free_pvs(module)
Expand Down Expand Up @@ -281,21 +281,19 @@ def find_valid_altdisk(module, hdisks, rootvg_info, disk_size_policy, force):
# Best Can Do...
selected_disk = prev_disk
else:
results['msg'] = 'No available alternate disk with size greater than {0} MB'\
' found'.format(rootvg_size)
results['msg'] = f'No available alternate disk with size greater than {rootvg_size} MB'\
' found'
module.fail_json(**results)

module.debug('Selected disk is {0} (select mode: {1})'
.format(selected_disk, disk_size_policy))
module.debug(f'Selected disk is {selected_disk} (select mode: {disk_size_policy})')
hdisks.append(selected_disk)

# hdisks specified by the user
else:
tot_size = 0
for hdisk in hdisks:
if hdisk not in pvs:
results['msg'] = 'Alternate disk {0} is either not found or not available'\
.format(hdisk)
results['msg'] = f'Alternate disk {hdisk} is either not found or not available'
module.fail_json(**results)
tot_size += pvs[hdisk]['size']

Expand All @@ -304,8 +302,7 @@ def find_valid_altdisk(module, hdisks, rootvg_info, disk_size_policy, force):
if tot_size >= used_size:
module.log('[WARNING] Alternate disks smaller than the current rootvg.')
else:
results['msg'] = 'Alternate disks too small ({0} < {1}).'\
.format(tot_size, rootvg_size)
results['msg'] = f'Alternate disks too small ({tot_size} < {rootvg_size}).'
module.fail_json(**results)


Expand Down Expand Up @@ -338,7 +335,7 @@ def check_rootvg(module):
if ret != 0:
results['stdout'] = stdout
results['stderr'] = stderr
results['msg'] = 'Command \'{0}\' failed with return code {1}.'.format(' '.join(cmd), ret)
results['msg'] = f"Command \'{' '.join(cmd)}\' failed with return code {ret}."
return None

# parse lsvg output to get the size in megabytes:
Expand Down Expand Up @@ -397,7 +394,7 @@ def alt_disk_copy(module, hdisks, disk_size_policy, force):
hdisks = []
find_valid_altdisk(module, hdisks, rootvg_info, disk_size_policy, force)

module.log('Using {0} as alternate disks'.format(hdisks))
module.log(f'Using {hdisks} as alternate disks')

# alt_root_vg
cmd = [ioscli_cmd, 'alt_root_vg', '-target', ' '.join(hdisks)]
Expand All @@ -408,7 +405,7 @@ def alt_disk_copy(module, hdisks, disk_size_policy, force):

if ret != 0:
# an error occured during alt_root_vg
results['msg'] = 'Failed to copy {0}: return code {1}.'.format(' '.join(hdisks), ret)
results['msg'] = f"Failed to copy {' '.join(hdisks)}: return code {ret}."
module.fail_json(**results)
results['changed'] = True

Expand All @@ -429,15 +426,14 @@ def alt_disk_clean(module, hdisks):
# Check that all specified disks exist and belong to altinst_rootvg
for hdisk in hdisks:
if (hdisk not in pvs) or (pvs[hdisk]['vg'] != 'altinst_rootvg'):
results['msg'] = 'Specified disk {0} is not an alternate install rootvg'\
.format(hdisk)
results['msg'] = f'Specified disk {hdisk} is not an alternate install rootvg'
module.fail_json(**results)
else:
# Retrieve the list of disks that belong to altinst_rootvg
hdisks = []
for pv in pvs.keys():
if pvs[pv]['vg'] == 'altinst_rootvg':
hdisks.append(pv)
for pv in pvs.items():
if pv[1]['vg'] == 'altinst_rootvg':
hdisks.append(pv[0])
if not hdisks:
# Do not fail if there is no altinst_rootvg to preserve idempotency
return
Expand All @@ -451,19 +447,19 @@ def alt_disk_clean(module, hdisks):
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)

# Clears the owning VG from the disks
for hdisk in hdisks:
module.log('Clearing the owning VG from disk {0}'.format(hdisk))
module.log(f'Clearing the owning VG from disk {hdisk}')

cmd = ['/usr/sbin/chpv', '-C', hdisk]
ret, stdout, stderr = module.run_command(cmd)
if ret != 0:
results['stdout'] = stdout
results['stderr'] = stderr
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 @@ -503,7 +499,7 @@ def main():
else:
alt_disk_clean(module, targets)

results['msg'] = 'alt_root_vg {0} operation completed successfully'.format(action)
results['msg'] = f'alt_root_vg {action} operation completed successfully'
module.exit_json(**results)


Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/backupios.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,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 @@ -154,7 +154,7 @@ def main():
cmd += ['-mksysb']
if params['nopack']:
# Create exclude file from exclude list
with open('/etc/exclude_packing.rootvg', 'w+') as f:
with open('/etc/exclude_packing.rootvg', 'w+', encoding="utf-8") as f:
f.writelines(line + '\n' for line in params['nopack'])
cmd += ['-nopak']
if not params['savevgstruct']:
Expand All @@ -166,7 +166,7 @@ def main():
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
1 change: 1 addition & 0 deletions plugins/modules/mapping_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@
stderr='',
)


def vscsi_mappings(module, mappings):
"""
Retrieve VSCSI mappings.
Expand Down
1 change: 1 addition & 0 deletions plugins/modules/viosbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ def viosbr_list(module, params):
results['msg'] = f"Command \'{' '.join(cmd)}\' failed with return code {ret}."
module.fail_json(**results)


def viosbr_view(module, params):
"""
Displays information for a user-specified backup file
Expand Down

0 comments on commit 1368299

Please sign in to comment.