Debian Codegraph @

ansible_collections/dellemc/powerflex/tests/unit/plugins/modules/test_protection_domain.py

raw symbols SCIP
1 # Copyright: (c) 2024, Dell Technologies
2
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 """Unit Tests for Protection Domain module on Dell Technologies (Dell) PowerFlex"""
6
7 from __future__ import (absolute_import, division, print_function)
8
9 __metaclass__ = type
10 import pytest
11 # pylint: disable=unused-import
12 from ansible_collections.dellemc.powerflex.tests.unit.plugins.module_utils.libraries import initial_mock
13 from mock.mock import MagicMock
14 from ansible_collections.dellemc.powerflex.tests.unit.plugins.module_utils.mock_protection_domain_api \
15 import MockProtectionDomainApi
16 from ansible_collections.dellemc.powerflex.tests.unit.plugins.module_utils.mock_api_exception \
17 import MockApiException
18 from ansible_collections.dellemc.powerflex.tests.unit.plugins.module_utils.libraries.powerflex_unit_base \
19 import PowerFlexUnitBase
20 from ansible_collections.dellemc.powerflex.plugins.modules.protection_domain \
21 import PowerFlexProtectionDomain
22
23
24 class TestPowerflexProtectionDomain(PowerFlexUnitBase):
25
26 get_module_args = MockProtectionDomainApi.PD_COMMON_ARGS
27
28 @pytest.fixture
29 def module_object(self):
30 return PowerFlexProtectionDomain
31
32 @pytest.mark.parametrize("params", [
33 {'protection_domain_id': MockProtectionDomainApi.PD_ID},
34 {"protection_domain_name": MockProtectionDomainApi.PD_NAME},
35 ])
36 def test_get_protection_domain_response(self, powerflex_module_mock, params):
37 self.set_module_params(
38 powerflex_module_mock,
39 self.get_module_args,
40 {
41 'protection_domain_id': params.get('protection_domain_id', None),
42 'protection_domain_name': params.get('protection_domain_name', None)
43 })
44 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
45 return_value=MockProtectionDomainApi.PROTECTION_DOMAIN
46 )
47 powerflex_module_mock.perform_module_operation()
48 powerflex_module_mock.powerflex_conn.protection_domain.get.assert_called()
49
50 def test_get_pd_exception(self, powerflex_module_mock):
51 self.set_module_params(
52 powerflex_module_mock,
53 self.get_module_args,
54 {
55 'protection_domain_id': MockProtectionDomainApi.PD_ID,
56 })
57 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
58 return_value=MockApiException())
59 self.capture_fail_json_call(
60 MockProtectionDomainApi.get_failed_msgs('get_pd_failed_msg'),
61 powerflex_module_mock, invoke_perform_module=True)
62
63 def test_validate_input_empty_params(self, powerflex_module_mock):
64 self.set_module_params(
65 powerflex_module_mock,
66 self.get_module_args,
67 {
68 'protection_domain_name': ''
69 })
70 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
71 return_value=MockProtectionDomainApi.PROTECTION_DOMAIN
72 )
73 self.capture_fail_json_call(
74 MockProtectionDomainApi.get_failed_msgs('empty_pd_msg'),
75 powerflex_module_mock, invoke_perform_module=True)
76
77 def test_validate_network_limits_params(self, powerflex_module_mock):
78 self.set_module_params(
79 powerflex_module_mock,
80 self.get_module_args,
81 {
82 'protection_domain_name': MockProtectionDomainApi.PD_NAME,
83 'network_limits': {'overall_limit': -199,
84 'bandwidth_unit': 'MBps'}
85 })
86 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
87 return_value=MockProtectionDomainApi.PROTECTION_DOMAIN
88 )
89 self.capture_fail_json_call(
90 MockProtectionDomainApi.get_failed_msgs('overall_limit_msg'),
91 powerflex_module_mock, invoke_perform_module=True)
92
93 def test_create_pd_new_name_exception(self, powerflex_module_mock):
94 self.set_module_params(
95 powerflex_module_mock,
96 self.get_module_args,
97 {
98 'protection_domain_name': MockProtectionDomainApi.PD_NAME,
99 'protection_domain_new_name': MockProtectionDomainApi.PD_NAME
100 })
101 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
102 return_value=[]
103 )
104 self.capture_fail_json_call(
105 MockProtectionDomainApi.get_failed_msgs('new_name_in_create'),
106 powerflex_module_mock, invoke_perform_module=True)
107
108 def test_create_pd_(self, powerflex_module_mock):
109 self.set_module_params(
110 powerflex_module_mock,
111 self.get_module_args,
112 {
113 'protection_domain_name': MockProtectionDomainApi.PD_NAME
114 })
115 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
116 return_value=[]
117 )
118 powerflex_module_mock.powerflex_conn.protection_domain.create = MagicMock(
119 return_value=None
120 )
121 resp = powerflex_module_mock.create_protection_domain("protection_domain_name")
122 assert resp is True
123 powerflex_module_mock.powerflex_conn.protection_domain.create.assert_called()
124
125 def test_rename_pd(self, powerflex_module_mock):
126 self.set_module_params(
127 powerflex_module_mock,
128 self.get_module_args,
129 {
130 'protection_domain_name': MockProtectionDomainApi.PD_NAME,
131 'protection_domain_new_name': MockProtectionDomainApi.PD_NEW_NAME,
132 })
133 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
134 return_value=MockProtectionDomainApi.PROTECTION_DOMAIN)
135 powerflex_module_mock.perform_module_operation()
136 powerflex_module_mock.powerflex_conn.protection_domain.rename.assert_called()
137
138 def test_rename_pd_execption(self, powerflex_module_mock):
139 self.set_module_params(
140 powerflex_module_mock,
141 self.get_module_args,
142 {
143 'protection_domain_name': MockProtectionDomainApi.PD_NAME,
144 'protection_domain_new_name': MockProtectionDomainApi.PD_NEW_NAME,
145 })
146 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
147 return_value=MockProtectionDomainApi.PROTECTION_DOMAIN)
148 powerflex_module_mock.powerflex_conn.protection_domain.rename = MagicMock(
149 side_effect=MockApiException
150 )
151 self.capture_fail_json_call(
152 MockProtectionDomainApi.get_failed_msgs('rename_pd_exception'),
153 powerflex_module_mock, invoke_perform_module=True
154 )
155
156 def test_inactivate_pd(self, powerflex_module_mock):
157 self.set_module_params(
158 powerflex_module_mock,
159 self.get_module_args,
160 {
161 'protection_domain_name': MockProtectionDomainApi.PD_NAME,
162 'is_active': False
163 })
164 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
165 return_value=MockProtectionDomainApi.PROTECTION_DOMAIN)
166 powerflex_module_mock.perform_module_operation()
167 powerflex_module_mock.powerflex_conn.protection_domain.inactivate.assert_called()
168
169 def test_activate_pd(self, powerflex_module_mock):
170 self.set_module_params(
171 powerflex_module_mock,
172 self.get_module_args,
173 {
174 'protection_domain_id': MockProtectionDomainApi.PD_ID,
175 'is_active': True
176 })
177 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
178 return_value=MockProtectionDomainApi.PROTECTION_DOMAIN_1)
179 powerflex_module_mock.perform_module_operation()
180 powerflex_module_mock.powerflex_conn.protection_domain.activate.assert_called()
181
182 def test_create_pd_exception(self, powerflex_module_mock):
183 self.set_module_params(
184 powerflex_module_mock,
185 self.get_module_args,
186 {
187 'protection_domain_name': MockProtectionDomainApi.PD_NAME,
188 'is_active': False
189 })
190 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
191 return_value=[]
192 )
193 powerflex_module_mock.powerflex_conn.protection_domain.create = MagicMock(
194 side_effect=MockApiException
195 )
196 self.capture_fail_json_call(
197 MockProtectionDomainApi.get_failed_msgs('create_pd_exception'),
198 powerflex_module_mock, invoke_perform_module=True
199 )
200
201 def test_modify_network_limits(self, powerflex_module_mock):
202 self.set_module_params(
203 powerflex_module_mock,
204 self.get_module_args,
205 {
206 'protection_domain_name': MockProtectionDomainApi.PD_NAME,
207 'network_limits': {'overall_limit': 15,
208 'bandwidth_unit': 'GBps',
209 'rebalance_limit': 10,
210 'rebuild_limit': 10,
211 'vtree_migration_limit': 10}
212 })
213 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
214 return_value=MockProtectionDomainApi.PROTECTION_DOMAIN)
215 powerflex_module_mock.perform_module_operation()
216 powerflex_module_mock.powerflex_conn.protection_domain.network_limits.assert_called()
217
218 def test_modify_network_limits_exception(self, powerflex_module_mock):
219 self.set_module_params(
220 powerflex_module_mock,
221 self.get_module_args,
222 {
223 'protection_domain_id': MockProtectionDomainApi.PD_ID,
224 'network_limits': {'overall_limit': 15,
225 'bandwidth_unit': 'GBps',
226 'rebalance_limit': 10,
227 'rebuild_limit': 10,
228 'vtree_migration_limit': 10}
229 })
230 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
231 return_value=MockProtectionDomainApi.PROTECTION_DOMAIN)
232 powerflex_module_mock.powerflex_conn.protection_domain.network_limits = MagicMock(
233 side_effect=MockApiException
234 )
235 self.capture_fail_json_call(
236 MockProtectionDomainApi.get_failed_msgs('modify_network_limits_exception'),
237 powerflex_module_mock, invoke_perform_module=True
238 )
239
240 def test_enable_rf_cache(self, powerflex_module_mock):
241 self.set_module_params(
242 powerflex_module_mock,
243 self.get_module_args,
244 {
245 'protection_domain_name': MockProtectionDomainApi.PD_NAME,
246 'rf_cache_limits': {'is_enabled': True,
247 'page_size': 10,
248 'max_io_limit': 10,
249 'pass_through_mode': 'Read'}
250 })
251 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
252 return_value=MockProtectionDomainApi.PROTECTION_DOMAIN)
253 powerflex_module_mock.perform_module_operation()
254 powerflex_module_mock.powerflex_conn.protection_domain.set_rfcache_enabled.assert_called()
255 powerflex_module_mock.powerflex_conn.protection_domain.rfcache_parameters.assert_called()
256
257 def test_modify_rf_cache_params_exception(self, powerflex_module_mock):
258 self.set_module_params(
259 powerflex_module_mock,
260 self.get_module_args,
261 {
262 'protection_domain_name': MockProtectionDomainApi.PD_NAME,
263 'rf_cache_limits': {'is_enabled': True, 'page_size': 10,
264 'max_io_limit': 10, 'pass_through_mode': 'Read'}
265 })
266 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
267 return_value=MockProtectionDomainApi.PROTECTION_DOMAIN)
268 powerflex_module_mock.powerflex_conn.protection_domain.set_rfcache_enabled = MagicMock(
269 side_effect=MockApiException)
270 self.capture_fail_json_call(
271 MockProtectionDomainApi.get_failed_msgs('rf_cache_limits_exception'),
272 powerflex_module_mock, invoke_perform_module=True
273 )
274
275 def test_delete_pd(self, powerflex_module_mock):
276 self.set_module_params(
277 powerflex_module_mock,
278 self.get_module_args,
279 {
280 'protection_domain_name': MockProtectionDomainApi.PD_NAME,
281 'state': 'absent'
282 })
283 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
284 return_value=MockProtectionDomainApi.PROTECTION_DOMAIN)
285 powerflex_module_mock.perform_module_operation()
286 powerflex_module_mock.powerflex_conn.protection_domain.delete.assert_called()
287
288 def test_delete_pd_exception(self, powerflex_module_mock):
289 self.set_module_params(
290 powerflex_module_mock,
291 self.get_module_args,
292 {
293 'protection_domain_id': MockProtectionDomainApi.PD_ID,
294 'state': 'absent'
295 })
296 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
297 return_value=MockProtectionDomainApi.PROTECTION_DOMAIN)
298 powerflex_module_mock.powerflex_conn.protection_domain.delete = MagicMock(
299 side_effect=MockApiException
300 )
301 self.capture_fail_json_call(
302 MockProtectionDomainApi.get_failed_msgs('delete_pd_exception'),
303 powerflex_module_mock, invoke_perform_module=True
304 )
305
306 def test_get_sp(self, powerflex_module_mock):
307 self.set_module_params(
308 powerflex_module_mock,
309 self.get_module_args,
310 {
311 'protection_domain_name': MockProtectionDomainApi.PD_NAME
312 })
313 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
314 return_value=MockProtectionDomainApi.PROTECTION_DOMAIN)
315 powerflex_module_mock.powerflex_conn.protection_domain.get_storage_pools = MagicMock(
316 return_value=MockProtectionDomainApi.STORAGE_POOL)
317 powerflex_module_mock.perform_module_operation()
318 powerflex_module_mock.powerflex_conn.protection_domain.get_storage_pools.assert_called()
319
320 def test_get_sp_exception(self, powerflex_module_mock):
321 self.set_module_params(
322 powerflex_module_mock,
323 self.get_module_args,
324 {
325 'protection_domain_id': MockProtectionDomainApi.PD_ID
326 })
327 powerflex_module_mock.powerflex_conn.protection_domain.get = MagicMock(
328 return_value=MockProtectionDomainApi.PROTECTION_DOMAIN)
329 powerflex_module_mock.powerflex_conn.protection_domain.get_storage_pools = MagicMock(
330 side_effect=MockApiException
331 )
332 self.capture_fail_json_call(
333 MockProtectionDomainApi.get_failed_msgs('get_sp_exception'),
334 powerflex_module_mock, invoke_perform_module=True)