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

Improving UT coverage for filesystem module #123

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 26 additions & 36 deletions plugins/modules/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,40 +1177,32 @@ def check_quota_param_modification(self, quota, filesystem_quota):

def is_quota_modified(self, filesystem_quota):
"""Determines if Quota is modified"""
try:
LOG.info('Determining if Quota is modified...')
if self.module.params['quota'] is not None \
and filesystem_quota is not None and filesystem_quota[
'quotas'] and \
self.module.params['quota']['quota_state'] == 'present':
quota = self.module.params['quota']
if 'include_snap_data' in quota and \
quota['include_snap_data'] is not None:
include_snap_data = quota['include_snap_data']
if include_snap_data != \
filesystem_quota['quotas'][0]['include_snapshots']:
error_message = 'The value of include_snap_data does ' \
'not match the state on the array. ' \
'Modifying include_snap_data is ' \
'not supported.'
LOG.error(error_message)
self.module.fail_json(msg=error_message)
if THRESHOLD_PARAM in quota and \
quota[THRESHOLD_PARAM] is not None:
include_data_protection_overhead = \
quota[THRESHOLD_PARAM]
if include_data_protection_overhead != \
filesystem_quota['quotas'][0][
'thresholds_on']:
return True
self.check_quota_param_modification(quota=quota, filesystem_quota=filesystem_quota)

except Exception as e:
error_msg = self.determine_error(error_obj=e)
error_message = 'Error {0} while determining ' \
'if Quotas are modified '.format((str(error_msg)))
LOG.error(error_message)
self.module.fail_json(msg=error_message)
LOG.info('Determining if Quota is modified...')
if self.module.params['quota'] is not None \
and filesystem_quota is not None and filesystem_quota[
'quotas'] and \
self.module.params['quota']['quota_state'] == 'present':
quota = self.module.params['quota']
if 'include_snap_data' in quota and \
quota['include_snap_data'] is not None:
include_snap_data = quota['include_snap_data']
if include_snap_data != \
filesystem_quota['quotas'][0]['include_snapshots']:
error_message = 'The value of include_snap_data does ' \
'not match the state on the array. ' \
'Modifying include_snap_data is ' \
'not supported.'
LOG.error(error_message)
self.module.fail_json(msg=error_message)
if THRESHOLD_PARAM in quota and \
quota[THRESHOLD_PARAM] is not None:
include_data_protection_overhead = \
quota[THRESHOLD_PARAM]
if include_data_protection_overhead != \
filesystem_quota['quotas'][0][
'thresholds_on']:
return True
return self.check_quota_param_modification(quota=quota, filesystem_quota=filesystem_quota)

def validate_input(self, quota):
"""Valid input parameters"""
Expand Down Expand Up @@ -1316,12 +1308,10 @@ def get_owner_id(self, name, zone, provider):
def get_group_id(self, name, zone, provider):
"""Get the group account details in PowerScale"""
try:
LOG.info("Getting group details here")
resp = self.auth_api.get_auth_group(
auth_group_id='GROUP:' + name,
zone=zone, provider=provider).to_dict()

LOG.info(resp)
return resp
except Exception as e:
error_msg = self.determine_error(error_obj=e)
Expand Down
59 changes: 51 additions & 8 deletions tests/unit/plugins/module_utils/mock_filesystem_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,33 @@ class MockFileSystemApi:
'quota': None,
'state': None
}
ZONE_PATH = {
'summary': {
'path': '/ifs/sample_zone'
}
}
DATE_TIME = "Thu, 15 Jun 2023 12:20:42 GMT"
QUOTA_DETAILS_0 = {
"quotas": [
{
"thresholds": {
"advisory": 5242880,
"hard": 11534336,
"soft": 4194304
},
"include_snapshots": False
}
]
}
# "thresholds_on": "fs_logical_size",
# "soft_limit_size": 4,
# "hard_limit_size": 11,
# "advisory_limit_size": 5,
# "cap_unit": 'GB',
# "container": True,
# "quota_state": "present",
# }
# }
FILESYSTEM_DETAILS = {
"attrs": [
{
Expand Down Expand Up @@ -235,11 +261,28 @@ def get_acl_response():

@staticmethod
def get_error_responses(response_type):
if response_type == 'update_quota_exception':
return "Modification of Quota on path"
elif response_type == "create_quota_exception":
return "Creation of Quota ifs/ATest3 failed with error: None"
elif response_type == "delete_filesystem_exception":
return "Deletion of Filesystem"
elif response_type == "acl_validation_exception":
return "Please specify access_rights or inherit_flags to set ACL"
err_msg_dict = {
"update_quota_error_exception": "Modification of Quota on path",
"create_quota_exception": "Creation of Quota ifs/ATest3 failed with error: None",
"delete_filesystem_exception": "Deletion of Filesystem",
"acl_validation_exception": "Invalid path path/path, Path must start with '/'",
"get_filesystem_exception": "extensions and state are required together when file_filter_extension is mentioned.",
"get_acl_exception": "while retrieving the access control list",
"get_filesystem_snapshots_exception": "Failed to get filesystem snapshots",
"get_zone_path_exception": "Unable to fetch base path of Access Zone",
"get_quota_state_exception": "quota_state is required",
"get_cap_unit_exception": "Invalid cap_unit provided",
"invalid_path_exception": "The path provided must start with /",
"get_group_id_exception": "Failed to get the group id for group",
"get_owner_id_exception": "Failed to get the owner id",
"create_file_system_wo_owner_name_exception": "Please specify a name for the owner.",
"create_file_system_wo_group_name_exception": "Please specify a name for the group.",
"set_acl_exception": "Setting ACL rights of Filesystem",
"delete_quota_exception": "Deletion of Quota on path",
"update_quota_exception": "Creation of Quota update param failed",
"create_quota_error_exception": "Creation of Quota param failed",
"update_include_snap_data_exception": "Modifying include_snap_data is not supported",
"create_quota_get_exception": "Creation of Quota param failed",
"set_access_control_rights_exception": "Setting ACL rights of Filesystem"
}
return err_msg_dict.get(response_type)
Loading
Loading