Debian Codegraph @

ansible_collections/netapp_eseries/santricity/tests/unit/modules/test_na_santricity_volume.py

raw symbols SCIP
1 # (c) 2020, NetApp, Inc
2 # BSD-3 Clause (see COPYING or https://opensource.org/licenses/BSD-3-Clause)
3 from __future__ import absolute_import, division, print_function
4 __metaclass__ = type
5
6 import unittest
7 from contextlib import contextmanager
8 from ansible.module_utils.testing import patch_module_args
9 from ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_volume import NetAppESeriesVolume
10 from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
11 AnsibleFailJson, ModuleTestCase
12 )
13 from ansible_collections.community.internal_test_tools.tests.unit.compat import mock
14
15
16 class NetAppESeriesVolumeTest(ModuleTestCase):
17 REQUIRED_PARAMS = {"api_username": "username",
18 "api_password": "password",
19 "api_url": "http://localhost/devmgr/v2",
20 "ssid": "1",
21 "validate_certs": "no"}
22
23 THIN_VOLUME_RESPONSE = [{"capacity": "1288490188800",
24 "volumeRef": "3A000000600A098000A4B28D000010475C405428",
25 "status": "optimal",
26 "protectionType": "type1Protection",
27 "maxVirtualCapacity": "281474976710656",
28 "initialProvisionedCapacity": "4294967296",
29 "currentProvisionedCapacity": "4294967296",
30 "provisionedCapacityQuota": "1305670057984",
31 "growthAlertThreshold": 85,
32 "expansionPolicy": "automatic",
33 "flashCached": False,
34 "metadata": [{"key": "workloadId", "value": "4200000001000000000000000000000000000000"},
35 {"key": "volumeTypeId", "value": "volume"}],
36 "dataAssurance": True,
37 "segmentSize": 131072,
38 "diskPool": True,
39 "listOfMappings": [],
40 "mapped": False,
41 "currentControllerId": "070000000000000000000001",
42 "cacheSettings": {"readCacheEnable": True, "writeCacheEnable": True,
43 "readAheadMultiplier": 0},
44 "name": "thin_volume",
45 "id": "3A000000600A098000A4B28D000010475C405428"}]
46 VOLUME_GET_RESPONSE = [{"offline": False,
47 "raidLevel": "raid6",
48 "capacity": "214748364800",
49 "reconPriority": 1,
50 "segmentSize": 131072,
51 "volumeRef": "02000000600A098000A4B9D100000F095C2F7F31",
52 "status": "optimal",
53 "protectionInformationCapable": False,
54 "protectionType": "type0Protection",
55 "diskPool": True,
56 "flashCached": False,
57 "metadata": [{"key": "workloadId", "value": "4200000002000000000000000000000000000000"},
58 {"key": "volumeTypeId", "value": "Clare"}],
59 "dataAssurance": False,
60 "currentControllerId": "070000000000000000000002",
61 "cacheSettings": {"readCacheEnable": True, "writeCacheEnable": False,
62 "readAheadMultiplier": 0},
63 "thinProvisioned": False,
64 "totalSizeInBytes": "214748364800",
65 "name": "Matthew",
66 "id": "02000000600A098000A4B9D100000F095C2F7F31"},
67 {"offline": False,
68 "raidLevel": "raid6",
69 "capacity": "107374182400",
70 "reconPriority": 1,
71 "segmentSize": 131072,
72 "volumeRef": "02000000600A098000A4B28D00000FBE5C2F7F26",
73 "status": "optimal",
74 "protectionInformationCapable": False,
75 "protectionType": "type0Protection",
76 "diskPool": True,
77 "flashCached": False,
78 "metadata": [{"key": "workloadId", "value": "4200000002000000000000000000000000000000"},
79 {"key": "volumeTypeId", "value": "Samantha"}],
80 "dataAssurance": False,
81 "currentControllerId": "070000000000000000000001",
82 "cacheSettings": {"readCacheEnable": True, "writeCacheEnable": False,
83 "readAheadMultiplier": 0},
84 "thinProvisioned": False,
85 "totalSizeInBytes": "107374182400",
86 "name": "Samantha",
87 "id": "02000000600A098000A4B28D00000FBE5C2F7F26"},
88 {"offline": False,
89 "raidLevel": "raid6",
90 "capacity": "107374182400",
91 "segmentSize": 131072,
92 "volumeRef": "02000000600A098000A4B9D100000F0B5C2F7F40",
93 "status": "optimal",
94 "protectionInformationCapable": False,
95 "protectionType": "type0Protection",
96 "volumeGroupRef": "04000000600A098000A4B9D100000F085C2F7F26",
97 "diskPool": True,
98 "flashCached": False,
99 "metadata": [{"key": "workloadId", "value": "4200000002000000000000000000000000000000"},
100 {"key": "volumeTypeId", "value": "Micah"}],
101 "dataAssurance": False,
102 "currentControllerId": "070000000000000000000002",
103 "cacheSettings": {"readCacheEnable": True, "writeCacheEnable": False,
104 "readAheadMultiplier": 0},
105 "thinProvisioned": False,
106 "totalSizeInBytes": "107374182400",
107 "name": "Micah",
108 "id": "02000000600A098000A4B9D100000F0B5C2F7F40"}]
109 STORAGE_POOL_GET_RESPONSE = [{"offline": False,
110 "raidLevel": "raidDiskPool",
111 "volumeGroupRef": "04000000600A",
112 "securityType": "capable",
113 "protectionInformationCapable": False,
114 "protectionInformationCapabilities": {"protectionInformationCapable": True,
115 "protectionType": "type2Protection"},
116 "volumeGroupData": {"type": "diskPool",
117 "diskPoolData": {"reconstructionReservedDriveCount": 1,
118 "reconstructionReservedAmt": "296889614336",
119 "reconstructionReservedDriveCountCurrent": 1,
120 "poolUtilizationWarningThreshold": 0,
121 "poolUtilizationCriticalThreshold": 85,
122 "poolUtilizationState": "utilizationOptimal",
123 "unusableCapacity": "0",
124 "degradedReconstructPriority": "high",
125 "criticalReconstructPriority": "highest",
126 "backgroundOperationPriority": "low",
127 "allocGranularity": "4294967296"}},
128 "reservedSpaceAllocated": False,
129 "securityLevel": "fde",
130 "usedSpace": "863288426496",
131 "totalRaidedSpace": "2276332666880",
132 "raidStatus": "optimal",
133 "freeSpace": "1413044240384",
134 "drivePhysicalType": "sas",
135 "driveMediaType": "hdd",
136 "diskPool": True,
137 "id": "04000000600A098000A4B9D100000F085C2F7F26",
138 "name": "employee_data_storage_pool"},
139 {"offline": False,
140 "raidLevel": "raid1",
141 "volumeGroupRef": "04000000600A098000A4B28D00000FBD5C2F7F19",
142 "state": "complete",
143 "securityType": "capable",
144 "drawerLossProtection": False,
145 "protectionInformationCapable": False,
146 "protectionInformationCapabilities": {"protectionInformationCapable": True,
147 "protectionType": "type2Protection"},
148 "volumeGroupData": {"type": "unknown", "diskPoolData": None},
149 "reservedSpaceAllocated": False,
150 "securityLevel": "fde",
151 "usedSpace": "322122547200",
152 "totalRaidedSpace": "598926258176",
153 "raidStatus": "optimal",
154 "freeSpace": "276803710976",
155 "drivePhysicalType": "sas",
156 "driveMediaType": "hdd",
157 "diskPool": False,
158 "id": "04000000600A098000A4B28D00000FBD5C2F7F19",
159 "name": "database_storage_pool"}]
160
161 GET_LONG_LIVED_OPERATION_RESPONSE = [
162 {"returnCode": "ok",
163 "longLivedOpsProgress": [
164 {"volAction": "initializing", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
165 "init": {"volumeRef": "02000000600A098000A4B9D1000037315D494C6F", "pending": False, "percentComplete": 1, "timeToCompletion": 20},
166 "format": None, "volCreation": None, "volDeletion": None},
167 {"volAction": "initializing", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
168 "init": {"volumeRef": "02000000600A098000A4B28D00003D2C5D494C87", "pending": False, "percentComplete": 0, "timeToCompletion": 18},
169 "volCreation": None, "volDeletion": None}]},
170 {"returnCode": "ok",
171 "longLivedOpsProgress": [
172 {"volAction": "complete", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
173 "init": {"volumeRef": "02000000600A098000A4B9D1000037315D494C6F", "pending": False, "percentComplete": 1, "timeToCompletion": 20},
174 "format": None, "volCreation": None, "volDeletion": None},
175 {"volAction": "initializing", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
176 "init": {"volumeRef": "02000000600A098000A4B28D00003D2C5D494C87", "pending": False, "percentComplete": 0, "timeToCompletion": 18},
177 "volCreation": None, "volDeletion": None}]},
178 {"returnCode": "ok",
179 "longLivedOpsProgress": [
180 {"volAction": "initializing", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
181 "init": {"volumeRef": "02000000600A098000A4B9D1000037315D494C6F", "pending": False, "percentComplete": 1, "timeToCompletion": 20},
182 "format": None, "volCreation": None, "volDeletion": None},
183 {"volAction": "complete", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
184 "init": {"volumeRef": "02000000600A098000A4B28D00003D2C5D494C87", "pending": False, "percentComplete": 0, "timeToCompletion": 18},
185 "volCreation": None, "volDeletion": None}]},
186 {"returnCode": "ok",
187 "longLivedOpsProgress": [
188 {"volAction": "complete", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
189 "init": {"volumeRef": "02000000600A098000A4B9D1000037315D494C6F", "pending": False, "percentComplete": 1, "timeToCompletion": 20},
190 "format": None, "volCreation": None, "volDeletion": None},
191 {"volAction": "complete", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
192 "init": {"volumeRef": "02000000600A098000A4B28D00003D2C5D494C87", "pending": False, "percentComplete": 0, "timeToCompletion": 18},
193 "volCreation": None, "volDeletion": None}]}]
194
195 WORKLOAD_GET_RESPONSE = [{"id": "4200000001000000000000000000000000000000", "name": "general_workload_1",
196 "workloadAttributes": [{"key": "profileId", "value": "Other_1"}]},
197 {"id": "4200000002000000000000000000000000000000", "name": "employee_data",
198 "workloadAttributes": [{"key": "use", "value": "EmployeeData"},
199 {"key": "location", "value": "ICT"},
200 {"key": "private", "value": "public"},
201 {"key": "profileId", "value": "ansible_workload_1"}]},
202 {"id": "4200000003000000000000000000000000000000", "name": "customer_database",
203 "workloadAttributes": [{"key": "use", "value": "customer_information"},
204 {"key": "location", "value": "global"},
205 {"key": "profileId", "value": "ansible_workload_2"}]},
206 {"id": "4200000004000000000000000000000000000000", "name": "product_database",
207 "workloadAttributes": [{"key": "use", "value": "production_information"},
208 {"key": "security", "value": "private"},
209 {"key": "location", "value": "global"},
210 {"key": "profileId", "value": "ansible_workload_4"}]}]
211
212 REQUEST_FUNC = "ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_volume.NetAppESeriesVolume.request"
213 GET_VOLUME_FUNC = "ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_volume.NetAppESeriesVolume.get_volume"
214 SLEEP_FUNC = "ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_volume.time.sleep"
215
216 @contextmanager
217 def _set_args(self, args=None):
218 module_args = self.REQUIRED_PARAMS.copy()
219 if args is not None:
220 module_args.update(args)
221 with patch_module_args(module_args):
222 yield
223
224 def test_module_arguments_pass(self):
225 """Ensure valid arguments successful create a class instance."""
226 arg_sets = [{"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 100, "size_unit": "tb",
227 "thin_provision": True, "thin_volume_repo_size": 64, "thin_volume_max_repo_size": 1000,
228 "thin_volume_growth_alert_threshold": 10},
229 {"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 100, "size_unit": "gb",
230 "thin_provision": True, "thin_volume_repo_size": 64, "thin_volume_max_repo_size": 1024,
231 "thin_volume_growth_alert_threshold": 99},
232 {"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 100, "size_unit": "gb",
233 "thin_provision": True, "thin_volume_repo_size": 64},
234 {"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 100, "size_unit": "kb",
235 "thin_provision": True, "thin_volume_repo_size": 64, "thin_volume_max_repo_size": 67108864}]
236
237 # validate size normalization
238 for arg_set in arg_sets:
239 with self._set_args(arg_set):
240 volume_object = NetAppESeriesVolume()
241
242 self.assertEqual(volume_object.size_b, volume_object.convert_to_aligned_bytes(arg_set["size"]))
243 self.assertEqual(volume_object.thin_volume_repo_size_b, volume_object.convert_to_aligned_bytes(arg_set["thin_volume_repo_size"]))
244 self.assertEqual(volume_object.thin_volume_expansion_policy, "automatic")
245 if "thin_volume_max_repo_size" not in arg_set.keys():
246 self.assertEqual(volume_object.thin_volume_max_repo_size_b, volume_object.convert_to_aligned_bytes(arg_set["size"]))
247 else:
248 self.assertEqual(volume_object.thin_volume_max_repo_size_b,
249 volume_object.convert_to_aligned_bytes(arg_set["thin_volume_max_repo_size"]))
250
251 # validate metadata form
252 with self._set_args(
253 {"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 10, "workload_name": "workload1",
254 "metadata": {"availability": "public", "security": "low"}}
255 ):
256 volume_object = NetAppESeriesVolume()
257 for entry in volume_object.metadata:
258 self.assertTrue(entry in [{'value': 'low', 'key': 'security'}, {'value': 'public', 'key': 'availability'}])
259
260 def test_module_arguments_fail(self):
261 """Ensure invalid arguments values do not create a class instance."""
262 arg_sets = [{"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 100, "size_unit": "tb",
263 "thin_provision": True, "thin_volume_repo_size": 260},
264 {"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 10000, "size_unit": "tb",
265 "thin_provision": True, "thin_volume_repo_size": 64, "thin_volume_max_repo_size": 10},
266 {"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 10000, "size_unit": "gb",
267 "thin_provision": True, "thin_volume_repo_size": 64, "thin_volume_max_repo_size": 1000,
268 "thin_volume_growth_alert_threshold": 9},
269 {"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 10000, "size_unit": "gb",
270 "thin_provision": True, "thin_volume_repo_size": 64, "thin_volume_max_repo_size": 1000,
271 "thin_volume_growth_alert_threshold": 100}]
272
273 for arg_set in arg_sets:
274 with self.assertRaises(AnsibleFailJson):
275 with self._set_args(arg_set):
276 print(arg_set)
277 volume_object = NetAppESeriesVolume()
278
279 def test_get_volume_pass(self):
280 """Evaluate the get_volume method."""
281 with mock.patch(self.REQUEST_FUNC,
282 side_effect=[(200, self.VOLUME_GET_RESPONSE), (200, self.THIN_VOLUME_RESPONSE)]):
283 with self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100}):
284 volume_object = NetAppESeriesVolume()
285 self.assertEqual(volume_object.get_volume(),
286 [entry for entry in self.VOLUME_GET_RESPONSE if entry["name"] == "Matthew"][0])
287
288 with mock.patch(self.REQUEST_FUNC,
289 side_effect=[(200, self.VOLUME_GET_RESPONSE), (200, self.THIN_VOLUME_RESPONSE)]):
290 with self._set_args({"state": "present", "name": "NotAVolume", "storage_pool_name": "pool", "size": 100}):
291 volume_object = NetAppESeriesVolume()
292 self.assertEqual(volume_object.get_volume(), {})
293
294 def test_get_volume_fail(self):
295 """Evaluate the get_volume exception paths."""
296 with self.assertRaisesRegex(AnsibleFailJson, "Failed to obtain list of thick volumes."):
297 with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
298 with self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100}):
299 volume_object = NetAppESeriesVolume()
300 volume_object.get_volume()
301
302 with self.assertRaisesRegex(AnsibleFailJson, "Failed to obtain list of thin volumes."):
303 with mock.patch(self.REQUEST_FUNC, side_effect=[(200, self.VOLUME_GET_RESPONSE), Exception()]):
304 with self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100}):
305 volume_object = NetAppESeriesVolume()
306 volume_object.get_volume()
307
308 def tests_wait_for_volume_availability_pass(self):
309 """Ensure wait_for_volume_availability completes as expected."""
310 with self._set_args({"state": "present", "name": "NewVolume", "storage_pool_name": "employee_data_storage_pool", "size": 100,
311 "wait_for_initialization": True}):
312 volume_object = NetAppESeriesVolume()
313 with mock.patch(self.SLEEP_FUNC, return_value=None):
314 with mock.patch(self.GET_VOLUME_FUNC, side_effect=[False, False, True]):
315 volume_object.wait_for_volume_availability()
316
317 def tests_wait_for_volume_availability_fail(self):
318 """Ensure wait_for_volume_availability throws the expected exceptions."""
319 with self._set_args({"state": "present", "name": "NewVolume", "storage_pool_name": "employee_data_storage_pool", "size": 100,
320 "wait_for_initialization": True}):
321 volume_object = NetAppESeriesVolume()
322 volume_object.get_volume = lambda: False
323 with self.assertRaisesRegex(AnsibleFailJson, "Timed out waiting for the volume"):
324 with mock.patch(self.SLEEP_FUNC, return_value=None):
325 volume_object.wait_for_volume_availability()
326
327 def tests_wait_for_volume_action_pass(self):
328 """Ensure wait_for_volume_action completes as expected."""
329 with self._set_args({"state": "present", "name": "NewVolume", "storage_pool_name": "employee_data_storage_pool", "size": 100,
330 "wait_for_initialization": True}):
331 volume_object = NetAppESeriesVolume()
332 volume_object.volume_detail = {"id": "02000000600A098000A4B9D1000037315D494C6F",
333 "storageVolumeRef": "02000000600A098000A4B9D1000037315DXXXXXX"}
334 with mock.patch(self.SLEEP_FUNC, return_value=None):
335 with mock.patch(self.REQUEST_FUNC, side_effect=[(200, self.GET_LONG_LIVED_OPERATION_RESPONSE[0]),
336 (200, self.GET_LONG_LIVED_OPERATION_RESPONSE[1]),
337 (200, self.GET_LONG_LIVED_OPERATION_RESPONSE[2]),
338 (200, self.GET_LONG_LIVED_OPERATION_RESPONSE[3])]):
339 volume_object.wait_for_volume_action()
340
341 with self._set_args({"state": "present", "name": "NewVolume", "storage_pool_name": "employee_data_storage_pool", "size": 100,
342 "wait_for_initialization": True}):
343 volume_object = NetAppESeriesVolume()
344 volume_object.volume_detail = {"id": "02000000600A098000A4B9D1000037315DXXXXXX",
345 "storageVolumeRef": "02000000600A098000A4B9D1000037315D494C6F"}
346 with mock.patch(self.SLEEP_FUNC, return_value=None):
347 with mock.patch(self.REQUEST_FUNC, side_effect=[(200, self.GET_LONG_LIVED_OPERATION_RESPONSE[0]),
348 (200, self.GET_LONG_LIVED_OPERATION_RESPONSE[1]),
349 (200, self.GET_LONG_LIVED_OPERATION_RESPONSE[2]),
350 (200, self.GET_LONG_LIVED_OPERATION_RESPONSE[3])]):
351 volume_object.wait_for_volume_action()
352
353 def tests_wait_for_volume_action_fail(self):
354 """Ensure wait_for_volume_action throws the expected exceptions."""
355 with self._set_args({"state": "present", "name": "NewVolume", "storage_pool_name": "employee_data_storage_pool", "size": 100,
356 "wait_for_initialization": True}):
357 volume_object = NetAppESeriesVolume()
358 volume_object.volume_detail = {"id": "02000000600A098000A4B9D1000037315DXXXXXX",
359 "storageVolumeRef": "02000000600A098000A4B9D1000037315D494C6F"}
360 with mock.patch(self.SLEEP_FUNC, return_value=None):
361 with self.assertRaisesRegex(AnsibleFailJson, "Failed to get volume expansion progress."):
362 with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
363 volume_object.wait_for_volume_action()
364
365 with self.assertRaisesRegex(AnsibleFailJson, "Expansion action failed to complete."):
366 with mock.patch(self.REQUEST_FUNC, return_value=(200, self.GET_LONG_LIVED_OPERATION_RESPONSE[0])):
367 volume_object.wait_for_volume_action(timeout=300)
368
369 def test_get_storage_pool_pass(self):
370 """Evaluate the get_storage_pool method."""
371 with mock.patch(self.REQUEST_FUNC, return_value=(200, self.STORAGE_POOL_GET_RESPONSE)):
372 with self._set_args({"state": "present", "name": "NewVolume", "storage_pool_name": "employee_data_storage_pool",
373 "size": 100}):
374 volume_object = NetAppESeriesVolume()
375 self.assertEqual(volume_object.get_storage_pool(), [entry for entry in self.STORAGE_POOL_GET_RESPONSE if
376 entry["name"] == "employee_data_storage_pool"][0])
377
378 with self._set_args(
379 {"state": "present", "name": "NewVolume", "storage_pool_name": "NotAStoragePool", "size": 100}
380 ):
381 volume_object = NetAppESeriesVolume()
382 self.assertEqual(volume_object.get_storage_pool(), {})
383
384 def test_get_storage_pool_fail(self):
385 """Evaluate the get_storage_pool exception paths."""
386 with self.assertRaisesRegex(AnsibleFailJson, "Failed to obtain list of storage pools."):
387 with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
388 with self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100}):
389 volume_object = NetAppESeriesVolume()
390 volume_object.get_storage_pool()
391
392 def test_check_storage_pool_sufficiency_pass(self):
393 """Ensure passing logic."""
394 with self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100}):
395 volume_object = NetAppESeriesVolume()
396 volume_object.pool_detail = [entry for entry in self.STORAGE_POOL_GET_RESPONSE
397 if entry["name"] == "employee_data_storage_pool"][0]
398 volume_object.check_storage_pool_sufficiency()
399
400 def test_check_storage_pool_sufficiency_fail(self):
401 """Validate exceptions are thrown for insufficient storage pool resources."""
402 with self._set_args({"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 100, "size_unit": "tb",
403 "thin_provision": True, "thin_volume_repo_size": 64, "thin_volume_max_repo_size": 1000,
404 "thin_volume_growth_alert_threshold": 10}):
405 volume_object = NetAppESeriesVolume()
406
407 with self.assertRaisesRegex(AnsibleFailJson, "Requested storage pool"):
408 volume_object.check_storage_pool_sufficiency()
409
410 with self.assertRaisesRegex(AnsibleFailJson,
411 "Thin provisioned volumes can only be created on raid disk pools."):
412 volume_object.pool_detail = [entry for entry in self.STORAGE_POOL_GET_RESPONSE
413 if entry["name"] == "database_storage_pool"][0]
414 volume_object.volume_detail = {}
415 volume_object.check_storage_pool_sufficiency()
416
417 with self.assertRaisesRegex(AnsibleFailJson, "requires the storage pool to be DA-compatible."):
418 volume_object.pool_detail = {"diskPool": True,
419 "protectionInformationCapabilities": {"protectionType": "type0Protection",
420 "protectionInformationCapable": False}}
421 volume_object.volume_detail = {}
422 volume_object.data_assurance_enabled = True
423 volume_object.check_storage_pool_sufficiency()
424
425 volume_object.pool_detail = {"diskPool": True,
426 "protectionInformationCapabilities": {"protectionType": "type2Protection",
427 "protectionInformationCapable": True}}
428 volume_object.check_storage_pool_sufficiency()
429
430 with self._set_args({"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 100, "size_unit": "tb",
431 "thin_provision": False}):
432 volume_object = NetAppESeriesVolume()
433 with self.assertRaisesRegex(AnsibleFailJson,
434 "Not enough storage pool free space available for the volume's needs."):
435 volume_object.pool_detail = {"freeSpace": 10, "diskPool": True,
436 "protectionInformationCapabilities": {"protectionType": "type2Protection",
437 "protectionInformationCapable": True}}
438 volume_object.volume_detail = {"totalSizeInBytes": 100}
439 volume_object.data_assurance_enabled = True
440 volume_object.size_b = 1
441 volume_object.check_storage_pool_sufficiency()
442
443 def test_update_workload_tags_pass(self):
444 """Validate updating workload tags."""
445 test_sets = [[{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100}, False],
446 [{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
447 "workload_name": "employee_data"}, False],
448 [{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
449 "workload_name": "customer_database",
450 "metadata": {"use": "customer_information", "location": "global"}}, False],
451 [{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
452 "workload_name": "customer_database",
453 "metadata": {"use": "customer_information"}}, True],
454 [{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
455 "workload_name": "customer_database",
456 "metadata": {"use": "customer_information", "location": "local"}}, True],
457 [{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
458 "workload_name": "customer_database",
459 "metadata": {"use": "customer_information", "location": "global", "importance": "no"}}, True],
460 [{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
461 "workload_name": "newWorkload",
462 "metadata": {"for_testing": "yes"}}, True],
463 [{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
464 "workload_name": "newWorkload"}, True]]
465
466 for test in test_sets:
467 with self._set_args(test[0]):
468 volume_object = NetAppESeriesVolume()
469
470 with mock.patch(self.REQUEST_FUNC, side_effect=[(200, self.WORKLOAD_GET_RESPONSE), (200, {"id": 1})]):
471 self.assertEqual(volume_object.update_workload_tags(), test[1])
472
473 def test_update_workload_tags_fail(self):
474 """Validate updating workload tags fails appropriately."""
475 with self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
476 "workload_name": "employee_data"}):
477 volume_object = NetAppESeriesVolume()
478 with self.assertRaisesRegex(AnsibleFailJson, "Failed to retrieve storage array workload tags."):
479 with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
480 volume_object.update_workload_tags()
481
482 with self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
483 "workload_name": "employee_data", "metadata": {"key": "not-use", "value": "EmployeeData"}}):
484 volume_object = NetAppESeriesVolume()
485 with self.assertRaisesRegex(AnsibleFailJson, "Failed to create new workload tag."):
486 with mock.patch(self.REQUEST_FUNC, side_effect=[(200, self.WORKLOAD_GET_RESPONSE), Exception()]):
487 volume_object.update_workload_tags()
488
489 with self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
490 "workload_name": "employee_data2", "metadata": {"key": "use", "value": "EmployeeData"}}):
491 volume_object = NetAppESeriesVolume()
492 with self.assertRaisesRegex(AnsibleFailJson, "Failed to create new workload tag."):
493 with mock.patch(self.REQUEST_FUNC, side_effect=[(200, self.WORKLOAD_GET_RESPONSE), Exception()]):
494 volume_object.update_workload_tags()
495
496 @unittest.skip("Test needs to be reworked.")
497 def test_get_volume_property_changes_pass(self):
498 """Verify correct dictionary is returned"""
499
500 # no property changes
501 with self._set_args(
502 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
503 "read_cache_enable": True, "write_cache_enable": True,
504 "read_ahead_enable": True, "thin_provision": False}
505 ):
506 volume_object = NetAppESeriesVolume()
507 volume_object.volume_detail = {"metadata": [],
508 "cacheSettings": {"cwob": False, "readCacheEnable": True, "writeCacheEnable": True,
509 "readAheadMultiplier": 1}, "flashCached": True,
510 "segmentSize": str(128 * 1024)}
511 self.assertEqual(volume_object.get_volume_property_changes(), dict())
512
513 with self._set_args(
514 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
515 "read_cache_enable": True, "write_cache_enable": True,
516 "read_ahead_enable": True, "thin_provision": True, "thin_volume_repo_size": 64,
517 "thin_volume_max_repo_size": 1000, "thin_volume_growth_alert_threshold": 90}
518 ):
519 volume_object = NetAppESeriesVolume()
520 volume_object.volume_detail = {"metadata": [],
521 "cacheSettings": {"cwob": False, "readCacheEnable": True, "writeCacheEnable": True,
522 "readAheadMultiplier": 1},
523 "flashCached": True, "growthAlertThreshold": "90",
524 "expansionPolicy": "automatic", "segmentSize": str(128 * 1024)}
525 self.assertEqual(volume_object.get_volume_property_changes(), dict())
526
527 # property changes
528 with self._set_args(
529 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
530 "read_cache_enable": True, "write_cache_enable": True,
531 "read_ahead_enable": True, "thin_provision": False}
532 ):
533 volume_object = NetAppESeriesVolume()
534 volume_object.volume_detail = {"metadata": [],
535 "cacheSettings": {"cwob": False, "readCacheEnable": False, "writeCacheEnable": True,
536 "readAheadMultiplier": 1}, "flashCached": True,
537 "segmentSize": str(128 * 1024)}
538 self.assertEqual(volume_object.get_volume_property_changes(),
539 {"metaTags": [], 'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True},
540 'flashCache': True})
541 with self._set_args(
542 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
543 "read_cache_enable": True, "write_cache_enable": True, "cache_without_batteries": False,
544 "read_ahead_enable": True, "thin_provision": False}
545 ):
546 volume_object = NetAppESeriesVolume()
547 volume_object.volume_detail = {"metadata": [],
548 "cacheSettings": {"cwob": False, "readCacheEnable": True, "writeCacheEnable": False,
549 "readAheadMultiplier": 1}, "flashCached": True,
550 "segmentSize": str(128 * 1024)}
551 self.assertEqual(volume_object.get_volume_property_changes(),
552 {"metaTags": [], 'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True},
553 'flashCache': True})
554 with self._set_args(
555 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
556 "read_cache_enable": True, "write_cache_enable": True, "cache_without_batteries": True,
557 "read_ahead_enable": True, "thin_provision": False}
558 ):
559 volume_object = NetAppESeriesVolume()
560 volume_object.volume_detail = {"metadata": [],
561 "cacheSettings": {"cwob": False, "readCacheEnable": True, "writeCacheEnable": True,
562 "readAheadMultiplier": 1}, "flashCached": False,
563 "segmentSize": str(128 * 1024)}
564 self.assertEqual(volume_object.get_volume_property_changes(),
565 {"metaTags": [], 'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True, "cacheWithoutBatteries": True},
566 'flashCache': True})
567 with self._set_args(
568 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
569 "read_cache_enable": True, "write_cache_enable": True, "cache_without_batteries": True,
570 "read_ahead_enable": False, "thin_provision": False}
571 ):
572 volume_object = NetAppESeriesVolume()
573 volume_object.volume_detail = {"metadata": [],
574 "cacheSettings": {"cwob": False, "readCacheEnable": True, "writeCacheEnable": True,
575 "readAheadMultiplier": 1}, "flashCached": False,
576 "segmentSize": str(128 * 1024)}
577 self.assertEqual(volume_object.get_volume_property_changes(), {"metaTags": [],
578 'cacheSettings': {'readCacheEnable': True,
579 'writeCacheEnable': True,
580 'readAheadEnable': False,
581 "cacheWithoutBatteries": True},
582 'flashCache': True})
583
584 with self._set_args(
585 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
586 "read_cache_enable": True, "write_cache_enable": True,
587 "read_ahead_enable": True, "thin_provision": True, "thin_volume_repo_size": 64,
588 "thin_volume_max_repo_size": 1000, "thin_volume_growth_alert_threshold": 90}
589 ):
590 volume_object = NetAppESeriesVolume()
591 volume_object.volume_detail = {"metadata": [],
592 "cacheSettings": {"cwob": True, "readCacheEnable": True, "writeCacheEnable": True,
593 "readAheadMultiplier": 1},
594 "flashCached": True, "growthAlertThreshold": "95",
595 "expansionPolicy": "automatic", "segmentSize": str(128 * 1024)}
596 self.assertEqual(volume_object.get_volume_property_changes(),
597 {"metaTags": [], 'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True},
598 'growthAlertThreshold': 90, 'flashCache': True})
599
600 def test_get_volume_property_changes_fail(self):
601 """Verify correct exception is thrown"""
602 with self._set_args(
603 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
604 "read_cache_enable": True, "write_cache_enable": True, "read_ahead_enable": True, "thin_provision": False}
605 ):
606 volume_object = NetAppESeriesVolume()
607 volume_object.volume_detail = {
608 "cacheSettings": {"cwob": False, "readCacheEnable": True, "writeCacheEnable": True, "readAheadMultiplier": 1},
609 "flashCached": True, "segmentSize": str(512 * 1024)}
610 with self.assertRaisesRegex(AnsibleFailJson, "Existing volume segment size is"):
611 volume_object.get_volume_property_changes()
612
613 @unittest.skip("Test needs to be reworked.")
614 def test_get_expand_volume_changes_pass(self):
615 """Verify expansion changes."""
616 # thick volumes
617 with self._set_args(
618 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False}
619 ):
620 volume_object = NetAppESeriesVolume()
621 volume_object.volume_detail = {"capacity": str(50 * 1024 * 1024 * 1024), "thinProvisioned": False}
622 self.assertEqual(volume_object.get_expand_volume_changes(),
623 {"sizeUnit": "bytes", "expansionSize": 100 * 1024 * 1024 * 1024})
624
625 # thin volumes
626 with self._set_args(
627 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
628 "thin_volume_expansion_policy": "automatic", "thin_volume_repo_size": 64,
629 "thin_volume_max_repo_size": 1000, "thin_volume_growth_alert_threshold": 90}
630 ):
631 volume_object = NetAppESeriesVolume()
632 volume_object.volume_detail = {"capacity": str(50 * 1024 * 1024 * 1024), "thinProvisioned": True,
633 "expansionPolicy": "automatic",
634 "provisionedCapacityQuota": str(1000 * 1024 * 1024 * 1024)}
635 self.assertEqual(volume_object.get_expand_volume_changes(),
636 {"sizeUnit": "bytes", "newVirtualSize": 100 * 1024 * 1024 * 1024})
637 with self._set_args(
638 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
639 "thin_volume_expansion_policy": "automatic", "thin_volume_repo_size": 64,
640 "thin_volume_max_repo_size": 1000, "thin_volume_growth_alert_threshold": 90}
641 ):
642 volume_object = NetAppESeriesVolume()
643 volume_object.volume_detail = {"capacity": str(100 * 1024 * 1024 * 1024), "thinProvisioned": True,
644 "expansionPolicy": "automatic",
645 "provisionedCapacityQuota": str(500 * 1024 * 1024 * 1024)}
646 self.assertEqual(volume_object.get_expand_volume_changes(),
647 {"sizeUnit": "bytes", "newRepositorySize": 1000 * 1024 * 1024 * 1024})
648 with self._set_args(
649 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
650 "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 504, "thin_volume_max_repo_size": 1000,
651 "thin_volume_growth_alert_threshold": 90}
652 ):
653 volume_object = NetAppESeriesVolume()
654 volume_object.volume_detail = {"capacity": str(100 * 1024 * 1024 * 1024), "thinProvisioned": True,
655 "expansionPolicy": "manual",
656 "currentProvisionedCapacity": str(500 * 1024 * 1024 * 1024)}
657 self.assertEqual(volume_object.get_expand_volume_changes(),
658 {"sizeUnit": "bytes", "newRepositorySize": 504 * 1024 * 1024 * 1024})
659 with self._set_args(
660 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
661 "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 756, "thin_volume_max_repo_size": 1000,
662 "thin_volume_growth_alert_threshold": 90}
663 ):
664 volume_object = NetAppESeriesVolume()
665 volume_object.volume_detail = {"capacity": str(100 * 1024 * 1024 * 1024), "thinProvisioned": True,
666 "expansionPolicy": "manual",
667 "currentProvisionedCapacity": str(500 * 1024 * 1024 * 1024)}
668 self.assertEqual(volume_object.get_expand_volume_changes(),
669 {"sizeUnit": "bytes", "newRepositorySize": 756 * 1024 * 1024 * 1024})
670
671 def test_get_expand_volume_changes_fail(self):
672 """Verify exceptions are thrown."""
673 with self._set_args(
674 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False}
675 ):
676 volume_object = NetAppESeriesVolume()
677 volume_object.volume_detail = {"capacity": str(1000 * 1024 * 1024 * 1024)}
678 with self.assertRaisesRegex(AnsibleFailJson, "Reducing the size of volumes is not permitted."):
679 volume_object.get_expand_volume_changes()
680
681 with self._set_args(
682 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
683 "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 502, "thin_volume_max_repo_size": 1000,
684 "thin_volume_growth_alert_threshold": 90}
685 ):
686 volume_object = NetAppESeriesVolume()
687 volume_object.volume_detail = {"capacity": str(100 * 1024 * 1024 * 1024), "thinProvisioned": True,
688 "expansionPolicy": "manual",
689 "currentProvisionedCapacity": str(500 * 1024 * 1024 * 1024)}
690 with self.assertRaisesRegex(AnsibleFailJson, "The thin volume repository increase must be between or equal"):
691 volume_object.get_expand_volume_changes()
692
693 with self._set_args(
694 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
695 "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 760, "thin_volume_max_repo_size": 1000,
696 "thin_volume_growth_alert_threshold": 90}
697 ):
698 volume_object = NetAppESeriesVolume()
699 volume_object.volume_detail = {"capacity": str(100 * 1024 * 1024 * 1024), "thinProvisioned": True,
700 "expansionPolicy": "manual",
701 "currentProvisionedCapacity": str(500 * 1024 * 1024 * 1024)}
702 with self.assertRaisesRegex(AnsibleFailJson, "The thin volume repository increase must be between or equal"):
703 volume_object.get_expand_volume_changes()
704
705 def test_create_volume_pass(self):
706 """Verify volume creation."""
707 with self._set_args(
708 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False}
709 ):
710 volume_object = NetAppESeriesVolume()
711 volume_object.pool_detail = {"id": "12345"}
712 with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
713 volume_object.create_volume()
714
715 with self._set_args(
716 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
717 "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 760, "thin_volume_max_repo_size": 1000,
718 "thin_volume_growth_alert_threshold": 90}
719 ):
720 volume_object = NetAppESeriesVolume()
721 volume_object.pool_detail = {"id": "12345"}
722 with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
723 volume_object.create_volume()
724
725 def test_create_volume_fail(self):
726 """Verify exceptions thrown."""
727 with self._set_args(
728 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False}
729 ):
730 volume_object = NetAppESeriesVolume()
731 volume_object.pool_detail = {"id": "12345"}
732 with self.assertRaisesRegex(AnsibleFailJson, "Failed to create volume."):
733 with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
734 volume_object.create_volume()
735
736 with self._set_args(
737 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
738 "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 760, "thin_volume_max_repo_size": 1000,
739 "thin_volume_growth_alert_threshold": 90}
740 ):
741 volume_object = NetAppESeriesVolume()
742 volume_object.pool_detail = {"id": "12345"}
743 with self.assertRaisesRegex(AnsibleFailJson, "Failed to create thin volume."):
744 with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
745 volume_object.create_volume()
746
747 def test_update_volume_properties_pass(self):
748 """verify property update."""
749 with self._set_args(
750 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False}
751 ):
752 volume_object = NetAppESeriesVolume()
753 volume_object.pool_detail = {"id": "12345"}
754 volume_object.wait_for_volume_availability = lambda: None
755 volume_object.get_volume = lambda: {"id": "12345'"}
756 volume_object.get_volume_property_changes = lambda: {
757 'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True}, 'growthAlertThreshold': 90,
758 'flashCached': True}
759 volume_object.workload_id = "4200000001000000000000000000000000000000"
760 with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
761 self.assertTrue(volume_object.update_volume_properties())
762
763 with self._set_args(
764 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
765 "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 760, "thin_volume_max_repo_size": 1000,
766 "thin_volume_growth_alert_threshold": 90}
767 ):
768 volume_object = NetAppESeriesVolume()
769 volume_object.pool_detail = {"id": "12345"}
770 volume_object.wait_for_volume_availability = lambda: None
771 volume_object.get_volume = lambda: {"id": "12345'"}
772 volume_object.get_volume_property_changes = lambda: {
773 'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True}, 'growthAlertThreshold': 90,
774 'flashCached': True}
775 volume_object.workload_id = "4200000001000000000000000000000000000000"
776 with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
777 self.assertTrue(volume_object.update_volume_properties())
778
779 with self._set_args(
780 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False}
781 ):
782 volume_object = NetAppESeriesVolume()
783 volume_object.pool_detail = {"metadata": [{"key": "workloadId", "value": "12345"}]}
784 volume_object.wait_for_volume_availability = lambda: None
785 volume_object.get_volume = lambda: {"id": "12345'"}
786 volume_object.get_volume_property_changes = lambda: {}
787 volume_object.workload_id = "4200000001000000000000000000000000000000"
788 self.assertFalse(volume_object.update_volume_properties())
789
790 def test_update_volume_properties_fail(self):
791 """Verify exceptions are thrown."""
792 with self._set_args(
793 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False}
794 ):
795 volume_object = NetAppESeriesVolume()
796 volume_object.pool_detail = {"id": "12345"}
797 volume_object.wait_for_volume_availability = lambda: None
798 volume_object.get_volume = lambda: {"id": "12345'"}
799 volume_object.get_volume_property_changes = lambda: {
800 'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True}, 'growthAlertThreshold': 90,
801 'flashCached': True}
802 volume_object.workload_id = "4200000001000000000000000000000000000000"
803 with self.assertRaisesRegex(AnsibleFailJson, "Failed to update volume properties."):
804 with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
805 self.assertTrue(volume_object.update_volume_properties())
806
807 with self._set_args(
808 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
809 "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 760, "thin_volume_max_repo_size": 1000,
810 "thin_volume_growth_alert_threshold": 90}
811 ):
812 volume_object = NetAppESeriesVolume()
813 volume_object.pool_detail = {"id": "12345"}
814 volume_object.wait_for_volume_availability = lambda: None
815 volume_object.get_volume = lambda: {"id": "12345'"}
816 volume_object.get_volume_property_changes = lambda: {
817 'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True}, 'growthAlertThreshold': 90,
818 'flashCached': True}
819 volume_object.workload_id = "4200000001000000000000000000000000000000"
820 with self.assertRaisesRegex(AnsibleFailJson, "Failed to update thin volume properties."):
821 with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
822 self.assertTrue(volume_object.update_volume_properties())
823
824 def test_expand_volume_pass(self):
825 """Verify volume expansion."""
826 with self._set_args(
827 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False}
828 ):
829 volume_object = NetAppESeriesVolume()
830 volume_object.get_expand_volume_changes = lambda: {"sizeUnit": "bytes",
831 "expansionSize": 100 * 1024 * 1024 * 1024}
832 volume_object.volume_detail = {"id": "12345", "thinProvisioned": True}
833 with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
834 volume_object.expand_volume()
835
836 with self._set_args(
837 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
838 "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 760, "thin_volume_max_repo_size": 1000,
839 "thin_volume_growth_alert_threshold": 90}
840 ):
841 volume_object = NetAppESeriesVolume()
842 volume_object.get_expand_volume_changes = lambda: {"sizeUnit": "bytes",
843 "expansionSize": 100 * 1024 * 1024 * 1024}
844 volume_object.volume_detail = {"id": "12345", "thinProvisioned": True}
845 with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
846 volume_object.expand_volume()
847
848 def test_expand_volume_fail(self):
849 """Verify exceptions are thrown."""
850 with self._set_args(
851 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False}
852 ):
853 volume_object = NetAppESeriesVolume()
854 volume_object.get_expand_volume_changes = lambda: {"sizeUnit": "bytes",
855 "expansionSize": 100 * 1024 * 1024 * 1024}
856 volume_object.volume_detail = {"id": "12345", "thinProvisioned": False}
857 with self.assertRaisesRegex(AnsibleFailJson, "Failed to expand volume."):
858 with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
859 volume_object.expand_volume()
860
861 with self._set_args(
862 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True}
863 ):
864 volume_object = NetAppESeriesVolume()
865 volume_object.get_expand_volume_changes = lambda: {"sizeUnit": "bytes",
866 "expansionSize": 100 * 1024 * 1024 * 1024}
867 volume_object.volume_detail = {"id": "12345", "thinProvisioned": True}
868 with self.assertRaisesRegex(AnsibleFailJson, "Failed to expand thin volume."):
869 with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
870 volume_object.expand_volume()
871
872 def test_delete_volume_pass(self):
873 """Verify volume deletion."""
874 with self._set_args(
875 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False}
876 ):
877 volume_object = NetAppESeriesVolume()
878 volume_object.volume_detail = {"id": "12345"}
879 with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
880 volume_object.delete_volume()
881
882 with self._set_args(
883 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
884 "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 760, "thin_volume_max_repo_size": 1000,
885 "thin_volume_growth_alert_threshold": 90}
886 ):
887 volume_object = NetAppESeriesVolume()
888 volume_object.volume_detail = {"id": "12345"}
889 with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
890 volume_object.delete_volume()
891
892 def test_delete_volume_fail(self):
893 """Verify exceptions are thrown."""
894 with self._set_args(
895 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False}
896 ):
897 volume_object = NetAppESeriesVolume()
898 with self.assertRaisesRegex(AnsibleFailJson, "Failed to delete volume."):
899 with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
900 volume_object.delete_volume()
901
902 with self._set_args(
903 {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True}
904 ):
905 volume_object = NetAppESeriesVolume()
906 with self.assertRaisesRegex(AnsibleFailJson, "Failed to delete thin volume."):
907 with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
908 volume_object.delete_volume()