-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_import_vol.py
1076 lines (941 loc) · 58 KB
/
test_import_vol.py
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
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import hpe_3par_kubernetes_manager as manager
from hpe3parclient.exceptions import HTTPBadRequest
from hpe3parclient.exceptions import HTTPForbidden
from hpe3parclient.exceptions import HTTPConflict
from hpe3parclient.exceptions import HTTPNotFound
from time import sleep
import logging
import globals
def test_import_and_clone_sanity():
base_yml = '%s/import_vol/import-vol-base-clone.yml' % globals.yaml_dir
clone_yml = '%s/import_vol/import-vol-clone.yml' % globals.yaml_dir
clone_pvc = None
clone_pod_obj = None
clone_pvc_obj = None
sc = None
pvc = None
pod = None
try:
"""array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(base_yml)
hpe3par_cli = manager.get_3par_cli_client(base_yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(base_yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(base_yml), protocol, manager.get_array_version(hpe3par_cli)))"""
# Create volume in 3par and import it to csi.
logging.getLogger().info("Creating base volume in 3par and importing it to CSI for further cloning...")
volume, secret, sc, pvc, pod = create_import_verify_volume(base_yml, globals.hpe3par_cli, globals.access_protocol, False, True)
# Now create clone of imported volume
logging.getLogger().info("Clone the imported volume...")
clone_pvc = manager.create_pvc(clone_yml)
flag, clone_pvc_obj = manager.check_status(None, clone_pvc.metadata.name, kind='pvc', status='Bound',
namespace=clone_pvc.metadata.namespace)
assert flag is True, "PVC %s status check timed out, clone pvc for imported volume not in Bound state yet..." % \
clone_pvc_obj.metadata.name
logging.getLogger().info("Cloned PVC is Bound")
assert manager.verify_clone_crd_status(clone_pvc_obj.spec.volume_name) is True, \
"Clone PVC CRD is not yet completed"
logging.getLogger().info("Cloned PVC CRD is completed")
clone_pvc_crd = manager.get_pvc_crd(clone_pvc_obj.spec.volume_name)
# logging.getLogger().info(pvc_crd)
clone_volume_name = manager.get_pvc_volume(clone_pvc_crd)
# Now publish cloned pvc
logging.getLogger().info("Publish cloned pvc...")
clone_pod_obj = create_verify_pod(clone_yml, globals.hpe3par_cli, clone_pvc_obj, clone_volume_name, globals.access_protocol,)
logging.getLogger().info("clone_pod_obj :: %s" % clone_pod_obj)
# Delete all kinds now
# delete_resources(hpe3par_cli, secret, sc, pvc, pod, protocol)
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, None, clone_pvc_obj, clone_pod_obj)
cleanup(None, sc, pvc, pod)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_import_cloned_vol():
yml = '%s/import_vol/import-vol-base-clone2.yml' % globals.yaml_dir
sc = None
pvc_obj = None
pod_obj = None
try:
# Create volume
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
hpe3par_version = manager.get_array_version(hpe3par_cli)
logging.getLogger().info("\n########################### test_import_cloned_vol test %s::%s::%s ###########################" %
(str(yml), protocol, hpe3par_version[0:5]))"""
yaml_values = manager.get_details_for_volume(yml)
options = prepare_options(yaml_values, globals.hpe3par_version)
# Create volume in array to be cloned and later imported to csi
vol_name = yaml_values['vol_name']
volume = None
volume, exception = create_vol_in_array(globals.hpe3par_cli, options, vol_name=vol_name, size=yaml_values['size'],
cpg_name=yaml_values['cpg'])
# assert volume is not None, "Volume %s is not created on array as %s. Terminating test." % (vol_name, exception)
if volume is None:
logging.getLogger().info("Volume %s is not created on array as %s. Terminating test." % (vol_name, exception))
return
logging.getLogger().info("Volume %s created successfully on array. Now Create clone..." % volume['name'])
clone_volume, message = create_clone_in_array(globals.hpe3par_cli, source_vol_name=vol_name, option={'online': True, 'tpvv': True})
logging.getLogger().info("Cloned volume is :: %s" % clone_volume)
message = "Clone volume creation on array failed with error %s. Terminating test." % message
assert clone_volume is not None, message
clone_vol_name = clone_volume['name']
# Now import base of the clone to csi
#secret = manager.create_secret(yml)
sc = manager.create_sc(yml)
pvc = manager.create_pvc(yml)
logging.getLogger().info("Check in events if volume is created...")
status, message = manager.check_status_from_events(kind='PersistentVolumeClaim', name=pvc.metadata.name,
namespace=pvc.metadata.namespace, uid=pvc.metadata.uid)
assert status == 'ProvisioningSucceeded', f"{message}"
flag, pvc_obj = manager.check_status(30, pvc.metadata.name, kind='pvc', status='Bound',
namespace=pvc.metadata.namespace)
assert flag is True, "PVC %s for base volume %s status check timed out, not in Bound state yet..." % \
(pvc_obj.metadata.name, vol_name)
logging.getLogger().info("\n\nBase volume (after cloning at array) has been imported successfully to CSI.")
# Compare imported volume object with old volume object on array
pvc_crd = manager.get_pvc_crd(pvc_obj.spec.volume_name)
# logging.getLogger().info(pvc_crd)
imported_volume_name = manager.get_pvc_volume(pvc_crd)
csi_volume = manager.get_volume_from_array(globals.hpe3par_cli, imported_volume_name)
vol_has_diff, diff = compare_volumes(volume, csi_volume)
assert vol_has_diff is False, "After import volume properties are changed. Modified properties are %s" % diff
logging.getLogger().info("\nImported volume's properties have been verified successfully, all property values retain.")
pod_obj = create_verify_pod(yml, globals.hpe3par_cli, pvc_obj, imported_volume_name, globals.access_protocol)
finally:
# Now cleanup secret, sc, pv, pvc, pod
delete_vol_from_array(globals.hpe3par_cli, clone_vol_name)
cleanup(None, sc, pvc_obj, pod_obj)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_thin_true_comp_import_vol():
yml = "%s/import_vol/import-vol-thin-true-comp.yml" % globals.yaml_dir
sc = None
pvc = None
pod = None
try:
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, manager.get_array_version(hpe3par_cli)))"""
volume, secret, sc, pvc, pod = create_import_verify_volume(yml, globals.hpe3par_cli, globals.access_protocol)
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc, pod)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_thin_false_comp_import_vol():
yml = "%s/import_vol/import-vol-thin-false-comp.yml" % globals.yaml_dir
sc = None
pvc = None
pod = None
try:
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, manager.get_array_version(hpe3par_cli)))"""
volume, secret, sc, pvc, pod = create_import_verify_volume(yml, globals.hpe3par_cli, globals.access_protocol)
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc, pod)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_thin_absent_comp_import_vol():
yml = "%s/import_vol/import-vol-thin-absent-comp.yml" % globals.yaml_dir
#hpe3par_cli = None
#secret = None
sc = None
pvc = None
pod = None
try:
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, manager.get_array_version(hpe3par_cli)))"""
volume, secret, sc, pvc, pod = create_import_verify_volume(yml, globals.hpe3par_cli, globals.access_protocol)
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc, pod)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_full_true_comp_import_vol():
yml = "%s/import_vol/import-vol-full-true-comp.yml" % globals.yaml_dir
sc = None
pvc = None
pod = None
try:
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, manager.get_array_version(hpe3par_cli)))"""
volume, secret, sc, pvc, pod = create_import_verify_volume(yml, globals.hpe3par_cli, globals.access_protocol)
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc, pod)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_full_false_comp_import_vol():
yml = "%s/import_vol/import-vol-full-false-comp.yml" % globals.yaml_dir
sc = None
pvc = None
pod = None
try:
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, manager.get_array_version(hpe3par_cli)))"""
volume, secret, sc, pvc, pod = create_import_verify_volume(yml, globals.hpe3par_cli, globals.access_protocol)
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc, pod)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_full_absent_comp_import_vol():
yml = "%s/import_vol/import-vol-full-absent-comp.yml" % globals.yaml_dir
sc = None
pvc = None
pod = None
try:
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, manager.get_array_version(hpe3par_cli)))"""
volume, secret, sc, pvc, pod = create_import_verify_volume(yml, globals.hpe3par_cli, globals.access_protocol)
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc, pod)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_dedup_true_comp_import_vol():
yml = "%s/import_vol/import-vol-dedup-true-comp.yml" % globals.yaml_dir
sc = None
pvc = None
pod = None
try:
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, manager.get_array_version(hpe3par_cli)))"""
volume, secret, sc, pvc, pod = create_import_verify_volume(yml, globals.hpe3par_cli, globals.access_protocol)
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc, pod)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_dedup_false_comp_import_vol():
yml = "%s/import_vol/import-vol-dedup-false-comp.yml" % globals.yaml_dir
sc = None
pvc = None
pod = None
try:
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, manager.get_array_version(hpe3par_cli)))"""
volume, secret, sc, pvc, pod = create_import_verify_volume(yml, globals.hpe3par_cli, globals.access_protocol)
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc, pod)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_dedup_absent_comp_import_vol():
yml = "%s/import_vol/import-vol-dedup-absent-comp.yml" % globals.yaml_dir
sc = None
pvc = None
pod = None
try:
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, manager.get_array_version(hpe3par_cli)))"""
volume, secret, sc, pvc, pod = create_import_verify_volume(yml, globals.hpe3par_cli, globals.access_protocol)
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc, pod)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_diff_snap_usr_cpg_import_vol():
yml = "%s/import_vol/import-vol-diff_snap_usr_cpg.yml" % globals.yaml_dir
sc = None
pvc = None
pod = None
try:
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, manager.get_array_version(hpe3par_cli)))"""
volume, secret, sc, pvc, pod = create_import_verify_volume(yml, globals.hpe3par_cli, globals.access_protocol)
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc, pod)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_exp_ret_set_import_vol():
yml = "%s/import_vol/import-vol-exp-ret-set.yml" % globals.yaml_dir
sc = None
pvc = None
pod = None
try:
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, manager.get_array_version(hpe3par_cli)))"""
volume, secret, sc, pvc, pod = create_import_verify_volume(yml, globals.hpe3par_cli, globals.access_protocol)
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc, pod)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_diff_size_pvc_import_vol():
yml = "%s/import_vol/import-vol-diff-size-in-pvc.yml" % globals.yaml_dir
sc = None
pvc = None
pod = None
vol_name = None
try:
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, manager.get_array_version(hpe3par_cli)))"""
yaml_values = manager.get_details_for_volume(yml)
vol_name = yaml_values['vol_name']
volume, secret, sc, pvc, pod = create_import_verify_volume(yml, globals.hpe3par_cli, globals.access_protocol,
publish=False, pvc_bound=False,
pvc_message='differs in size given in pvc yml')
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc, pod)
delete_vol_from_array(globals.hpe3par_cli, vol_name)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_diff_domain_import_vol():
yml = "%s/import_vol/import-vol-in-domain.yml" % globals.yaml_dir
sc = None
pvc_obj = None
pod = None
secret_other_domain = None
sc_other_domain = None
pvc_other_domain = None
pod_other_domain = None
diff_domain_hpe3par_cli = None
try:
# Create PVC and mount to put this host in a domain
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
hpe3par_version = manager.get_array_version(hpe3par_cli)
logging.getLogger().info("\n########################### test_thin_false_comp_diff_domain_import_vol %s::%s::%s ###########################" %
(str(yml), protocol, hpe3par_version[0:5]))
secret = manager.create_secret(yml)"""
sc = manager.create_sc(yml)
pvc = manager.create_pvc(yml)
logging.getLogger().info("Check in events if volume is created...")
status, message = manager.check_status_from_events(kind='PersistentVolumeClaim', name=pvc.metadata.name,
namespace=pvc.metadata.namespace, uid=pvc.metadata.uid)
assert status == 'ProvisioningSucceeded', f"{message}"
flag, pvc_obj = manager.check_status(30, pvc.metadata.name, kind='pvc', status='Bound',
namespace=pvc.metadata.namespace)
assert flag is True, "PVC %s status check timed out, not in Bound state yet..." % pvc_obj.metadata.name
logging.getLogger().info("\n\nThin-False PVC created and Bound now will mount it to put host in domain")
pvc_crd = manager.get_pvc_crd(pvc_obj.spec.volume_name)
volume_name = manager.get_pvc_volume(pvc_crd)
pod = create_verify_pod(yml, globals.hpe3par_cli, pvc_obj, volume_name, globals.access_protocol)
logging.getLogger().info("Publish done, host belongs to domain now.\nImport a volume now from CPG belongs to different domain")
diff_domain_yml = "%s/import_vol/import-vol-thin-false-comp.yml" % globals.yaml_dir
#diff_domain_hpe3par_cli = manager.get_3par_cli_client(diff_domain_yml)
#diff_domain_array_ip, diff_domain_array_uname, diff_domain_array_pwd, diff_domain_protocol = manager.read_array_prop(diff_domain_yml)
#logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
# (str(diff_domain_yml), diff_domain_protocol, manager.get_array_version(diff_domain_hpe3par_cli)))
volume_other_domain, secret_other_domain, sc_other_domain, pvc_other_domain, pod_other_domain = \
create_import_verify_volume(diff_domain_yml, globals.hpe3par_cli, globals.access_protocol, publish=True,
pvc_bound=True, pod_run=False,
pod_message='Imported volume failed to publsh on different domain as expected.')
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc_obj, pod)
cleanup(secret_other_domain, sc_other_domain, pvc_other_domain, pod_other_domain)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
if diff_domain_hpe3par_cli is not None:
diff_domain_hpe3par_cli.logout()
def test_import_vol_with_other_param():
yml = "%s/import_vol/import-vol-with-other-param.yml" % globals.yaml_dir
hpe3par_cli = None
secret = None
sc = None
pvc = None
pod = None
vol_name = None
try:
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, manager.get_array_version(hpe3par_cli)))"""
yaml_values = manager.get_details_for_volume(yml)
vol_name = yaml_values['vol_name']
volume, secret, sc, pvc, pod = create_import_verify_volume(yml, globals.hpe3par_cli, globals.access_protocol, publish=False, pvc_bound=False,
pvc_message=
'storage class has different parameters set')
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc, pod)
delete_vol_from_array(globals.hpe3par_cli, vol_name)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_import_imported_volume():
yml = "%s/import_vol/import-vol-test-import-imported.yml" % globals.yaml_dir
import_imported_volume(yml, False)
def test_import_exported_volume():
yml = "%s/import_vol/import-vol-test-import-exported.yml" % globals.yaml_dir
import_imported_volume(yml, True)
def test_import_vol_starts_from_pvc():
yml = "%s/import_vol/import-vol-start-from-pvc.yml" % globals.yaml_dir
try:
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, manager.get_array_version(hpe3par_cli)))"""
volume, secret, sc, pvc, pod = create_import_verify_volume(yml, globals.hpe3par_cli, globals.access_protocol, False, False, pvc_message=
'starts with string pvc')
"""status, message, secret, sc, pvc, pod = create_import_verify_volume(yml, False, False)
assert status == 'ProvisioningFailed', "Imported volume name starts from pvc"
logging.getLogger().info(message)"""
finally:
# Now cleanup secret, sc, pv, pvc, pod
if volume is not None:
delete_vol_from_array(globals.hpe3par_cli, volume['name'])
cleanup(None, sc, pvc, pod)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_import_snap_no_base():
try:
yml = "%s/import_vol/import-vol-snap-no-base.yml" % globals.yaml_dir
# Create volume
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
hpe3par_version = manager.get_array_version(hpe3par_cli)
logging.getLogger().info("\n########################### test_import_snap_no_base test %s::%s::%s ###########################" %
(str(yml), protocol, hpe3par_version[0:5]))"""
yaml_values = manager.get_details_for_volume(yml)
options = prepare_options(yaml_values, globals.hpe3par_version)
# Create volume in array to be imported
vol_name = yaml_values['vol_name']
snap_volume = None
volume = None
volume, exception = create_vol_in_array(globals.hpe3par_cli, options, vol_name=vol_name, size=yaml_values['size'], cpg_name=yaml_values['cpg'])
# assert volume is not None, "Volume %s is not created on array as %s. Terminating test." % (vol_name, exception)
if volume is None:
logging.getLogger().info("Volume %s is not created on array as %s. Terminating test." % (vol_name, exception))
return
logging.getLogger().info("Volume %s created successfully on array. Now Create snapshot..." % volume['name'])
snap_volume, message = create_snapshot_in_array(globals.hpe3par_cli, None, snap_name='snap-of-%s' % vol_name, vol_name=vol_name)
logging.getLogger().info("Snapshot volume is :: %s" % snap_volume)
# Now import this snap volume to csi without importing base volume
#secret = manager.create_secret(yml)
sc = manager.create_sc(yml)
pvc = manager.create_pvc(yml)
logging.getLogger().info("Check in events if volume is created...")
status, message = manager.check_status_from_events(kind='PersistentVolumeClaim', name=pvc.metadata.name,
namespace=pvc.metadata.namespace, uid=pvc.metadata.uid)
assert status == 'ProvisioningFailed', "Imported snap volume %s without importing base %s)" % (snap_volume, vol_name)
logging.getLogger().info("\n\nCould not import snap volume before importing base, as expected.")
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc, None)
delete_vol_from_array(globals.hpe3par_cli, snap_volume['name'])
delete_vol_from_array(globals.hpe3par_cli, volume['name'])
"""if snap_volume is not None:
hpe3par_cli.deleteVolume(snap_volume['name'])
if volume is not None:
hpe3par_cli.deleteVolume(volume['name'])"""
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def test_create_snap_import_both_publish_base():
base_yml = "%s/import_vol/import-vol-base-snap.yml" % globals.yaml_dir
snap_yml = "%s/import_vol/import-vol-snap-of-base.yml" % globals.yaml_dir
create_vol_snap_import_publish(base_yml, snap_yml, mount_base='after_snap')
def test_create_snap_import_publish_base_import_snap():
base_yml = "%s/import_vol/import-vol-base-snap.yml" % globals.yaml_dir
snap_yml = "%s/import_vol/import-vol-snap-of-base.yml" % globals.yaml_dir
create_vol_snap_import_publish(base_yml, snap_yml, mount_base='before_snap')
def test_snap_name_starts_with_snapshot():
base_yml = "%s/import_vol/import-vol-base-for-snap-start-with-snapshot.yml" % globals.yaml_dir
snap_yml = "%s/import_vol/import-vol-snap-name-start-with-snapshot.yml" % globals.yaml_dir
create_vol_snap_import_publish(base_yml, snap_yml, first_snap_import='fail')
def create_vol_snap_import_publish(base_yml, snap_yml, first_snap_import='pass', create_second_snap=False, mount_base='after_snap'):
base_secret = None
base_sc = None
base_pvc_obj = None
base_pod = None
snap_secret = None
snap_sc = None
snap_pvc = None
snap_class_name = None
snapshot_name = None
try:
# Create base volume
"""hpe3par_cli = manager.get_3par_cli_client(base_yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(base_yml)
hpe3par_version = manager.get_array_version(hpe3par_cli)
logging.getLogger().info("\n########################### test_import_base_and_snap test %s::%s::%s ###########################" %
(str(base_yml), protocol, hpe3par_version[0:5]))"""
base_yaml_values = manager.get_details_for_volume(base_yml)
base_options = prepare_options(base_yaml_values, globals.hpe3par_version)
# Create volume in array to be imported
base_vol_name = base_yaml_values['vol_name']
volume, exception = create_vol_in_array(globals.hpe3par_cli, base_options, vol_name=base_vol_name, size=base_yaml_values['size'],
cpg_name=base_yaml_values['cpg'])
assert volume is not None, f"{exception}"
"""if volume is None:
logging.getLogger().info("Volume %s is not created on array as %s. Terminating test." % (base_vol_name, exception))
return"""
# Now create snap volume and import
logging.getLogger().info("\n\nVolume %s created successfully on array. Now Create snapshot..." % volume['name'])
#snap_yml = "YAML/import_vol/import-vol-snap-of-base.yml"
snap_yaml_values = manager.get_details_for_volume(snap_yml)
snap_options = prepare_options(snap_yaml_values, globals.hpe3par_version)
# Create snapshot in array to be imported
snap_vol_name = snap_yaml_values['vol_name']
snap_volume, message = create_snapshot_in_array(globals.hpe3par_cli, None, snap_name=snap_vol_name, vol_name=base_vol_name)
logging.getLogger().info("Snapshot volume is :: %s" % snap_volume)
# Import base volume to csi
logging.getLogger().info("Importing base volume to CSI...")
#base_secret = manager.create_secret(base_yml)
base_sc = manager.create_sc(base_yml)
base_pvc = manager.create_pvc(base_yml)
logging.getLogger().info("Check in events if volume is created...")
base_status, base_message = manager.check_status_from_events(kind='PersistentVolumeClaim', name=base_pvc.metadata.name,
namespace=base_pvc.metadata.namespace, uid=base_pvc.metadata.uid)
assert base_status == 'ProvisioningSucceeded', f"{base_message}"
logging.getLogger().info("\n\nImported base volume successfully to CSI, now import snap")
# Publish base if is to be done before snapshot import
if mount_base == 'before_snap':
logging.getLogger().info("Now publish base volume that is imported to csi...")
base_pvc_obj = manager.hpe_read_pvc_object(base_pvc.metadata.name, base_pvc.metadata.namespace)
base_pvc_crd = manager.get_pvc_crd(base_pvc_obj.spec.volume_name)
# logging.getLogger().info(pvc_crd)
base_imported_volume_name = manager.get_pvc_volume(base_pvc_crd)
base_pod = create_verify_pod(base_yml, globals.hpe3par_cli, base_pvc_obj, base_imported_volume_name, globals.access_protocol)
logging.getLogger().info("Imported base volume is published successfully")
# Import snap volume to csi
logging.getLogger().info("Now importing snap to CSI...")
# Create snapclass
logging.getLogger().info("Creating Snapclass now...")
snap_class_yml = "%s/import_vol/import-vol-snapshot-class.yml" % globals.yaml_dir
snap_class_name = manager.get_kind_name(snap_class_yml, 'VolumeSnapshotClass')
assert manager.create_snapclass(snap_class_yml, snap_class_name) is True, \
'Snapclass %s is not created.' % snap_class_name
logging.getLogger().info('Snapclass %s is created successfully.' % snap_class_name)
assert manager.verify_snapclass_created(snap_class_name) is True, \
'Snapclass %s is not found in crd list.' % snap_class_name
logging.getLogger().info('Verified snapclass %s in crd list.' % snap_class_name)
# Create snapshot
logging.getLogger().info("Creating snapshot now...")
snapshot_yml = "%s/import_vol/import-vol-snapshot.yml" % globals.yaml_dir
snapshot_name = manager.get_kind_name(snapshot_yml, 'VolumeSnapshot')
#assert manager.create_snapshot(snapshot_yml, snapshot_name) is True, 'Snapshot %s is not created.' % snapshot_name
#logging.getLogger().info('Snapshot %s is created successfully.' % snapshot_name)
manager.create_snapshot(snapshot_yml, snapshot_name)
assert manager.verify_snapshot_created(snapshot_name) is True, 'Snapshot %s is not found in crd list.' % \
snapshot_name
logging.getLogger().info('Verified snapshot %s in crd list.' % snapshot_name)
# Verify if snapshot ready to use
flag, snap_uid = manager.verify_snapshot_ready(snapshot_name)
if first_snap_import == 'fail':
assert flag is False, "Snapshot %s is ready to use" % snapshot_name
logging.getLogger().info("\n\nSnapshot %s creation failed as expected." % snapshot_name)
else:
assert flag is True, "Snapshot %s is not ready to use" % snapshot_name
logging.getLogger().info('\n\nVerified snapshot %s is ready to use.' % snapshot_name)
snap_pvc_uid = "snapshot-" + snap_uid
csi_snap_volume = manager.get_volume_from_array(globals.hpe3par_cli, snap_pvc_uid[0:31])
vol_has_diff, diff = compare_volumes(snap_volume, csi_snap_volume)
assert vol_has_diff is False, "After import snap volume properties are changed. Modified properties are %s" % \
diff
logging.getLogger().info("\nImported snapshot's properties have been verified successfully, all property values retain.")
if mount_base == 'after_snap':
logging.getLogger().info("Now publish base volume that is imported to csi...")
base_pvc_obj = manager.hpe_read_pvc_object(base_pvc.metadata.name, base_pvc.metadata.namespace)
base_pvc_crd = manager.get_pvc_crd(base_pvc_obj.spec.volume_name)
# logging.getLogger().info(pvc_crd)
base_imported_volume_name = manager.get_pvc_volume(base_pvc_crd)
base_pod = create_verify_pod(base_yml, globals.hpe3par_cli, base_pvc_obj, base_imported_volume_name, globals.access_protocol)
logging.getLogger().info("Imported base volume is published successfully")
"""snap_secret = manager.create_secret(snap_yml)
snap_sc = manager.create_sc(snap_yml)
snap_pvc = manager.create_pvc(snap_yml)
logging.getLogger().info("Check in events if snap volume is created...")
snap_status, snap_message = manager.check_status_from_events(kind='PersistentVolumeClaim', name=snap_pvc.metadata.name,
namespace=snap_pvc.metadata.namespace, uid=snap_pvc.metadata.uid)
assert snap_status == 'ProvisioningSucceeded', f"{snap_message}"
logging.getLogger().info("\n\nImported snap volume successfully to CSI, now publish")
# Publish base volume imported to csi
flag, base_pvc_obj = manager.check_status(30, base_pvc.metadata.name, kind='pvc', status='Bound',
namespace=base_pvc.metadata.namespace)
base_pvc_crd = manager.get_pvc_crd(base_pvc_obj.spec.volume_name)
# logging.getLogger().info(pvc_crd)
base_imported_volume_name = manager.get_pvc_volume(base_pvc_crd)
base_pod = create_verify_pod(
base_yml, hpe3par_cli, base_pvc_obj, base_imported_volume_name, protocol)"""
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, snap_sc, snap_pvc, None)
cleanup_crd(snapshot_name, snap_class_name)
cleanup(None, base_sc, base_pvc_obj, base_pod)
#if hpe3par_cli is not None:
# hpe3par_cli.logout()
def prepare_options(yaml_values, hpe3par_version):
options = {}
if 'comment' in yaml_values.keys():
options['comment'] = yaml_values['comment']
if 'snapCPG' in yaml_values.keys():
options['snapCPG'] = yaml_values['snapCPG']
if yaml_values['provisioning'] == "tpvv":
options['tpvv'] = True
if yaml_values['provisioning'] == "dedup":
options['tdvv'] = True
if yaml_values['provisioning'] == "reduce":
options['tdvv'] = True
if 'compression' in yaml_values.keys():
if yaml_values['compression'] is True or yaml_values['compression'] == 'true':
options['compression'] = True
if yaml_values['compression'] is False or yaml_values['compression'] == 'false':
options['compression'] = False
return options
def import_imported_volume(yml, publish):
secret = None
sc = None
pvc = None
pod = None
sc_with_imported_vol = None
pvc_with_imported_vol = None
try:
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, manager.get_array_version(hpe3par_cli)))"""
# Import volume for 1st time
volume, secret, sc, pvc, pod = create_import_verify_volume(yml, globals.hpe3par_cli, globals.access_protocol, publish)
logging.getLogger().info("SC :: %s\nPVC :: %s\nPOD :: %s" % (sc, pvc, pod))
# Fetch name of the volume after import
pvc_crd = manager.get_pvc_crd(pvc.spec.volume_name)
# logging.getLogger().info(pvc_crd)
imported_volume_name = manager.get_pvc_volume(pvc_crd)
logging.getLogger().info("Modifying yml for storage class and pvc for import_vol and name")
# Modify yml and provide renamed volume for import_vol param in sc
yml_list = modify_in_mem_yml(yml, imported_volume_name)
logging.getLogger().info("modified yml :: %s" % yml_list)
pvc_with_imported_vol = None
# Create sc and pvc
for kind in yml_list:
if str(kind.get('kind')) == 'StorageClass':
sc_with_imported_vol = manager.hpe_create_sc_object(kind)
logging.getLogger().info(sc_with_imported_vol)
if str(kind.get('kind')) == 'PersistentVolumeClaim':
pvc_with_imported_vol = manager.hpe_create_pvc_object(kind)
logging.getLogger().info(pvc_with_imported_vol)
logging.getLogger().info("PVC with imported volume :: %s " % pvc_with_imported_vol)
logging.getLogger().info("Check in events if volume provisioning status...")
status, message = manager.check_status_from_events(kind='PersistentVolumeClaim', name=pvc_with_imported_vol.metadata.name,
namespace=pvc_with_imported_vol.metadata.namespace, uid=pvc_with_imported_vol.metadata.uid)
assert status != 'ProvisioningSucceeded', "Import succeeded for already imported volume %s" % imported_volume_name
logging.getLogger().info("\n\nProvisioning failed for PVC with already imported volume %s. Error is %s " % (imported_volume_name,message))
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc, pvc, pod)
cleanup(None, sc_with_imported_vol, pvc_with_imported_vol, None)
except Exception as e:
logging.getLogger().info("Exception in test_import_imported_volume :: %s" % e)
#logging.error("Exception in test_publish :: %s" % e)
raise e
finally:
cleanup(None, sc, pvc, pod)
cleanup(None, sc_with_imported_vol, pvc_with_imported_vol, None)
def modify_in_mem_yml(yml, new_vol_name, suffix='new'):
import yaml
obj = None
with open(yml) as f:
elements = list(yaml.safe_load_all(f))
for el in elements:
# logging.getLogger().info("======== kind :: %s " % str(el.get('kind')))
"""if str(el.get('kind')) == to_be_modified['kind']:
for key in to_be_modified.keys():
if key == 'kind':
continue
if len(key.keys()) == 0:
el[key] = to_be_modified['kind'][key]
else:
for key1 in key.keys():
len(key1.keys()) == 0:
e1['parameters']['importVol'] = to_be_modified['value']
HPE3PAR_IP = el['stringData']['backend']
# logging.getLogger().info("PersistentVolume YAML :: %s" % el)
logging.getLogger().info("\nCreating StorageClass...")
obj = hpe_create_sc_object(el)
logging.getLogger().info("\nStorageClass %s created." % obj.metadata.name)"""
if str(el.get('kind')) == 'StorageClass':
el['parameters']['importVolumeName'] = new_vol_name
el['metadata']['name'] = el['metadata']['name'] + "-%s" % suffix
if str(el.get('kind')) == 'PersistentVolumeClaim':
el['spec']['storageClassName'] = el['spec']['storageClassName'] + "-%s" % suffix
el['metadata']['name'] = el['metadata']['name'] + "-%s" % suffix
return elements
def create_import_verify_volume(yml, hpe3par_cli, protocol, publish=True, pvc_bound=True, pvc_message='', pod_run=True, pod_message=''):
secret = None
sc = None
pvc_obj = None
pod_obj = None
volume = None
# Create volume
"""hpe3par_cli = manager.get_3par_cli_client(yml)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(yml)
hpe3par_version = manager.get_array_version(hpe3par_cli)
logging.getLogger().info("\n########################### Import volume test %s::%s::%s ###########################" %
(str(yml), protocol, hpe3par_version[0:5]))"""
hpe3par_version = manager.get_array_version(hpe3par_cli)
yaml_values = manager.get_details_for_volume(yml)
if yaml_values['provisioning'].lower() == 'full' and hpe3par_version[0:1] == '4':
logging.getLogger().info("Full Provisioning not supported on primera. Terminating test.")
return None, None, None, None, None
options = prepare_options(yaml_values, hpe3par_version)
# Create volume in array to be imported
logging.getLogger().info("Options to 3par cli for creating volume :: %s " % options)
volume, exception = create_vol_in_array(hpe3par_cli, options, vol_name=yaml_values['vol_name'],
size=yaml_values['size'], cpg_name=yaml_values['cpg'])
# assert volume is not None, "Volume %s is not created on array as %s. Terminating test." % (vol_name, exception)
if volume is None:
logging.getLogger().info("Volume %s is not created on array as %s. Terminating test." % (yaml_values['vol_name'], exception))
return None, None, None, None, None
logging.getLogger().info("Volume %s created successfully on array. Now import it to CSI..." % volume['name'])
# Import volume now in CSI
#secret = manager.create_secret(yml)
sc = manager.create_sc(yml)
pvc = manager.create_pvc(yml)
logging.getLogger().info("Check in events if volume is created...")
status, message = manager.check_status_from_events(kind='PersistentVolumeClaim', name=pvc.metadata.name,
namespace=pvc.metadata.namespace, uid=pvc.metadata.uid)
#logging.getLogger().info(status)
#logging.getLogger().info(message)
if pvc_bound:
assert status == 'ProvisioningSucceeded', f"{message}"
flag, pvc_obj = manager.check_status(30, pvc.metadata.name, kind='pvc', status='Bound',
namespace=pvc.metadata.namespace)
assert flag is True, "PVC %s status check timed out, not in Bound state yet..." % pvc_obj.metadata.name
# Compare imported volume object with old volume object on array
pvc_crd = manager.get_pvc_crd(pvc_obj.spec.volume_name)
# logging.getLogger().info(pvc_crd)
imported_volume_name = manager.get_pvc_volume(pvc_crd)
csi_volume = manager.get_volume_from_array(hpe3par_cli, imported_volume_name)
vol_has_diff, diff = compare_volumes(volume, csi_volume)
assert vol_has_diff is False, "After import volume properties are changed. Modified properties are %s" % diff
logging.getLogger().info("\nImported volume's properties have been verified successfully, all property values retain.")
else:
pvc_obj = pvc
"""assert status == 'ProvisioningFailed', "Imported volume that starts from PVC (%s)" % yaml_values['vol_name']
logging.getLogger().info("\n\nCould not import volume starts with PVC, as expected.")"""
assert status == 'ProvisioningFailed', "Imported volume that %s" % pvc_message
logging.getLogger().info("\n\nCould not import volume %s, as expected." % pvc_message)
# return status, "\n\nCould not import volume starts with PVC, as expected.", secret, pvc_obj, None
# Now publish this volume and verify vluns
if publish is True:
if protocol is None: # not specified at command line
# read it from sc yml
protocol = manager.read_protocol(yml)
pod_obj = create_verify_pod(yml, hpe3par_cli, pvc_obj, imported_volume_name, protocol, pod_run, pod_message)
return volume, secret, sc, pvc_obj, pod_obj
def create_verify_pod(yml, hpe3par_cli, pvc_obj, imported_volume_name, protocol, pod_run=True, pod_message=''):
pod = manager.create_pod(yml)
flag, pod_obj = manager.check_status(None, pod.metadata.name, kind='pod', status='Running',
namespace=pod.metadata.namespace)
logging.getLogger().info("pod_run :: %s " % pod_run)
logging.getLogger().info("pod_message :: %s " % pod_message)
logging.getLogger().info("hpe3par_cli :: %s " % hpe3par_cli)
logging.getLogger().info("flag :: %s " % flag)
#logging.getLogger().info("pod_obj :: %s " % pod_obj)
#logging.getLogger().info("pvc_obj :: %s " % pvc_obj)
if pod_run:
assert flag is True, "Published imported volume via pod %s, but it is not in Running state yet..." % pod.metadata.name
else:
assert flag is False
logging.getLogger().info(pod_message)
return pod_obj
# Verify crd fpr published status
assert manager.verify_pvc_crd_published(pvc_obj.spec.volume_name) is True, \
"PVC CRD %s Published is false after Pod is running" % pvc_obj.spec.volume_name
logging.getLogger().info("PVC CRD %s Published is True after Pod is running" % pvc_obj.spec.volume_name)
hpe3par_vlun = manager.get_3par_vlun(hpe3par_cli, imported_volume_name)
assert manager.verify_pod_node(hpe3par_vlun, pod_obj) is True, \
"Node for pod received from 3par and cluster do not match"
logging.getLogger().info("Node for pod received from 3par and cluster do match")
# verify_vlun(hpe3par_cli, hpe3par_vlun, pod_obj, protocol)
return pod_obj
def verify_vlun(hpe3par_cli, hpe3par_vlun, pod_obj, protocol):
pvc_name = pod_obj.spec.volumes[0].persistent_volume_claim.claim_name
logging.getLogger().info("\n\nPVC is :: %s " % pvc_name)
volume_name = manager.hpe_read_pvc_object(pvc_name, globals.namespace).spec.volume_name
logging.getLogger().info("volume_name is :: %s " % volume_name)
pvc_crd = manager.get_pvc_crd(volume_name)
iscsi_ips = manager.get_iscsi_ips(hpe3par_cli)
flag, disk_partition = manager.verify_by_path(iscsi_ips, pod_obj.spec.node_name, pvc_crd, hpe3par_vlun)
assert flag is True, "partition not found"
logging.getLogger().info("disk_partition received are %s " % disk_partition)
flag, disk_partition_mod, partition_map = manager.verify_multipath(hpe3par_vlun, disk_partition)
assert flag is True, "multipath check failed"
logging.getLogger().info("disk_partition after multipath check are %s " % disk_partition)
logging.getLogger().info("disk_partition_mod after multipath check are %s " % disk_partition_mod)
assert manager.verify_partition(disk_partition_mod), "partition mismatch"
assert manager.verify_lsscsi(pod_obj.spec.node_name, disk_partition), "lsscsi verificatio failed"
def compare_volumes(vol1, vol2):
logging.getLogger().info("In compare_volumes()")
logging.getLogger().info("vol1 :: %s" % vol1)
logging.getLogger().info("vol2 :: %s" % vol2)
flag = False
diff_keys = {}
try:
for key, value in vol1.items():
# if key == 'name' or key == 'links':
# continue
if key not in ['deduplicationState', 'compressionState', 'provisioningType', 'copyType', 'wwn', 'userCPG',
'snapCPG']:
continue
if key in vol2 and vol1[key] != vol2[key]:
diff_keys[key] = value
flag = True
return flag, diff_keys
except Exception as e:
logging.getLogger().info("Exception in compare_volumes :: %s" % e)
#logging.error("Exception in test_publish :: %s" % e)
raise e
def create_vol_in_array(hpe3par_cli, options, vol_name='test-importVol', cpg_name='CI_CPG', size=10240):
try:
logging.getLogger().info("In create_vol_in_array() :: vol_name :: %s, cpg_name :: %s, size :: %s, options :: %s" % (vol_name,
cpg_name, size, options))
response = hpe3par_cli.createVolume(vol_name, cpg_name, size, options)
logging.getLogger().info("Create volume response %s" % response)
volume = manager.get_volume_from_array(hpe3par_cli, vol_name)
return volume, None
except (HTTPConflict, HTTPBadRequest, HTTPForbidden) as e:
logging.getLogger().info("Exception from create_vol_in_array :: %s " % e)
return None, e
except Exception as e:
logging.getLogger().info("Exception in create_vol_in_array :: %s" % e)
#logging.error("Exception in test_publish :: %s" % e)
raise e
def create_snapshot_in_array(hpe3par_cli, options, snap_name='snap-test-importVol', vol_name='test-importVol'):
try:
logging.getLogger().info("In create_snapshot_in_array() :: snap_name :: %s, vol_name :: %s" % (snap_name, vol_name))
response = hpe3par_cli.createSnapshot(snap_name, vol_name)
logging.getLogger().info("Create volume response\n%s" % response)
snap_volume = manager.get_volume_from_array(hpe3par_cli, snap_name)
return snap_volume, None
except (HTTPConflict, HTTPForbidden) as e:
logging.getLogger().info("Exception from create_snapshot_in_array :: %s " % e)
return None, e
except Exception as e:
logging.getLogger().info("Exception in create_snapshot_in_array :: %s" % e)
#logging.error("Exception in test_publish :: %s" % e)
raise e
def create_clone_in_array(hpe3par_cli, source_vol_name='test-importVol', dest_vol_name=None, dest_cpg='CI_CPG', option=None):
try:
if dest_vol_name is None or dest_vol_name == '':
dest_vol_name = 'clone-%s' % source_vol_name
logging.getLogger().info("In create_clone_in_array() :: source_vol_name :: %s, dest_vol_name :: %s, dest_cpg :: %s, option :: %s" %
(source_vol_name, dest_vol_name, dest_cpg, option))
response = hpe3par_cli.copyVolume(source_vol_name, dest_vol_name, dest_cpg, option)
logging.getLogger().info("Create clone response\n%s" % response)
clone_volume = manager.get_volume_from_array(hpe3par_cli, dest_vol_name)
return clone_volume, None
except (HTTPConflict, HTTPForbidden, HTTPBadRequest) as e:
logging.getLogger().info("Exception from create_clone_in_array :: %s " % e)
return None, e
except Exception as e:
logging.getLogger().info("Exception in create_clone_in_array :: %s" % e)
#logging.
def delete_vol_from_array(hpe3par_cli, vol_name):
try:
logging.getLogger().info("In delete_vol_from_array() :: vol_name :: %s" % vol_name)
volume = manager.get_volume_from_array(hpe3par_cli, vol_name)
if volume is not None:
hpe3par_cli.deleteVolume(vol_name)
except (HTTPConflict, HTTPNotFound, HTTPForbidden) as e:
logging.getLogger().info("Exception from delete_vol_from_array :: %s " % e)
except Exception as e:
logging.getLogger().info("Exception in delete_vol_from_array :: %s" % e)
#logging.error("Exception in test_publish :: %s" % e)
raise e
def cleanup(secret, sc, pvc, pod):
logging.getLogger().info("====== cleanup :START =========")
#logging.info("====== cleanup after failure:START =========")
logging.getLogger().info("pod :: %s, pvc :: %s, sc :: %s" % (pod, pvc, sc))
if pod is not None and manager.check_if_deleted(2, pod.metadata.name, "Pod", namespace=pod.metadata.namespace) is False:
manager.delete_pod(pod.metadata.name, pod.metadata.namespace)
if pvc is not None and manager.check_if_deleted(2, pvc.metadata.name, "PVC", namespace=pvc.metadata.namespace) is False:
manager.delete_pvc(pvc.metadata.name)
"""assert manager.check_if_crd_deleted(pvc.spec.volume_name, "hpevolumeinfos") is True, \
"CRD %s of %s is not deleted yet. Taking longer..." % (pvc.spec.volume_name, 'hpevolumeinfos')"""
flag = manager.check_if_crd_deleted(pvc.spec.volume_name, "hpevolumeinfos")
if flag is False:
logging.getLogger().error("CRD %s of %s is not deleted yet. Taking longer..." % (pvc.spec.volume_name, 'hpevolumeinfos'))
if sc is not None and manager.check_if_deleted(2, sc.metadata.name, "SC", sc.metadata.namespace) is False:
manager.delete_sc(sc.metadata.name)
"""if secret is not None and manager.check_if_deleted(2, secret.metadata.name, "Secret", namespace=secret.metadata.namespace) is False:
manager.delete_secret(secret.metadata.name, secret.metadata.namespace)"""
logging.getLogger().info("====== cleanup :END =========")