Skip to content

Commit f402b1b

Browse files
committed
Mock the actual behavior of fail_json
Ansible faile_json will call sys.exit, then abort the execution, but currently we use FailJsonException to mock fail_json, that it cannot abort the execution. Now mock fail_json to throw SystemExit to align with Ansible behavior. All UTs are updated to extend PowerScaleUnitBase.
1 parent b7de8d3 commit f402b1b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4144
-4140
lines changed

plugins/modules/synciqpolicy.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -550,17 +550,16 @@ def get_synciq_policy_details(self, policy_name, policy_id, job_params=None):
550550
if policy:
551551
return policy[0], False
552552
return None, False
553-
554-
except utils.ApiException as e:
555-
if str(e.status) == "404":
553+
except (utils.ApiException, Exception) as e:
554+
if isinstance(e, utils.ApiException) and str(e.status) == "404":
556555
LOG.info("SyncIQ policy %s is not found", name_or_id)
557556
return self.get_synciq_target_policy(name_or_id, job_params)
558-
except Exception as e:
559-
error_msg = utils.determine_error(error_obj=e)
560-
error_message = 'Get details of SyncIQ policy %s failed with ' \
561-
'error : %s' % (name_or_id, str(error_msg))
562-
LOG.error(error_message)
563-
self.module.fail_json(msg=error_message)
557+
else:
558+
error_msg = utils.determine_error(error_obj=e)
559+
error_message = 'Get details of SyncIQ policy %s failed with ' \
560+
'error : %s' % (name_or_id, str(error_msg))
561+
LOG.error(error_message)
562+
self.module.fail_json(msg=error_message)
564563

565564
def get_synciq_target_policy(self, policy_id, job_params):
566565
""" Returns details of target syncIQ policy"""

tests/unit/plugins/module_utils/mock_fail_json.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/unit/plugins/module_utils/mock_filepoolpolicy_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def get_storage_tiers_response():
315315
tiers_list = MagicMock()
316316
tiers_list.tiers = MagicMock()
317317
tier_one = MagicMock()
318-
tier_one.name = 'test_ansible_neo_tier'
318+
tier_one.name = 'esa_tier'
319319
tier_one.lnns = [1, 2, 3]
320320
tiers_list.tiers = [tier_one]
321321
return tiers_list

tests/unit/plugins/module_utils/mock_filesystem_api.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,12 @@ def get_error_responses(response_type):
265265
"404_exception": "status is 404",
266266
"get_filesystem_exception": "Failed to get details of Filesystem",
267267
"update_quota_error_exception": "Modification of Quota on path",
268-
"create_quota_exception": "Creation of Quota ifs/ATest3 failed with error: None",
268+
"create_quota_exception": "Creation of Quota ifs/ATest3 failed with error:",
269269
"delete_filesystem_exception": "Deletion of Filesystem",
270-
"acl_validation_exception": "Invalid path path/path, Path must start with '/'",
270+
"delete_file_system_with_export_exception": "The Filesystem path ifs/ATest3 has NFS exports. Hence, deleting this directory is not safe",
271+
"acl_validation_exception": "Please specify access_rights or inherit_flags to set ACL",
271272
"get_acl_exception": "while retrieving the access control list",
273+
"get_acl_object_exception": "Error SDK Error message while retrieving ACL object instance",
272274
"get_filesystem_snapshots_exception": "Failed to get filesystem snapshots",
273275
"get_zone_path_exception": "Unable to fetch base path of Access Zone",
274276
"get_quota_state_exception": "quota_state is required",
@@ -278,17 +280,24 @@ def get_error_responses(response_type):
278280
"get_owner_id_exception": "Failed to get the owner id",
279281
"modify_owner_exception": "Failed to modify owner due to error",
280282
"modify_group_exception": "Failed to modify group due to error",
283+
"create_file_system_exception": "Creation of Filesystem ifs/ATest3 failed",
284+
"create_file_system_wo_owner_exception": "owner is required while creating Filesystem",
281285
"create_file_system_wo_owner_name_exception": "Please specify a name for the owner.",
282286
"create_file_system_wo_group_name_exception": "Please specify a name for the group.",
287+
"create_file_system_with_access_control_rights_exception": "Failed to get the wellknown id for wellknown",
283288
"set_acl_exception": "Setting ACL rights of Filesystem",
284-
"modify_acl_exception": "Modification of ACL on path",
289+
"modify_acl_exception": "Setting ACL rights of Filesystem",
290+
"modify_acl_posix_exception": "Modification of ACL",
285291
"check_acl_modified_exception": "determining if ACLs are modified",
286292
"invalid_wellknown_exception": "Provide valid wellknown",
287293
"delete_quota_exception": "Deletion of Quota on path",
288294
"update_quota_exception": "Modification of Quota on path",
289295
"create_quota_error_exception": "Creation of Quota",
296+
"get_quota_update_param_exception": "Creation of Quota update param failed with error",
290297
"update_include_snap_data_exception": "Modifying include_snap_data is not supported",
291298
"create_quota_get_exception": "Creation of Quota",
292-
"set_access_control_rights_exception": "Setting ACL rights of Filesystem"
299+
"set_access_control_rights_exception": "Setting ACL rights of Filesystem",
300+
"is_owner_modified_exception": "Failed to determine if owner is modified",
301+
"is_group_modified_exception": "Failed to determine if group is modified"
293302
}
294303
return err_msg_dict.get(response_type)

tests/unit/plugins/module_utils/mock_nfs_alias_api.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,19 @@ def create_nfs_alias_failed_msg():
2929

3030
def modify_nfs_alias_failed_msg():
3131
return 'failed with error:'
32+
33+
34+
def space_in_nfs_alias_name_msg():
35+
return 'Spaces are not allowed in NFS alias name. Provide a valid nfs_alias_name'
36+
37+
38+
def empty_nfs_alias_name_msg():
39+
return 'Provide a valid NFS alias name'
40+
41+
42+
def get_nfs_alias_failure_msg():
43+
return 'Get details of NFS alias with name:/test_alias_1 failed with error'
44+
45+
46+
def new_alias_name_when_creation_msg():
47+
return 'new_alias_name should not be provided during the creation of an NFS alias'

tests/unit/plugins/module_utils/mock_nfs_export_api.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright: (c) 2022-2024, Dell Technologies
1+
# Copyright: (c) 2023-2024, Dell Technologies
22

33
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
44

@@ -117,27 +117,27 @@
117117
"snapshot": None,
118118
"zone": SYS_ZONE},
119119
{
120-
"all_dirs": False,
121-
"block_size": 8192,
122-
"case_insensitive": False,
123-
"case_preserving": True,
124-
"clients": [
125-
SAMPLE_IP1
126-
],
127-
"description": "description",
128-
"id": NFS_ID_2,
129-
"name_max_size": 255,
130-
"paths": [PATH_1],
131-
"read_only": False,
132-
"read_only_clients": [],
133-
"read_write_clients": [],
134-
"readdirplus": True,
135-
"root_clients": [],
136-
"security_flavors": [
137-
"krb5"
138-
],
139-
"snapshot": None,
140-
"zone": SYS_ZONE}],
120+
"all_dirs": False,
121+
"block_size": 8192,
122+
"case_insensitive": False,
123+
"case_preserving": True,
124+
"clients": [
125+
SAMPLE_IP1
126+
],
127+
"description": "description",
128+
"id": NFS_ID_2,
129+
"name_max_size": 255,
130+
"paths": [PATH_1],
131+
"read_only": False,
132+
"read_only_clients": [],
133+
"read_write_clients": [],
134+
"readdirplus": True,
135+
"root_clients": [],
136+
"security_flavors": [
137+
"krb5"
138+
],
139+
"snapshot": None,
140+
"zone": SYS_ZONE}],
141141
"total": 2}
142142

143143
NFS_2 = {"exports": [{
@@ -220,8 +220,8 @@ def get_nfs_failed_msg():
220220
return 'Got error SDK Error message while getting NFS export details for path'
221221

222222

223-
def get_multiple_nfs_failed_msg():
224-
return 'Multiple NFS Exports found'
223+
def get_nfs_non_zone_failed_msg():
224+
return 'Unable to fetch base path of Access Zone'
225225

226226

227227
def create_nfs_failed_msg():

tests/unit/plugins/module_utils/mock_node_api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ def api_exception_msg():
4141

4242
def invalid_node_msg():
4343
return 'Please provide a valid Node Id'
44+
45+
46+
def disallow_delete_node_msg():
47+
return 'Deletion of node is not allowed through Ansible module'

tests/unit/plugins/module_utils/mock_s3_bucket_api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ def get_error_responses(response_type):
176176
return "Failed to get the group id for group wheel in zone " \
177177
"sample-zone and provider local due to error SDK Error message"
178178
elif response_type == "wellknown_exception":
179-
return "Failed to get the wellknown id for wellknown wheel due to" \
180-
" error Wellknown wheel does not exist. Provide valid wellknown"
179+
return "Wellknown wheel does not exist. Provide valid wellknown"
181180
elif response_type == "modify_path":
182181
return "path of the S3 bucket is not modifiable after creation."
183182
elif response_type == "modify_owner":

tests/unit/plugins/module_utils/mock_smartquota_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,17 @@ def get_group_sid():
6565

6666
@staticmethod
6767
def smartquota_create_quota_response(path):
68-
return "Create quota for" + path + "failed with"
68+
return "Create quota for " + path + " failed with"
6969

7070
@staticmethod
7171
def smartquota_delete_quota_response(path):
72-
return "Delete quota for" + path + "failed with"
72+
return "Delete quota for " + path + " failed with"
7373

7474
@staticmethod
7575
def smartquota_get_sid_exception(name, az, provider):
7676
return "Failed to get " + name + \
77-
"details for AccessZone:" + az + "and Provider:" + provider + \
78-
"with error"
77+
" details for AccessZone:" + az + " and Provider:" + provider + \
78+
" with error"
7979

8080
@staticmethod
8181
def get_smartquota_dependent_response(response_type):

tests/unit/plugins/module_utils/mock_smb_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,6 @@ def get_smb_exception_response(response_type):
178178
'modify_path_err': "Modifying path for a SMB Share is not allowed through Ansible Module",
179179
'sid_err': "Failed to get the user details for root in zone None and provider None due to error",
180180
'smb_parm_err': "Failed to get SMB params from details",
181-
'wellknown_err': "Failed to get the wellknown id for wellknown root"
181+
'wellknown_err': "Wellknown root does not exist. Provide valid wellknown"
182182
}
183183
return err_msg_dict.get(response_type)

0 commit comments

Comments
 (0)