summaryrefslogtreecommitdiff
path: root/test/units/modules/storage/netapp/test_netapp_e_volume.py
blob: 348d0e4b1f41851b1bcf97fbf9b3812d1f82f4ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
# coding=utf-8
# (c) 2018, NetApp Inc.
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type

try:
    from unittest import mock
except ImportError:
    import mock

from ansible.module_utils.netapp import NetAppESeriesModule
from ansible.modules.storage.netapp.netapp_e_volume import NetAppESeriesVolume
from units.modules.utils import AnsibleFailJson, ModuleTestCase, set_module_args


class NetAppESeriesVolumeTest(ModuleTestCase):
    REQUIRED_PARAMS = {"api_username": "username",
                       "api_password": "password",
                       "api_url": "http://localhost/devmgr/v2",
                       "ssid": "1",
                       "validate_certs": "no"}

    THIN_VOLUME_RESPONSE = [{"capacity": "1288490188800",
                             "volumeRef": "3A000000600A098000A4B28D000010475C405428",
                             "status": "optimal",
                             "protectionType": "type1Protection",
                             "maxVirtualCapacity": "281474976710656",
                             "initialProvisionedCapacity": "4294967296",
                             "currentProvisionedCapacity": "4294967296",
                             "provisionedCapacityQuota": "1305670057984",
                             "growthAlertThreshold": 85,
                             "expansionPolicy": "automatic",
                             "flashCached": False,
                             "metadata": [{"key": "workloadId", "value": "4200000001000000000000000000000000000000"},
                                          {"key": "volumeTypeId", "value": "volume"}],
                             "dataAssurance": True,
                             "segmentSize": 131072,
                             "diskPool": True,
                             "listOfMappings": [],
                             "mapped": False,
                             "currentControllerId": "070000000000000000000001",
                             "cacheSettings": {"readCacheEnable": True, "writeCacheEnable": True,
                                               "readAheadMultiplier": 0},
                             "name": "thin_volume",
                             "id": "3A000000600A098000A4B28D000010475C405428"}]
    VOLUME_GET_RESPONSE = [{"offline": False,
                            "raidLevel": "raid6",
                            "capacity": "214748364800",
                            "reconPriority": 1,
                            "segmentSize": 131072,
                            "volumeRef": "02000000600A098000A4B9D100000F095C2F7F31",
                            "status": "optimal",
                            "protectionInformationCapable": False,
                            "protectionType": "type0Protection",
                            "diskPool": True,
                            "flashCached": False,
                            "metadata": [{"key": "workloadId", "value": "4200000002000000000000000000000000000000"},
                                         {"key": "volumeTypeId", "value": "Clare"}],
                            "dataAssurance": False,
                            "currentControllerId": "070000000000000000000002",
                            "cacheSettings": {"readCacheEnable": True, "writeCacheEnable": False,
                                              "readAheadMultiplier": 0},
                            "thinProvisioned": False,
                            "totalSizeInBytes": "214748364800",
                            "name": "Matthew",
                            "id": "02000000600A098000A4B9D100000F095C2F7F31"},
                           {"offline": False,
                            "raidLevel": "raid6",
                            "capacity": "107374182400",
                            "reconPriority": 1,
                            "segmentSize": 131072,
                            "volumeRef": "02000000600A098000A4B28D00000FBE5C2F7F26",
                            "status": "optimal",
                            "protectionInformationCapable": False,
                            "protectionType": "type0Protection",
                            "diskPool": True,
                            "flashCached": False,
                            "metadata": [{"key": "workloadId", "value": "4200000002000000000000000000000000000000"},
                                         {"key": "volumeTypeId", "value": "Samantha"}],
                            "dataAssurance": False,
                            "currentControllerId": "070000000000000000000001",
                            "cacheSettings": {"readCacheEnable": True, "writeCacheEnable": False,
                                              "readAheadMultiplier": 0},
                            "thinProvisioned": False,
                            "totalSizeInBytes": "107374182400",
                            "name": "Samantha",
                            "id": "02000000600A098000A4B28D00000FBE5C2F7F26"},
                           {"offline": False,
                            "raidLevel": "raid6",
                            "capacity": "107374182400",
                            "segmentSize": 131072,
                            "volumeRef": "02000000600A098000A4B9D100000F0B5C2F7F40",
                            "status": "optimal",
                            "protectionInformationCapable": False,
                            "protectionType": "type0Protection",
                            "volumeGroupRef": "04000000600A098000A4B9D100000F085C2F7F26",
                            "diskPool": True,
                            "flashCached": False,
                            "metadata": [{"key": "workloadId", "value": "4200000002000000000000000000000000000000"},
                                         {"key": "volumeTypeId", "value": "Micah"}],
                            "dataAssurance": False,
                            "currentControllerId": "070000000000000000000002",
                            "cacheSettings": {"readCacheEnable": True, "writeCacheEnable": False,
                                              "readAheadMultiplier": 0},
                            "thinProvisioned": False,
                            "totalSizeInBytes": "107374182400",
                            "name": "Micah",
                            "id": "02000000600A098000A4B9D100000F0B5C2F7F40"}]
    STORAGE_POOL_GET_RESPONSE = [{"offline": False,
                                  "raidLevel": "raidDiskPool",
                                  "volumeGroupRef": "04000000600A",
                                  "securityType": "capable",
                                  "protectionInformationCapable": False,
                                  "protectionInformationCapabilities": {"protectionInformationCapable": True,
                                                                        "protectionType": "type2Protection"},
                                  "volumeGroupData": {"type": "diskPool",
                                                      "diskPoolData": {"reconstructionReservedDriveCount": 1,
                                                                       "reconstructionReservedAmt": "296889614336",
                                                                       "reconstructionReservedDriveCountCurrent": 1,
                                                                       "poolUtilizationWarningThreshold": 0,
                                                                       "poolUtilizationCriticalThreshold": 85,
                                                                       "poolUtilizationState": "utilizationOptimal",
                                                                       "unusableCapacity": "0",
                                                                       "degradedReconstructPriority": "high",
                                                                       "criticalReconstructPriority": "highest",
                                                                       "backgroundOperationPriority": "low",
                                                                       "allocGranularity": "4294967296"}},
                                  "reservedSpaceAllocated": False,
                                  "securityLevel": "fde",
                                  "usedSpace": "863288426496",
                                  "totalRaidedSpace": "2276332666880",
                                  "raidStatus": "optimal",
                                  "freeSpace": "1413044240384",
                                  "drivePhysicalType": "sas",
                                  "driveMediaType": "hdd",
                                  "diskPool": True,
                                  "id": "04000000600A098000A4B9D100000F085C2F7F26",
                                  "name": "employee_data_storage_pool"},
                                 {"offline": False,
                                  "raidLevel": "raid1",
                                  "volumeGroupRef": "04000000600A098000A4B28D00000FBD5C2F7F19",
                                  "state": "complete",
                                  "securityType": "capable",
                                  "drawerLossProtection": False,
                                  "protectionInformationCapable": False,
                                  "protectionInformationCapabilities": {"protectionInformationCapable": True,
                                                                        "protectionType": "type2Protection"},
                                  "volumeGroupData": {"type": "unknown", "diskPoolData": None},
                                  "reservedSpaceAllocated": False,
                                  "securityLevel": "fde",
                                  "usedSpace": "322122547200",
                                  "totalRaidedSpace": "598926258176",
                                  "raidStatus": "optimal",
                                  "freeSpace": "276803710976",
                                  "drivePhysicalType": "sas",
                                  "driveMediaType": "hdd",
                                  "diskPool": False,
                                  "id": "04000000600A098000A4B28D00000FBD5C2F7F19",
                                  "name": "database_storage_pool"}]

    GET_LONG_LIVED_OPERATION_RESPONSE = [
        {"returnCode": "ok",
         "longLivedOpsProgress": [
             {"volAction": "initializing", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
              "init": {"volumeRef": "02000000600A098000A4B9D1000037315D494C6F", "pending": False, "percentComplete": 1, "timeToCompletion": 20},
              "format": None, "volCreation": None, "volDeletion": None},
             {"volAction": "initializing", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
              "init": {"volumeRef": "02000000600A098000A4B28D00003D2C5D494C87", "pending": False, "percentComplete": 0, "timeToCompletion": 18},
              "volCreation": None, "volDeletion": None}]},
        {"returnCode": "ok",
         "longLivedOpsProgress": [
             {"volAction": "complete", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
              "init": {"volumeRef": "02000000600A098000A4B9D1000037315D494C6F", "pending": False, "percentComplete": 1, "timeToCompletion": 20},
              "format": None, "volCreation": None, "volDeletion": None},
             {"volAction": "initializing", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
              "init": {"volumeRef": "02000000600A098000A4B28D00003D2C5D494C87", "pending": False, "percentComplete": 0, "timeToCompletion": 18},
              "volCreation": None, "volDeletion": None}]},
        {"returnCode": "ok",
         "longLivedOpsProgress": [
             {"volAction": "initializing", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
              "init": {"volumeRef": "02000000600A098000A4B9D1000037315D494C6F", "pending": False, "percentComplete": 1, "timeToCompletion": 20},
              "format": None, "volCreation": None, "volDeletion": None},
             {"volAction": "complete", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
              "init": {"volumeRef": "02000000600A098000A4B28D00003D2C5D494C87", "pending": False, "percentComplete": 0, "timeToCompletion": 18},
              "volCreation": None, "volDeletion": None}]},
        {"returnCode": "ok",
         "longLivedOpsProgress": [
             {"volAction": "complete", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
              "init": {"volumeRef": "02000000600A098000A4B9D1000037315D494C6F", "pending": False, "percentComplete": 1, "timeToCompletion": 20},
              "format": None, "volCreation": None, "volDeletion": None},
             {"volAction": "complete", "reconstruct": None, "volExpansion": None, "volAndCapExpansion": None,
              "init": {"volumeRef": "02000000600A098000A4B28D00003D2C5D494C87", "pending": False, "percentComplete": 0, "timeToCompletion": 18},
              "volCreation": None, "volDeletion": None}]}]

    WORKLOAD_GET_RESPONSE = [{"id": "4200000001000000000000000000000000000000", "name": "general_workload_1",
                              "workloadAttributes": [{"key": "profileId", "value": "Other_1"}]},
                             {"id": "4200000002000000000000000000000000000000", "name": "employee_data",
                              "workloadAttributes": [{"key": "use", "value": "EmployeeData"},
                                                     {"key": "location", "value": "ICT"},
                                                     {"key": "private", "value": "public"},
                                                     {"key": "profileId", "value": "ansible_workload_1"}]},
                             {"id": "4200000003000000000000000000000000000000", "name": "customer_database",
                              "workloadAttributes": [{"key": "use", "value": "customer_information"},
                                                     {"key": "location", "value": "global"},
                                                     {"key": "profileId", "value": "ansible_workload_2"}]},
                             {"id": "4200000004000000000000000000000000000000", "name": "product_database",
                              "workloadAttributes": [{"key": "use", "value": "production_information"},
                                                     {"key": "security", "value": "private"},
                                                     {"key": "location", "value": "global"},
                                                     {"key": "profileId", "value": "ansible_workload_4"}]}]

    REQUEST_FUNC = "ansible.modules.storage.netapp.netapp_e_volume.NetAppESeriesVolume.request"
    GET_VOLUME_FUNC = "ansible.modules.storage.netapp.netapp_e_volume.NetAppESeriesVolume.get_volume"
    SLEEP_FUNC = "ansible.modules.storage.netapp.netapp_e_volume.sleep"

    def _set_args(self, args=None):
        module_args = self.REQUIRED_PARAMS.copy()
        if args is not None:
            module_args.update(args)
        set_module_args(module_args)

    def test_module_arguments_pass(self):
        """Ensure valid arguments successful create a class instance."""
        arg_sets = [{"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 100, "size_unit": "tb",
                     "thin_provision": True, "thin_volume_repo_size": 64, "thin_volume_max_repo_size": 1000,
                     "thin_volume_growth_alert_threshold": 10},
                    {"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 100, "size_unit": "gb",
                     "thin_provision": True, "thin_volume_repo_size": 64, "thin_volume_max_repo_size": 1024,
                     "thin_volume_growth_alert_threshold": 99},
                    {"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 100, "size_unit": "gb",
                     "thin_provision": True, "thin_volume_repo_size": 64},
                    {"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 100, "size_unit": "kb",
                     "thin_provision": True, "thin_volume_repo_size": 64, "thin_volume_max_repo_size": 67108864}]

        # validate size normalization
        for arg_set in arg_sets:
            self._set_args(arg_set)
            volume_object = NetAppESeriesVolume()

            self.assertEqual(volume_object.size_b, volume_object.convert_to_aligned_bytes(arg_set["size"]))
            self.assertEqual(volume_object.thin_volume_repo_size_b, volume_object.convert_to_aligned_bytes(arg_set["thin_volume_repo_size"]))
            self.assertEqual(volume_object.thin_volume_expansion_policy, "automatic")
            if "thin_volume_max_repo_size" not in arg_set.keys():
                self.assertEqual(volume_object.thin_volume_max_repo_size_b, volume_object.convert_to_aligned_bytes(arg_set["size"]))
            else:
                self.assertEqual(volume_object.thin_volume_max_repo_size_b,
                                 volume_object.convert_to_aligned_bytes(arg_set["thin_volume_max_repo_size"]))

        # validate metadata form
        self._set_args(
            {"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 10, "workload_name": "workload1",
             "metadata": {"availability": "public", "security": "low"}})
        volume_object = NetAppESeriesVolume()
        for entry in volume_object.metadata:
            self.assertTrue(entry in [{'value': 'low', 'key': 'security'}, {'value': 'public', 'key': 'availability'}])

    def test_module_arguments_fail(self):
        """Ensure invalid arguments values do not create a class instance."""
        arg_sets = [{"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 100, "size_unit": "tb",
                     "thin_provision": True, "thin_volume_repo_size": 260},
                    {"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 10000, "size_unit": "tb",
                     "thin_provision": True, "thin_volume_repo_size": 64, "thin_volume_max_repo_size": 10},
                    {"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 10000, "size_unit": "gb",
                     "thin_provision": True, "thin_volume_repo_size": 64, "thin_volume_max_repo_size": 1000,
                     "thin_volume_growth_alert_threshold": 9},
                    {"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 10000, "size_unit": "gb",
                     "thin_provision": True, "thin_volume_repo_size": 64, "thin_volume_max_repo_size": 1000,
                     "thin_volume_growth_alert_threshold": 100}]

        for arg_set in arg_sets:
            with self.assertRaises(AnsibleFailJson):
                self._set_args(arg_set)
                print(arg_set)
                volume_object = NetAppESeriesVolume()

    def test_get_volume_pass(self):
        """Evaluate the get_volume method."""
        with mock.patch(self.REQUEST_FUNC,
                        side_effect=[(200, self.VOLUME_GET_RESPONSE), (200, self.THIN_VOLUME_RESPONSE)]):
            self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100})
            volume_object = NetAppESeriesVolume()
            self.assertEqual(volume_object.get_volume(),
                             [entry for entry in self.VOLUME_GET_RESPONSE if entry["name"] == "Matthew"][0])

        with mock.patch(self.REQUEST_FUNC,
                        side_effect=[(200, self.VOLUME_GET_RESPONSE), (200, self.THIN_VOLUME_RESPONSE)]):
            self._set_args({"state": "present", "name": "NotAVolume", "storage_pool_name": "pool", "size": 100})
            volume_object = NetAppESeriesVolume()
            self.assertEqual(volume_object.get_volume(), {})

    def test_get_volume_fail(self):
        """Evaluate the get_volume exception paths."""
        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to obtain list of thick volumes."):
            with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
                self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100})
                volume_object = NetAppESeriesVolume()
                volume_object.get_volume()

        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to obtain list of thin volumes."):
            with mock.patch(self.REQUEST_FUNC, side_effect=[(200, self.VOLUME_GET_RESPONSE), Exception()]):
                self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100})
                volume_object = NetAppESeriesVolume()
                volume_object.get_volume()

    def tests_wait_for_volume_availability_pass(self):
        """Ensure wait_for_volume_availability completes as expected."""
        self._set_args({"state": "present", "name": "NewVolume", "storage_pool_name": "employee_data_storage_pool", "size": 100,
                        "wait_for_initialization": True})
        volume_object = NetAppESeriesVolume()
        with mock.patch(self.SLEEP_FUNC, return_value=None):
            with mock.patch(self.GET_VOLUME_FUNC, side_effect=[False, False, True]):
                volume_object.wait_for_volume_availability()

    def tests_wait_for_volume_availability_fail(self):
        """Ensure wait_for_volume_availability throws the expected exceptions."""
        self._set_args({"state": "present", "name": "NewVolume", "storage_pool_name": "employee_data_storage_pool", "size": 100,
                        "wait_for_initialization": True})
        volume_object = NetAppESeriesVolume()
        volume_object.get_volume = lambda: False
        with self.assertRaisesRegexp(AnsibleFailJson, "Timed out waiting for the volume"):
            with mock.patch(self.SLEEP_FUNC, return_value=None):
                volume_object.wait_for_volume_availability()

    def tests_wait_for_volume_action_pass(self):
        """Ensure wait_for_volume_action completes as expected."""
        self._set_args({"state": "present", "name": "NewVolume", "storage_pool_name": "employee_data_storage_pool", "size": 100,
                        "wait_for_initialization": True})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"id": "02000000600A098000A4B9D1000037315D494C6F",
                                       "storageVolumeRef": "02000000600A098000A4B9D1000037315DXXXXXX"}
        with mock.patch(self.SLEEP_FUNC, return_value=None):
            with mock.patch(self.REQUEST_FUNC, side_effect=[(200, self.GET_LONG_LIVED_OPERATION_RESPONSE[0]),
                                                            (200, self.GET_LONG_LIVED_OPERATION_RESPONSE[1]),
                                                            (200, self.GET_LONG_LIVED_OPERATION_RESPONSE[2]),
                                                            (200, self.GET_LONG_LIVED_OPERATION_RESPONSE[3])]):
                volume_object.wait_for_volume_action()

        self._set_args({"state": "present", "name": "NewVolume", "storage_pool_name": "employee_data_storage_pool", "size": 100,
                        "wait_for_initialization": True})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"id": "02000000600A098000A4B9D1000037315DXXXXXX",
                                       "storageVolumeRef": "02000000600A098000A4B9D1000037315D494C6F"}
        with mock.patch(self.SLEEP_FUNC, return_value=None):
            with mock.patch(self.REQUEST_FUNC, side_effect=[(200, self.GET_LONG_LIVED_OPERATION_RESPONSE[0]),
                                                            (200, self.GET_LONG_LIVED_OPERATION_RESPONSE[1]),
                                                            (200, self.GET_LONG_LIVED_OPERATION_RESPONSE[2]),
                                                            (200, self.GET_LONG_LIVED_OPERATION_RESPONSE[3])]):
                volume_object.wait_for_volume_action()

    def tests_wait_for_volume_action_fail(self):
        """Ensure wait_for_volume_action throws the expected exceptions."""
        self._set_args({"state": "present", "name": "NewVolume", "storage_pool_name": "employee_data_storage_pool", "size": 100,
                        "wait_for_initialization": True})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"id": "02000000600A098000A4B9D1000037315DXXXXXX",
                                       "storageVolumeRef": "02000000600A098000A4B9D1000037315D494C6F"}
        with mock.patch(self.SLEEP_FUNC, return_value=None):
            with self.assertRaisesRegexp(AnsibleFailJson, "Failed to get volume expansion progress."):
                with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
                    volume_object.wait_for_volume_action()

            with self.assertRaisesRegexp(AnsibleFailJson, "Expansion action failed to complete."):
                with mock.patch(self.REQUEST_FUNC, return_value=(200, self.GET_LONG_LIVED_OPERATION_RESPONSE[0])):
                    volume_object.wait_for_volume_action(timeout=300)

    def test_get_storage_pool_pass(self):
        """Evaluate the get_storage_pool method."""
        with mock.patch(self.REQUEST_FUNC, return_value=(200, self.STORAGE_POOL_GET_RESPONSE)):
            self._set_args({"state": "present", "name": "NewVolume", "storage_pool_name": "employee_data_storage_pool",
                            "size": 100})
            volume_object = NetAppESeriesVolume()
            self.assertEqual(volume_object.get_storage_pool(), [entry for entry in self.STORAGE_POOL_GET_RESPONSE if
                                                                entry["name"] == "employee_data_storage_pool"][0])

            self._set_args(
                {"state": "present", "name": "NewVolume", "storage_pool_name": "NotAStoragePool", "size": 100})
            volume_object = NetAppESeriesVolume()
            self.assertEqual(volume_object.get_storage_pool(), {})

    def test_get_storage_pool_fail(self):
        """Evaluate the get_storage_pool exception paths."""
        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to obtain list of storage pools."):
            with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
                self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100})
                volume_object = NetAppESeriesVolume()
                volume_object.get_storage_pool()

    def test_check_storage_pool_sufficiency_pass(self):
        """Ensure passing logic."""
        self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100})
        volume_object = NetAppESeriesVolume()
        volume_object.pool_detail = [entry for entry in self.STORAGE_POOL_GET_RESPONSE
                                     if entry["name"] == "employee_data_storage_pool"][0]
        volume_object.check_storage_pool_sufficiency()

    def test_check_storage_pool_sufficiency_fail(self):
        """Validate exceptions are thrown for insufficient storage pool resources."""
        self._set_args({"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 100, "size_unit": "tb",
                        "thin_provision": True, "thin_volume_repo_size": 64, "thin_volume_max_repo_size": 1000,
                        "thin_volume_growth_alert_threshold": 10})
        volume_object = NetAppESeriesVolume()

        with self.assertRaisesRegexp(AnsibleFailJson, "Requested storage pool"):
            volume_object.check_storage_pool_sufficiency()

        with self.assertRaisesRegexp(AnsibleFailJson,
                                     "Thin provisioned volumes can only be created on raid disk pools."):
            volume_object.pool_detail = [entry for entry in self.STORAGE_POOL_GET_RESPONSE
                                         if entry["name"] == "database_storage_pool"][0]
            volume_object.volume_detail = {}
            volume_object.check_storage_pool_sufficiency()

        with self.assertRaisesRegexp(AnsibleFailJson, "requires the storage pool to be DA-compatible."):
            volume_object.pool_detail = {"diskPool": True,
                                         "protectionInformationCapabilities": {"protectionType": "type0Protection",
                                                                               "protectionInformationCapable": False}}
            volume_object.volume_detail = {}
            volume_object.data_assurance_enabled = True
            volume_object.check_storage_pool_sufficiency()

            volume_object.pool_detail = {"diskPool": True,
                                         "protectionInformationCapabilities": {"protectionType": "type2Protection",
                                                                               "protectionInformationCapable": True}}
            volume_object.check_storage_pool_sufficiency()

        self._set_args({"state": "present", "name": "vol", "storage_pool_name": "pool", "size": 100, "size_unit": "tb",
                        "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        with self.assertRaisesRegexp(AnsibleFailJson,
                                     "Not enough storage pool free space available for the volume's needs."):
            volume_object.pool_detail = {"freeSpace": 10, "diskPool": True,
                                         "protectionInformationCapabilities": {"protectionType": "type2Protection",
                                                                               "protectionInformationCapable": True}}
            volume_object.volume_detail = {"totalSizeInBytes": 100}
            volume_object.data_assurance_enabled = True
            volume_object.size_b = 1
            volume_object.check_storage_pool_sufficiency()

    def test_update_workload_tags_pass(self):
        """Validate updating workload tags."""
        test_sets = [[{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100}, False],
                     [{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
                       "workload_name": "employee_data"}, False],
                     [{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
                       "workload_name": "customer_database",
                       "metadata": {"use": "customer_information", "location": "global"}}, False],
                     [{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
                       "workload_name": "customer_database",
                       "metadata": {"use": "customer_information"}}, True],
                     [{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
                       "workload_name": "customer_database",
                       "metadata": {"use": "customer_information", "location": "local"}}, True],
                     [{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
                       "workload_name": "customer_database",
                       "metadata": {"use": "customer_information", "location": "global", "importance": "no"}}, True],
                     [{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
                       "workload_name": "newWorkload",
                       "metadata": {"for_testing": "yes"}}, True],
                     [{"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
                       "workload_name": "newWorkload"}, True]]

        for test in test_sets:
            self._set_args(test[0])
            volume_object = NetAppESeriesVolume()

            with mock.patch(self.REQUEST_FUNC, side_effect=[(200, self.WORKLOAD_GET_RESPONSE), (200, {"id": 1})]):
                self.assertEqual(volume_object.update_workload_tags(), test[1])

    def test_update_workload_tags_fail(self):
        """Validate updating workload tags fails appropriately."""
        self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
                        "workload_name": "employee_data"})
        volume_object = NetAppESeriesVolume()
        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to retrieve storage array workload tags."):
            with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
                volume_object.update_workload_tags()

        self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
                        "workload_name": "employee_data", "metadata": {"key": "not-use", "value": "EmployeeData"}})
        volume_object = NetAppESeriesVolume()
        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to create new workload tag."):
            with mock.patch(self.REQUEST_FUNC, side_effect=[(200, self.WORKLOAD_GET_RESPONSE), Exception()]):
                volume_object.update_workload_tags()

        self._set_args({"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100,
                        "workload_name": "employee_data2", "metadata": {"key": "use", "value": "EmployeeData"}})
        volume_object = NetAppESeriesVolume()
        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to create new workload tag."):
            with mock.patch(self.REQUEST_FUNC, side_effect=[(200, self.WORKLOAD_GET_RESPONSE), Exception()]):
                volume_object.update_workload_tags()

    def test_get_volume_property_changes_pass(self):
        """Verify correct dictionary is returned"""

        # no property changes
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
             "read_cache_enable": True, "write_cache_enable": True,
             "read_ahead_enable": True, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"metadata": [],
                                       "cacheSettings": {"cwob": False, "readCacheEnable": True, "writeCacheEnable": True,
                                                         "readAheadMultiplier": 1}, "flashCached": True,
                                       "segmentSize": str(128 * 1024)}
        self.assertEqual(volume_object.get_volume_property_changes(), dict())

        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
             "read_cache_enable": True, "write_cache_enable": True,
             "read_ahead_enable": True, "thin_provision": True, "thin_volume_repo_size": 64,
             "thin_volume_max_repo_size": 1000, "thin_volume_growth_alert_threshold": 90})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"metadata": [],
                                       "cacheSettings": {"cwob": False, "readCacheEnable": True, "writeCacheEnable": True,
                                                         "readAheadMultiplier": 1},
                                       "flashCached": True, "growthAlertThreshold": "90",
                                       "expansionPolicy": "automatic", "segmentSize": str(128 * 1024)}
        self.assertEqual(volume_object.get_volume_property_changes(), dict())

        # property changes
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
             "read_cache_enable": True, "write_cache_enable": True,
             "read_ahead_enable": True, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"metadata": [],
                                       "cacheSettings": {"cwob": False, "readCacheEnable": False, "writeCacheEnable": True,
                                                         "readAheadMultiplier": 1}, "flashCached": True,
                                       "segmentSize": str(128 * 1024)}
        self.assertEqual(volume_object.get_volume_property_changes(),
                         {"metaTags": [], 'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True},
                          'flashCache': True})
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
             "read_cache_enable": True, "write_cache_enable": True, "cache_without_batteries": False,
             "read_ahead_enable": True, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"metadata": [],
                                       "cacheSettings": {"cwob": False, "readCacheEnable": True, "writeCacheEnable": False,
                                                         "readAheadMultiplier": 1}, "flashCached": True,
                                       "segmentSize": str(128 * 1024)}
        self.assertEqual(volume_object.get_volume_property_changes(),
                         {"metaTags": [], 'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True},
                          'flashCache': True})
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
             "read_cache_enable": True, "write_cache_enable": True, "cache_without_batteries": True,
             "read_ahead_enable": True, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"metadata": [],
                                       "cacheSettings": {"cwob": False, "readCacheEnable": True, "writeCacheEnable": True,
                                                         "readAheadMultiplier": 1}, "flashCached": False,
                                       "segmentSize": str(128 * 1024)}
        self.assertEqual(volume_object.get_volume_property_changes(),
                         {"metaTags": [], 'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True, "cacheWithoutBatteries": True},
                          'flashCache': True})
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
             "read_cache_enable": True, "write_cache_enable": True, "cache_without_batteries": True,
             "read_ahead_enable": False, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"metadata": [],
                                       "cacheSettings": {"cwob": False, "readCacheEnable": True, "writeCacheEnable": True,
                                                         "readAheadMultiplier": 1}, "flashCached": False,
                                       "segmentSize": str(128 * 1024)}
        self.assertEqual(volume_object.get_volume_property_changes(), {"metaTags": [],
                                                                       'cacheSettings': {'readCacheEnable': True,
                                                                                         'writeCacheEnable': True,
                                                                                         'readAheadEnable': False,
                                                                                         "cacheWithoutBatteries": True},
                                                                       'flashCache': True})

        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
             "read_cache_enable": True, "write_cache_enable": True,
             "read_ahead_enable": True, "thin_provision": True, "thin_volume_repo_size": 64,
             "thin_volume_max_repo_size": 1000, "thin_volume_growth_alert_threshold": 90})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"metadata": [],
                                       "cacheSettings": {"cwob": True, "readCacheEnable": True, "writeCacheEnable": True,
                                                         "readAheadMultiplier": 1},
                                       "flashCached": True, "growthAlertThreshold": "95",
                                       "expansionPolicy": "automatic", "segmentSize": str(128 * 1024)}
        self.assertEqual(volume_object.get_volume_property_changes(),
                         {"metaTags": [], 'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True},
                          'growthAlertThreshold': 90, 'flashCache': True})

    def test_get_volume_property_changes_fail(self):
        """Verify correct exception is thrown"""
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "ssd_cache_enabled": True,
             "read_cache_enable": True, "write_cache_enable": True, "read_ahead_enable": True, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {
            "cacheSettings": {"cwob": False, "readCacheEnable": True, "writeCacheEnable": True, "readAheadMultiplier": 1},
            "flashCached": True, "segmentSize": str(512 * 1024)}
        with self.assertRaisesRegexp(AnsibleFailJson, "Existing volume segment size is"):
            volume_object.get_volume_property_changes()

    def test_get_expand_volume_changes_pass(self):
        """Verify expansion changes."""
        # thick volumes
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"capacity": str(50 * 1024 * 1024 * 1024), "thinProvisioned": False}
        self.assertEqual(volume_object.get_expand_volume_changes(),
                         {"sizeUnit": "bytes", "expansionSize": 100 * 1024 * 1024 * 1024})

        # thin volumes
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
             "thin_volume_expansion_policy": "automatic", "thin_volume_repo_size": 64,
             "thin_volume_max_repo_size": 1000, "thin_volume_growth_alert_threshold": 90})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"capacity": str(50 * 1024 * 1024 * 1024), "thinProvisioned": True,
                                       "expansionPolicy": "automatic",
                                       "provisionedCapacityQuota": str(1000 * 1024 * 1024 * 1024)}
        self.assertEqual(volume_object.get_expand_volume_changes(),
                         {"sizeUnit": "bytes", "newVirtualSize": 100 * 1024 * 1024 * 1024})
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
             "thin_volume_expansion_policy": "automatic", "thin_volume_repo_size": 64,
             "thin_volume_max_repo_size": 1000, "thin_volume_growth_alert_threshold": 90})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"capacity": str(100 * 1024 * 1024 * 1024), "thinProvisioned": True,
                                       "expansionPolicy": "automatic",
                                       "provisionedCapacityQuota": str(500 * 1024 * 1024 * 1024)}
        self.assertEqual(volume_object.get_expand_volume_changes(),
                         {"sizeUnit": "bytes", "newRepositorySize": 1000 * 1024 * 1024 * 1024})
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
             "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 504, "thin_volume_max_repo_size": 1000,
             "thin_volume_growth_alert_threshold": 90})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"capacity": str(100 * 1024 * 1024 * 1024), "thinProvisioned": True,
                                       "expansionPolicy": "manual",
                                       "currentProvisionedCapacity": str(500 * 1024 * 1024 * 1024)}
        self.assertEqual(volume_object.get_expand_volume_changes(),
                         {"sizeUnit": "bytes", "newRepositorySize": 504 * 1024 * 1024 * 1024})
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
             "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 756, "thin_volume_max_repo_size": 1000,
             "thin_volume_growth_alert_threshold": 90})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"capacity": str(100 * 1024 * 1024 * 1024), "thinProvisioned": True,
                                       "expansionPolicy": "manual",
                                       "currentProvisionedCapacity": str(500 * 1024 * 1024 * 1024)}
        self.assertEqual(volume_object.get_expand_volume_changes(),
                         {"sizeUnit": "bytes", "newRepositorySize": 756 * 1024 * 1024 * 1024})

    def test_get_expand_volume_changes_fail(self):
        """Verify exceptions are thrown."""
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"capacity": str(1000 * 1024 * 1024 * 1024)}
        with self.assertRaisesRegexp(AnsibleFailJson, "Reducing the size of volumes is not permitted."):
            volume_object.get_expand_volume_changes()

        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
             "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 502, "thin_volume_max_repo_size": 1000,
             "thin_volume_growth_alert_threshold": 90})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"capacity": str(100 * 1024 * 1024 * 1024), "thinProvisioned": True,
                                       "expansionPolicy": "manual",
                                       "currentProvisionedCapacity": str(500 * 1024 * 1024 * 1024)}
        with self.assertRaisesRegexp(AnsibleFailJson, "The thin volume repository increase must be between or equal"):
            volume_object.get_expand_volume_changes()

        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
             "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 760, "thin_volume_max_repo_size": 1000,
             "thin_volume_growth_alert_threshold": 90})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"capacity": str(100 * 1024 * 1024 * 1024), "thinProvisioned": True,
                                       "expansionPolicy": "manual",
                                       "currentProvisionedCapacity": str(500 * 1024 * 1024 * 1024)}
        with self.assertRaisesRegexp(AnsibleFailJson, "The thin volume repository increase must be between or equal"):
            volume_object.get_expand_volume_changes()

    def test_create_volume_pass(self):
        """Verify volume creation."""
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.pool_detail = {"id": "12345"}
        with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
            volume_object.create_volume()

        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
             "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 760, "thin_volume_max_repo_size": 1000,
             "thin_volume_growth_alert_threshold": 90})
        volume_object = NetAppESeriesVolume()
        volume_object.pool_detail = {"id": "12345"}
        with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
            volume_object.create_volume()

    def test_create_volume_fail(self):
        """Verify exceptions thrown."""
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.pool_detail = {"id": "12345"}
        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to create volume."):
            with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
                volume_object.create_volume()

        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
             "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 760, "thin_volume_max_repo_size": 1000,
             "thin_volume_growth_alert_threshold": 90})
        volume_object = NetAppESeriesVolume()
        volume_object.pool_detail = {"id": "12345"}
        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to create thin volume."):
            with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
                volume_object.create_volume()

    def test_update_volume_properties_pass(self):
        """verify property update."""
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.pool_detail = {"id": "12345"}
        volume_object.wait_for_volume_availability = lambda: None
        volume_object.get_volume = lambda: {"id": "12345'"}
        volume_object.get_volume_property_changes = lambda: {
            'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True}, 'growthAlertThreshold': 90,
            'flashCached': True}
        volume_object.workload_id = "4200000001000000000000000000000000000000"
        with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
            self.assertTrue(volume_object.update_volume_properties())

        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
             "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 760, "thin_volume_max_repo_size": 1000,
             "thin_volume_growth_alert_threshold": 90})
        volume_object = NetAppESeriesVolume()
        volume_object.pool_detail = {"id": "12345"}
        volume_object.wait_for_volume_availability = lambda: None
        volume_object.get_volume = lambda: {"id": "12345'"}
        volume_object.get_volume_property_changes = lambda: {
            'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True}, 'growthAlertThreshold': 90,
            'flashCached': True}
        volume_object.workload_id = "4200000001000000000000000000000000000000"
        with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
            self.assertTrue(volume_object.update_volume_properties())

        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.pool_detail = {"metadata": [{"key": "workloadId", "value": "12345"}]}
        volume_object.wait_for_volume_availability = lambda: None
        volume_object.get_volume = lambda: {"id": "12345'"}
        volume_object.get_volume_property_changes = lambda: {}
        volume_object.workload_id = "4200000001000000000000000000000000000000"
        self.assertFalse(volume_object.update_volume_properties())

    def test_update_volume_properties_fail(self):
        """Verify exceptions are thrown."""
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.pool_detail = {"id": "12345"}
        volume_object.wait_for_volume_availability = lambda: None
        volume_object.get_volume = lambda: {"id": "12345'"}
        volume_object.get_volume_property_changes = lambda: {
            'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True}, 'growthAlertThreshold': 90,
            'flashCached': True}
        volume_object.workload_id = "4200000001000000000000000000000000000000"
        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to update volume properties."):
            with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
                self.assertTrue(volume_object.update_volume_properties())

        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
             "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 760, "thin_volume_max_repo_size": 1000,
             "thin_volume_growth_alert_threshold": 90})
        volume_object = NetAppESeriesVolume()
        volume_object.pool_detail = {"id": "12345"}
        volume_object.wait_for_volume_availability = lambda: None
        volume_object.get_volume = lambda: {"id": "12345'"}
        volume_object.get_volume_property_changes = lambda: {
            'cacheSettings': {'readCacheEnable': True, 'writeCacheEnable': True}, 'growthAlertThreshold': 90,
            'flashCached': True}
        volume_object.workload_id = "4200000001000000000000000000000000000000"
        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to update thin volume properties."):
            with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
                self.assertTrue(volume_object.update_volume_properties())

    def test_expand_volume_pass(self):
        """Verify volume expansion."""
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.get_expand_volume_changes = lambda: {"sizeUnit": "bytes",
                                                           "expansionSize": 100 * 1024 * 1024 * 1024}
        volume_object.volume_detail = {"id": "12345", "thinProvisioned": True}
        with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
            volume_object.expand_volume()

        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
             "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 760, "thin_volume_max_repo_size": 1000,
             "thin_volume_growth_alert_threshold": 90})
        volume_object = NetAppESeriesVolume()
        volume_object.get_expand_volume_changes = lambda: {"sizeUnit": "bytes",
                                                           "expansionSize": 100 * 1024 * 1024 * 1024}
        volume_object.volume_detail = {"id": "12345", "thinProvisioned": True}
        with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
            volume_object.expand_volume()

    def test_expand_volume_fail(self):
        """Verify exceptions are thrown."""
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.get_expand_volume_changes = lambda: {"sizeUnit": "bytes",
                                                           "expansionSize": 100 * 1024 * 1024 * 1024}
        volume_object.volume_detail = {"id": "12345", "thinProvisioned": False}
        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to expand volume."):
            with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
                volume_object.expand_volume()

        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True})
        volume_object = NetAppESeriesVolume()
        volume_object.get_expand_volume_changes = lambda: {"sizeUnit": "bytes",
                                                           "expansionSize": 100 * 1024 * 1024 * 1024}
        volume_object.volume_detail = {"id": "12345", "thinProvisioned": True}
        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to expand thin volume."):
            with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
                volume_object.expand_volume()

    def test_delete_volume_pass(self):
        """Verify volume deletion."""
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"id": "12345"}
        with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
            volume_object.delete_volume()

        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True,
             "thin_volume_expansion_policy": "manual", "thin_volume_repo_size": 760, "thin_volume_max_repo_size": 1000,
             "thin_volume_growth_alert_threshold": 90})
        volume_object = NetAppESeriesVolume()
        volume_object.volume_detail = {"id": "12345"}
        with mock.patch(self.REQUEST_FUNC, return_value=(200, {})):
            volume_object.delete_volume()

    def test_delete_volume_fail(self):
        """Verify exceptions are thrown."""
        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": False})
        volume_object = NetAppESeriesVolume()
        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to delete volume."):
            with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
                volume_object.delete_volume()

        self._set_args(
            {"state": "present", "name": "Matthew", "storage_pool_name": "pool", "size": 100, "thin_provision": True})
        volume_object = NetAppESeriesVolume()
        with self.assertRaisesRegexp(AnsibleFailJson, "Failed to delete thin volume."):
            with mock.patch(self.REQUEST_FUNC, return_value=Exception()):
                volume_object.delete_volume()