Fix reported AIX filesystem module incorrect fail_json() usage (#58642)
* Fix reported AIX filesystem module incorrect fail_json() usage and extend reporting on an error. Fixes #58609 * pep8 and ansible-test fixes, as well one missed msg param
This commit is contained in:
parent
adea964c3e
commit
75724bb7ca
1 changed files with 15 additions and 20 deletions
|
@ -5,6 +5,7 @@
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
ANSIBLE_METADATA = {
|
ANSIBLE_METADATA = {
|
||||||
|
@ -195,7 +196,7 @@ def _fs_exists(module, filesystem):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg="Failed to run lsfs.", rc=rc, err=err)
|
module.fail_json(msg="Failed to run lsfs. Error message: %s" % err)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
@ -215,7 +216,7 @@ def _check_nfs_device(module, nfs_host, device):
|
||||||
rc, showmount_out, err = module.run_command(
|
rc, showmount_out, err = module.run_command(
|
||||||
"%s -a %s" % (showmount_cmd, nfs_host))
|
"%s -a %s" % (showmount_cmd, nfs_host))
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
module.fail_json(msg="Failed to run showmount.", rc=rc, err=err)
|
module.fail_json(msg="Failed to run showmount. Error message: %s" % err)
|
||||||
else:
|
else:
|
||||||
showmount_data = showmount_out.splitlines()
|
showmount_data = showmount_out.splitlines()
|
||||||
for line in showmount_data:
|
for line in showmount_data:
|
||||||
|
@ -263,17 +264,13 @@ def resize_fs(module, filesystem, size):
|
||||||
|
|
||||||
if rc == 28:
|
if rc == 28:
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
return changed, chfs_out
|
return changed, chfs_out
|
||||||
|
|
||||||
elif rc != 0:
|
elif rc != 0:
|
||||||
if re.findall('Maximum allocation for logical', err):
|
if re.findall('Maximum allocation for logical', err):
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
return changed, err
|
return changed, err
|
||||||
|
|
||||||
else:
|
else:
|
||||||
module.fail_json("Failed to run chfs.", rc=rc, err=err)
|
module.fail_json(msg="Failed to run chfs. Error message: %s" % err)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if re.findall('The filesystem size is already', chfs_out):
|
if re.findall('The filesystem size is already', chfs_out):
|
||||||
|
@ -351,7 +348,7 @@ def create_fs(
|
||||||
rc, mknfsmnt_out, err = module.run_command('%s -f "%s" %s -h "%s" -t "%s" "%s" -w "bg"' % (
|
rc, mknfsmnt_out, err = module.run_command('%s -f "%s" %s -h "%s" -t "%s" "%s" -w "bg"' % (
|
||||||
mknfsmnt_cmd, filesystem, device, nfs_server, permissions, auto_mount))
|
mknfsmnt_cmd, filesystem, device, nfs_server, permissions, auto_mount))
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
module.fail_json(msg="Failed to run mknfsmnt.", rc=rc, err=err)
|
module.fail_json(msg="Failed to run mknfsmnt. Error message: %s" % err)
|
||||||
else:
|
else:
|
||||||
changed = True
|
changed = True
|
||||||
msg = "NFS file system %s created." % filesystem
|
msg = "NFS file system %s created." % filesystem
|
||||||
|
@ -367,9 +364,9 @@ def create_fs(
|
||||||
# Creates a LVM file system.
|
# Creates a LVM file system.
|
||||||
crfs_cmd = module.get_bin_path('crfs', True)
|
crfs_cmd = module.get_bin_path('crfs', True)
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
rc, crfs_out, err = module.run_command(
|
cmd = "%s -v %s -m %s %s %s %s %s %s -p %s %s -a %s" % (
|
||||||
"%s -v %s -m %s %s %s %s %s %s -p %s %s -a %s" % (
|
crfs_cmd, fs_type, filesystem, vg, device, mount_group, auto_mount, account_subsystem, permissions, size, attributes)
|
||||||
crfs_cmd, fs_type, filesystem, vg, device, mount_group, auto_mount, account_subsystem, permissions, size, attributes))
|
rc, crfs_out, err = module.run_command(cmd)
|
||||||
|
|
||||||
if rc == 10:
|
if rc == 10:
|
||||||
module.exit_json(
|
module.exit_json(
|
||||||
|
@ -377,7 +374,7 @@ def create_fs(
|
||||||
"volume group needs to be empty. %s" % err)
|
"volume group needs to be empty. %s" % err)
|
||||||
|
|
||||||
elif rc != 0:
|
elif rc != 0:
|
||||||
module.fail_json(msg="Failed to run crfs.", rc=rc, err=err)
|
module.fail_json(msg="Failed to run %s. Error message: %s" % (cmd, err))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
changed = True
|
changed = True
|
||||||
|
@ -402,9 +399,10 @@ def remove_fs(module, filesystem, rm_mount_point):
|
||||||
|
|
||||||
rmfs_cmd = module.get_bin_path('rmfs', True)
|
rmfs_cmd = module.get_bin_path('rmfs', True)
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
rc, rmfs_out, err = module.run_command("%s -r %s %s" % (rmfs_cmd, rm_mount_point, filesystem))
|
cmd = "%s -r %s %s" % (rmfs_cmd, rm_mount_point, filesystem)
|
||||||
|
rc, rmfs_out, err = module.run_command(cmd)
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
module.fail_json(msg="Failed to run rmfs.", rc=rc, err=err)
|
module.fail_json(msg="Failed to run %s. Error message: %s" % (cmd, err))
|
||||||
else:
|
else:
|
||||||
changed = True
|
changed = True
|
||||||
msg = rmfs_out
|
msg = rmfs_out
|
||||||
|
@ -427,7 +425,7 @@ def mount_fs(module, filesystem):
|
||||||
rc, mount_out, err = module.run_command(
|
rc, mount_out, err = module.run_command(
|
||||||
"%s %s" % (mount_cmd, filesystem))
|
"%s %s" % (mount_cmd, filesystem))
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
module.fail_json("Failed to run mount.", rc=rc, err=err)
|
module.fail_json(msg="Failed to run mount. Error message: %s" % err)
|
||||||
else:
|
else:
|
||||||
changed = True
|
changed = True
|
||||||
msg = "File system %s mounted." % filesystem
|
msg = "File system %s mounted." % filesystem
|
||||||
|
@ -447,7 +445,7 @@ def unmount_fs(module, filesystem):
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
rc, unmount_out, err = module.run_command("%s %s" % (unmount_cmd, filesystem))
|
rc, unmount_out, err = module.run_command("%s %s" % (unmount_cmd, filesystem))
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
module.fail_json("Failed to run unmount.", rc=rc, err=err)
|
module.fail_json(msg="Failed to run unmount. Error message: %s" % err)
|
||||||
else:
|
else:
|
||||||
changed = True
|
changed = True
|
||||||
msg = "File system %s unmounted." % filesystem
|
msg = "File system %s unmounted." % filesystem
|
||||||
|
@ -518,9 +516,7 @@ def main():
|
||||||
if nfs_server is not None:
|
if nfs_server is not None:
|
||||||
if device is None:
|
if device is None:
|
||||||
result['msg'] = 'Parameter "device" is required when "nfs_server" is defined.'
|
result['msg'] = 'Parameter "device" is required when "nfs_server" is defined.'
|
||||||
|
|
||||||
module.fail_json(**result)
|
module.fail_json(**result)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Create a fs from NFS export.
|
# Create a fs from NFS export.
|
||||||
if _check_nfs_device(module, nfs_server, device):
|
if _check_nfs_device(module, nfs_server, device):
|
||||||
|
@ -529,9 +525,8 @@ def main():
|
||||||
|
|
||||||
if device is None:
|
if device is None:
|
||||||
if vg is None:
|
if vg is None:
|
||||||
|
result['msg'] = 'Required parameter "device" and/or "vg" is missing for filesystem creation.'
|
||||||
module.fail_json(**result)
|
module.fail_json(**result)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Create a fs from
|
# Create a fs from
|
||||||
result['changed'], result['msg'] = create_fs(
|
result['changed'], result['msg'] = create_fs(
|
||||||
|
|
Loading…
Reference in a new issue