Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reported AIX filesystem module incorrect fail_json() usage #58642

Merged
merged 2 commits into from
Jul 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 15 additions & 20 deletions lib/ansible/modules/system/aix_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# 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

__metaclass__ = type

ANSIBLE_METADATA = {
Expand Down Expand Up @@ -195,7 +196,7 @@ def _fs_exists(module, filesystem):
return False

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:

Expand All @@ -215,7 +216,7 @@ def _check_nfs_device(module, nfs_host, device):
rc, showmount_out, err = module.run_command(
"%s -a %s" % (showmount_cmd, nfs_host))
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:
showmount_data = showmount_out.splitlines()
for line in showmount_data:
Expand Down Expand Up @@ -263,17 +264,13 @@ def resize_fs(module, filesystem, size):

if rc == 28:
changed = False

return changed, chfs_out

elif rc != 0:
if re.findall('Maximum allocation for logical', err):
changed = False

return changed, err

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:
if re.findall('The filesystem size is already', chfs_out):
Expand Down Expand Up @@ -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"' % (
mknfsmnt_cmd, filesystem, device, nfs_server, permissions, auto_mount))
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:
changed = True
msg = "NFS file system %s created." % filesystem
Expand All @@ -367,17 +364,17 @@ def create_fs(
# Creates a LVM file system.
crfs_cmd = module.get_bin_path('crfs', True)
if not module.check_mode:
rc, crfs_out, err = module.run_command(
"%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))
cmd = "%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)
rc, crfs_out, err = module.run_command(cmd)

if rc == 10:
module.exit_json(
msg="Using a existent previously defined logical volume, "
"volume group needs to be empty. %s" % err)

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:
changed = True
Expand All @@ -402,9 +399,10 @@ def remove_fs(module, filesystem, rm_mount_point):

rmfs_cmd = module.get_bin_path('rmfs', True)
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:
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:
changed = True
msg = rmfs_out
Expand All @@ -427,7 +425,7 @@ def mount_fs(module, filesystem):
rc, mount_out, err = module.run_command(
"%s %s" % (mount_cmd, filesystem))
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:
changed = True
msg = "File system %s mounted." % filesystem
Expand All @@ -447,7 +445,7 @@ def unmount_fs(module, filesystem):
if not module.check_mode:
rc, unmount_out, err = module.run_command("%s %s" % (unmount_cmd, filesystem))
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:
changed = True
msg = "File system %s unmounted." % filesystem
Expand Down Expand Up @@ -518,9 +516,7 @@ def main():
if nfs_server is not None:
if device is None:
result['msg'] = 'Parameter "device" is required when "nfs_server" is defined.'

module.fail_json(**result)

else:
# Create a fs from NFS export.
if _check_nfs_device(module, nfs_server, device):
Expand All @@ -529,9 +525,8 @@ def main():

if device is None:
if vg is None:

result['msg'] = 'Required parameter "device" and/or "vg" is missing for filesystem creation.'
module.fail_json(**result)

else:
# Create a fs from
result['changed'], result['msg'] = create_fs(
Expand Down