Debian Codegraph @

ansible_collections/dellemc/powerflex/tests/unit/plugins/module_utils/mock_device_api.py

raw symbols SCIP
1 # Copyright: (c) 2023, Dell Technologies
2
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 """
6 Mock Api response for Unit tests of Device module on Dell Technologies (Dell) PowerFlex
7 """
8
9 from __future__ import (absolute_import, division, print_function)
10
11 __metaclass__ = type
12
13
14 class MockDeviceApi:
15 MODULE_UTILS_PATH = "ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell.utils"
16
17 DEVICE_NAME_1 = "ansible_device_1"
18 DEVICE_ID_1 = "3fef781c00080000"
19 PD_ID_1 = "4eeb305100000001"
20 PD_NAME_1 = "domain1"
21 SDS_ID_1 = "6af03fc500000008"
22 SDS_NAME_1 = "ansible_sds_1"
23 SP_ID_1 = "7644c68600000008"
24 SP_NAME_1 = "ansible_sp_1"
25 PATH_1 = "/dev/sdb"
26
27 DEVICE_COMMON_ARGS = {
28 "hostname": "**.***.**.***",
29 "current_pathname": None,
30 "device_id": None,
31 "device_name": None,
32 "sds_name": None,
33 "sds_id": None,
34 "storage_pool_name": None,
35 "storage_pool_id": None,
36 "acceleration_pool_name": None,
37 "acceleration_pool_id": None,
38 "protection_domain_name": None,
39 "protection_domain_id": None,
40 "external_acceleration_type": None,
41 "media_type": None,
42 "state": None
43 }
44
45 DEVICE_GET_LIST = [
46 {
47 "accelerationPoolId": SP_ID_1,
48 "accelerationPoolName": SP_NAME_1,
49 "autoDetectMediaType": "Unknown",
50 "capacityLimitInKb": 124718080,
51 "deviceCurrentPathName": PATH_1,
52 "deviceOriginalPathName": PATH_1,
53 "externalAccelerationType": "ReadAndWrite",
54 "fglNvdimmWriteCacheSize": 16,
55 "id": DEVICE_ID_1,
56 "mediaType": "HDD",
57 "name": DEVICE_NAME_1,
58 "protectionDomainId": PD_ID_1,
59 "protectionDomainName": PD_NAME_1,
60 "sdsId": SDS_ID_1,
61 "sdsName": SDS_NAME_1,
62 "spSdsId": "bfe791ff00080000",
63 "storagePoolId": SP_ID_1,
64 "storagePoolName": SP_NAME_1
65 }
66 ]
67 SDS_DETAILS_1 = [
68 {
69 "name": SDS_NAME_1,
70 "id": SDS_ID_1
71 }
72 ]
73 PD_DETAILS_1 = [
74 {
75 "name": PD_NAME_1,
76 "id": PD_ID_1
77 }
78 ]
79 SP_DETAILS_1 = [
80 {
81 "name": SP_NAME_1,
82 "protectionDomainId": PD_ID_1,
83 "id": SP_ID_1
84 }
85 ]
86 AP_DETAILS_1 = [
87 {
88 "name": SP_NAME_1,
89 "protectionDomainId": PD_ID_1,
90 "id": SP_ID_1
91 }
92 ]
93
94 @staticmethod
95 def get_device_exception_response(response_type):
96 if response_type == 'get_dev_without_SDS':
97 return "sds_name or sds_id is mandatory along with device_name. Please enter a valid value"
98 elif response_type == 'get_device_details_without_path':
99 return "sds_name or sds_id is mandatory along with current_pathname. Please enter a valid value"
100 elif response_type == 'get_device_exception':
101 return "Failed to get the device with error"
102 elif response_type == 'create_id_exception':
103 return "Addition of device is allowed using device_name only, device_id given."
104 elif response_type == 'empty_path':
105 return "Please enter a valid value for current_pathname"
106 elif response_type == 'empty_device_name':
107 return "Please enter a valid value for device_name."
108 elif response_type == 'empty_sds':
109 return "Please enter a valid value for "
110 elif response_type == 'empty_dev_id':
111 return "Please provide valid device_id value to identify a device"
112 elif response_type == 'space_in_name':
113 return "current_pathname or device_name is mandatory along with sds"
114 elif response_type == 'with_required_params':
115 return "Please specify a valid parameter combination to identify a device"
116
117 @staticmethod
118 def get_device_exception_response1(response_type):
119 if response_type == 'modify_exception':
120 return "Modification of device attributes is currently not supported by Ansible modules."
121 elif response_type == 'delete_exception':
122 return f"Remove device '{MockDeviceApi.DEVICE_ID_1}' operation failed with error"
123 elif response_type == 'sds_exception':
124 return f"Unable to find the SDS with '{MockDeviceApi.SDS_NAME_1}'. Please enter a valid SDS name/id."
125 elif response_type == 'pd_exception':
126 return f"Unable to find the protection domain with " \
127 f"'{MockDeviceApi.PD_NAME_1}'. Please enter a valid " \
128 f"protection domain name/id"
129 elif response_type == 'sp_exception':
130 return f"Unable to find the storage pool with " \
131 f"'{MockDeviceApi.SP_NAME_1}'. Please enter a valid " \
132 f"storage pool name/id."
133 elif response_type == 'ap_exception':
134 return f"Unable to find the acceleration pool with " \
135 f"'{MockDeviceApi.SP_NAME_1}'. Please enter a valid " \
136 f"acceleration pool name/id."
137 elif response_type == 'add_exception':
138 return "Adding device ansible_device_1 operation failed with error"
139 elif response_type == 'add_dev_name_exception':
140 return "Please provide valid device_name value for adding a device"
141 elif response_type == 'add_dev_path_exception':
142 return "Current pathname of device is a mandatory parameter for adding a device. Please enter a valid value"
143 elif response_type == 'ext_type_exception':
144 return "Storage Pool ID/name or Acceleration Pool ID/name is mandatory along with external_acceleration_type."
145 elif response_type == 'add_without_pd':
146 return "Protection domain name/id is required to uniquely identify"