From 54bfbd8a414c27e3a84f8c06628a058bed54d69e Mon Sep 17 00:00:00 2001 From: Christoph Fiehe Date: Thu, 20 Apr 2023 18:38:48 +0200 Subject: [PATCH] This fix ensures that in case of a project quota, the corresponding project gets initialized, if required. Signed-off-by: Christoph Fiehe --- .../5143-fix-xfs-quota-project-init.yml | 3 + plugins/modules/xfs_quota.py | 91 +++++++++++-------- .../targets/xfs_quota/tasks/pquota.yml | 2 +- 3 files changed, 59 insertions(+), 37 deletions(-) create mode 100644 changelogs/fragments/5143-fix-xfs-quota-project-init.yml diff --git a/changelogs/fragments/5143-fix-xfs-quota-project-init.yml b/changelogs/fragments/5143-fix-xfs-quota-project-init.yml new file mode 100644 index 00000000000..f577f69f772 --- /dev/null +++ b/changelogs/fragments/5143-fix-xfs-quota-project-init.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - xfs_quota - in case of a project quota, the call to ``xfs_quota`` did not initialize the project (https://github.com/ansible-collections/community.general/issues/5143). diff --git a/plugins/modules/xfs_quota.py b/plugins/modules/xfs_quota.py index d01f3dc0e68..6d05219905b 100644 --- a/plugins/modules/xfs_quota.py +++ b/plugins/modules/xfs_quota.py @@ -300,31 +300,35 @@ def main(): prj_set = False break - if not prj_set and not module.check_mode: - cmd = "project -s" - rc, stdout, stderr = exec_quota(module, xfs_quota_bin, cmd, mountpoint) - if rc != 0: - result["cmd"] = cmd - result["rc"] = rc - result["stdout"] = stdout - result["stderr"] = stderr - module.fail_json( - msg="Could not get quota realtime block report.", **result - ) + if state == "present" and not prj_set: + if not module.check_mode: + cmd = "project -s %s" % name + rc, stdout, stderr = exec_quota(module, xfs_quota_bin, cmd, mountpoint) + if rc != 0: + result["cmd"] = cmd + result["rc"] = rc + result["stdout"] = stdout + result["stderr"] = stderr + module.fail_json( + msg="Could not get quota realtime block report.", **result + ) result["changed"] = True - elif not prj_set and module.check_mode: - result["changed"] = True + elif state == "absent" and prj_set and name != quota_default: + if not module.check_mode: + cmd = "project -C %s" % name + rc, stdout, stderr = exec_quota(module, xfs_quota_bin, cmd, mountpoint) + if rc != 0: + result["cmd"] = cmd + result["rc"] = rc + result["stdout"] = stdout + result["stderr"] = stderr + module.fail_json( + msg="Failed to clear managed tree from project quota control.", **result + ) - # Set limits - if state == "absent": - bhard = 0 - bsoft = 0 - ihard = 0 - isoft = 0 - rtbhard = 0 - rtbsoft = 0 + result["changed"] = True current_bsoft, current_bhard = quota_report( module, xfs_quota_bin, mountpoint, name, quota_type, "b" @@ -336,6 +340,23 @@ def main(): module, xfs_quota_bin, mountpoint, name, quota_type, "rtb" ) + # Set limits + if state == "absent": + bhard = 0 + bsoft = 0 + ihard = 0 + isoft = 0 + rtbhard = 0 + rtbsoft = 0 + + # Ensure that a non-existing quota does not trigger a change + current_bsoft = current_bsoft if current_bsoft is not None else 0 + current_bhard = current_bhard if current_bhard is not None else 0 + current_isoft = current_isoft if current_isoft is not None else 0 + current_ihard = current_ihard if current_ihard is not None else 0 + current_rtbsoft = current_rtbsoft if current_rtbsoft is not None else 0 + current_rtbhard = current_rtbhard if current_rtbhard is not None else 0 + result["xfs_quota"] = dict( bsoft=current_bsoft, bhard=current_bhard, @@ -370,23 +391,21 @@ def main(): limit.append("rtbhard=%s" % rtbhard) result["rtbhard"] = int(rtbhard) - if len(limit) > 0 and not module.check_mode: - if name == quota_default: - cmd = "limit %s -d %s" % (type_arg, " ".join(limit)) - else: - cmd = "limit %s %s %s" % (type_arg, " ".join(limit), name) - - rc, stdout, stderr = exec_quota(module, xfs_quota_bin, cmd, mountpoint) - if rc != 0: - result["cmd"] = cmd - result["rc"] = rc - result["stdout"] = stdout - result["stderr"] = stderr - module.fail_json(msg="Could not set limits.", **result) + if len(limit) > 0: + if not module.check_mode: + if name == quota_default: + cmd = "limit %s -d %s" % (type_arg, " ".join(limit)) + else: + cmd = "limit %s %s %s" % (type_arg, " ".join(limit), name) - result["changed"] = True + rc, stdout, stderr = exec_quota(module, xfs_quota_bin, cmd, mountpoint) + if rc != 0: + result["cmd"] = cmd + result["rc"] = rc + result["stdout"] = stdout + result["stderr"] = stderr + module.fail_json(msg="Could not set limits.", **result) - elif len(limit) > 0 and module.check_mode: result["changed"] = True module.exit_json(**result) diff --git a/tests/integration/targets/xfs_quota/tasks/pquota.yml b/tests/integration/targets/xfs_quota/tasks/pquota.yml index 5053457ddb8..e0865b536f6 100644 --- a/tests/integration/targets/xfs_quota/tasks/pquota.yml +++ b/tests/integration/targets/xfs_quota/tasks/pquota.yml @@ -123,7 +123,7 @@ - name: Assert project limits results for xft_quotaval after re-apply assert: that: - - test_pquota_project_after.changed + - not test_pquota_project_after.changed - name: Reset default project limits xfs_quota: mountpoint: '{{ remote_tmp_dir }}/pquota'