-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_volumeGroup.py
1201 lines (969 loc) · 52.5 KB
/
test_volumeGroup.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
import time
import yaml
import pytest
import random
import globals
import logging
timeout = globals.status_check_timeout
pvc_list = []
pod_list = []
# C547899: associate the created volume to volumegroup
def test_volume_group_test_1_sanity():
yml = '%s/volume_group/sc_vg.yaml' % globals.yaml_dir
volGrp = '%s/volume_group/volume-group.yaml' % globals.yaml_dir
volGrpClass = '%s/volume_group/volume-group-class.yml' % globals.yaml_dir
sc = None
pvc = None
pod = None
isFilePresent = False
try:
with open(volGrp, "r") as ymlfile:
elements = list(yaml.safe_load_all(ymlfile))
for el in elements:
if str(el.get('kind')) == "VolumeGroup":
volGrp_name = el['metadata']['name']
break
logging.getLogger().info("Creating volume group class and volume group")
command = 'kubectl create -f ' + volGrpClass
resp = manager.get_command_output_string(command)
assert "create" in resp, "volume group not created"
command = 'kubectl create -f ' + volGrp
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group class not created"
command = 'kubectl describe volumegroup ' + volGrp_name + ' -n ' +globals.namespace
resp = manager.get_command_output_string(command)
# Getting volumegroup uid
id = [s for s in resp.split('\n') if "UID" in s]
volGrp_uid = id[0].split()[1][:27]
# Checking in array if volume group is created
isPresent = volume_group_create_status(volGrp_uid)
assert isPresent is True , "Volume group not created on array"
logging.getLogger().info("Volume group {0} created on array".format(volGrp_uid))
# Creating sc and pvc
sc = manager.create_sc(yml)
pvc = manager.create_pvc(yml)
logging.getLogger().info("Check in events if volume is created...")
flag, base_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..." % base_pvc_obj.metadata.name
yaml_values = manager.get_details_for_volume(volGrp)
vol_grp_name = yaml_values['name']
volume_name = base_pvc_obj.spec.volume_name[:31]
logging.getLogger().info("Adding pvc {0} to volume group {1} ".format(pvc.metadata.name, vol_grp_name))
body = { 'metadata': { 'annotations': { 'csi.hpe.com/volume-group' : vol_grp_name} } }
patched_pvc_obj = manager.patch_pvc(pvc.metadata.name,globals.namespace,body)
# Checking in array if pvc is added to volume group
is_pvc_added = pvc_add_status(volGrp_uid, volume_name)
assert is_pvc_added is True, "Pvc not added to volume group"
logging.getLogger().info("pvc {0} added to volume group {1} ".format(pvc.metadata.name, vol_grp_name))
time.sleep(10)
# Export base volume
pod = manager.create_pod(yml)
flag, base_pod_obj = manager.check_status(timeout, pod.metadata.name, kind='pod', status='Running',
namespace=pod.metadata.namespace)
assert flag is True, "Pod %s status check timed out, not in Running state yet..." % pod.metadata.name
time.sleep(20)
# Checking base volume data
command = ['/bin/sh', '-c', 'ls -l /export']
data = manager.hpe_connect_pod_container(pod.metadata.name, command)
if any("mynewdata.txt" in x for x in data.split('\n')):
isFilePresent = True
assert isFilePresent is True, "File not present in base volume"
logging.getLogger().info("File is present in base volume")
except Exception as e:
logging.getLogger().error("Exception :: %s" % e)
raise e
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(sc, pvc, pod)
cleanup_volume_group(volGrp, volGrpClass, volGrp_uid)
#C547902 Delete volumegroup without removing pvc/volume
def test_volume_group_test_5():
yml = '%s/volume_group/sc_vg.yaml' % globals.yaml_dir
volGrp = '%s/volume_group/volume-group.yaml' % globals.yaml_dir
volGrpClass = '%s/volume_group/volume-group-class.yml' % globals.yaml_dir
sc = None
pvc = None
pod = None
isFilePresent = False
try:
with open(volGrp, "r") as ymlfile:
elements = list(yaml.safe_load_all(ymlfile))
for el in elements:
if str(el.get('kind')) == "VolumeGroup":
volGrp_name = el['metadata']['name']
break
logging.getLogger().info("Creating volume group and volume group class")
command = 'kubectl create -f ' + volGrpClass
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group not created"
command = 'kubectl create -f ' + volGrp
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group class not created"
command = 'kubectl describe volumegroup ' + volGrp_name + ' -n ' +globals.namespace
resp = manager.get_command_output_string(command)
# Getting volumegroup uid
id = [s for s in resp.split('\n') if "UID" in s]
volGrp_uid = id[0].split()[1][:27]
#Checking in array if volume group is created
isPresent = volume_group_create_status(volGrp_uid)
assert isPresent is True, "Volume group not created on array"
logging.getLogger().info("Volume group {0} created on array".format(volGrp_uid))
#Creating sc and pvc
sc = manager.create_sc(yml)
pvc = manager.create_pvc(yml)
logging.getLogger().info("Check in events if volume is created...")
flag, base_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..." % base_pvc_obj.metadata.name
yaml_values = manager.get_details_for_volume(volGrp)
vol_grp_name = yaml_values['name']
volume_name = base_pvc_obj.spec.volume_name[:31]
body = { 'metadata': { 'annotations': { 'csi.hpe.com/volume-group' : vol_grp_name} } }
patched_pvc_obj = manager.patch_pvc(pvc.metadata.name,globals.namespace,body)
# Checking in array if pvc is added to volume group
is_pvc_added = pvc_add_status(volGrp_uid, volume_name)
assert is_pvc_added is True, "Pvc not added to volume group"
logging.getLogger().info("Pvc {0} added to volume group {1}".format(pvc.metadata.name, vol_grp_name))
time.sleep(10)
# Export base volume
pod = manager.create_pod(yml)
flag, base_pod_obj = manager.check_status(timeout, pod.metadata.name, kind='pod', status='Running',
namespace=pod.metadata.namespace)
assert flag is True, "Pod %s status check timed out, not in Running state yet..." % pod.metadata.name
# Checking base volume data
command = ['/bin/sh', '-c', 'ls -l /export']
data = manager.hpe_connect_pod_container(pod.metadata.name, command)
if any("mynewdata.txt" in x for x in data.split('\n')):
isFilePresent = True
assert isFilePresent is True, "File not present in base volume"
# Deleting created resources
manager.hpe_delete_pod_object_by_name(base_pod_obj.metadata.name, base_pod_obj.metadata.namespace)
flag = manager.check_if_deleted(180, base_pod_obj.metadata.name, "Pod", namespace=base_pod_obj.metadata.namespace)
assert flag is True, "POD %s delete status check timedout..." % base_pod_obj.metadata.name
command = 'kubectl delete -f ' + volGrp
resp = manager.get_command_output_string(command)
assert "deleted" in resp, "volume group not deleted"
isDeleted = volume_group_delete_status(volGrp_uid)
assert isDeleted is True, "Volume group not deleted on array"
command = 'kubectl delete -f ' + volGrpClass
resp = manager.get_command_output_string(command)
assert "deleted" in resp, "volume group class not deleted"
except Exception as e:
logging.getLogger().error("Exception :: %s" % e)
raise e
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(sc, pvc, pod)
#C547901 Delete a pvc/volume and dis-associate it from volumegroup by deleting pvc/volume
def test_volume_group_test_2():
yml = '%s/volume_group/sc_vg.yaml' % globals.yaml_dir
volGrp = '%s/volume_group/volume-group.yaml' % globals.yaml_dir
volGrpClass = '%s/volume_group/volume-group-class.yml' % globals.yaml_dir
sc = None
pvc = None
pod = None
isFilePresent = False
try:
with open(volGrp, "r") as ymlfile:
elements = list(yaml.safe_load_all(ymlfile))
for el in elements:
if str(el.get('kind')) == "VolumeGroup":
volGrp_name = el['metadata']['name']
break
logging.getLogger().info("Creating volume group class and volume group")
command = 'kubectl create -f ' + volGrpClass
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group not created"
command = 'kubectl create -f ' + volGrp
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group class not created"
command = 'kubectl describe volumegroup ' + volGrp_name + ' -n ' +globals.namespace
resp = manager.get_command_output_string(command)
#Getting volumegroup uid
id = [s for s in resp.split('\n') if "UID" in s]
volGrp_uid = id[0].split()[1][:27]
#Checking in array if volume group is created
isPresent = volume_group_create_status(volGrp_uid)
assert isPresent is True, "Volume group not created on array"
logging.getLogger().info("Volume group {0} created on array".format(volGrp_uid))
# Creating sc and pvc
sc = manager.create_sc(yml)
pvc = manager.create_pvc(yml)
logging.getLogger().info("Check in events if volume is created...")
flag, base_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..." % base_pvc_obj.metadata.name
yaml_values = manager.get_details_for_volume(volGrp)
vol_grp_name = yaml_values['name']
volume_name = base_pvc_obj.spec.volume_name[:31]
logging.getLogger().info("Adding pvc to volume group.")
body = { 'metadata': { 'annotations': { 'csi.hpe.com/volume-group' : vol_grp_name} } }
patched_pvc_obj = manager.patch_pvc(pvc.metadata.name,globals.namespace,body)
#Checking in array if pvc is added to volume group
is_pvc_added = pvc_add_status(volGrp_uid, volume_name)
assert is_pvc_added is True, "Pvc not added to volume group"
logging.getLogger().info("Pvc {0} added to volume group {1}".format(pvc.metadata.name, vol_grp_name))
time.sleep(10)
# Export volume
pod = manager.create_pod(yml)
flag, base_pod_obj = manager.check_status(timeout, pod.metadata.name, kind='pod', status='Running',
namespace=pod.metadata.namespace)
assert flag is True, "Pod %s status check timed out, not in Running state yet..." % pod.metadata.name
time.sleep(20)
# Checking volume data
command = ['/bin/sh', '-c', 'ls -l /export']
data = manager.hpe_connect_pod_container(pod.metadata.name, command)
if any("mynewdata.txt" in x for x in data.split('\n')):
isFilePresent = True
assert isFilePresent is True, "File not present in base volume"
logging.getLogger().info("File present on volume")
# Deleting created resources
manager.hpe_delete_pod_object_by_name(base_pod_obj.metadata.name, base_pod_obj.metadata.namespace)
flag = manager.check_if_deleted(180, base_pod_obj.metadata.name, "Pod", namespace=base_pod_obj.metadata.namespace)
assert flag is True, "POD %s delete status check timedout..." % base_pod_obj.metadata.name
manager.delete_pvc(base_pvc_obj.metadata.name)
flag = manager.check_if_deleted(2, base_pvc_obj.metadata.name, "Pod", namespace=base_pvc_obj.metadata.namespace)
assert flag is True, "PVC %s delete status check timedout..." % base_pvc_obj.metadata.name
# Checking in array if pvc is deleted from volume group
Del_flag = pvc_delete_status(volGrp_uid,volume_name )
assert Del_flag is True, "Pvc not deleted from volume group"
logging.getLogger().info("Pvc {0} deleted from volume group".format(volume_name))
command = 'kubectl delete -f ' + volGrp
resp = manager.get_command_output_string(command)
assert "deleted" in resp, "Volume group not deleted"
isDeleted = volume_group_delete_status(volGrp_uid)
assert isDeleted is True, "Volume group not deleted on array"
logging.getLogger().info("Volume group deleted from array")
command = 'kubectl delete -f ' + volGrpClass
resp = manager.get_command_output_string(command)
time.sleep(10)
except Exception as e:
logging.getLogger().error("Exception :: %s" % e)
raise e
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(sc, pvc, pod)
#C547905 Add already existing pvc not part of any vg or vvset to vg
def test_volume_group_test_6():
yml = '%s/volume_group/sc_vg.yaml' % globals.yaml_dir
yml_pvc = '%s/volume_group/pvc_vg.yaml' % globals.yaml_dir
volGrp = '%s/volume_group/volume-group.yaml' % globals.yaml_dir
volGrpClass = '%s/volume_group/volume-group-class.yml' % globals.yaml_dir
pod_vg = '%s/volume_group/pod_vg.yaml' % globals.yaml_dir
ymlpod = '%s/volume_group/ymlpod.yaml' % globals.yaml_dir
sc = None
pvc = None
pod = None
global pvc_list
global pod_list
isFilePresent = False
try:
with open(volGrp, "r") as ymlfile:
elements = list(yaml.safe_load_all(ymlfile))
for el in elements:
if str(el.get('kind')) == "VolumeGroup":
volGrp_name = el['metadata']['name']
break
logging.getLogger().info("Creating volume group and volume group class")
command = 'kubectl create -f ' + volGrpClass
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group class not created"
command = 'kubectl create -f ' + volGrp
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group not created"
command = 'kubectl describe volumegroup ' + volGrp_name + ' -n ' +globals.namespace
resp = manager.get_command_output_string(command)
#Getting volumegroup uid
id = [s for s in resp.split('\n') if "UID" in s]
volGrp_uid = id[0].split()[1][:27]
#Checking in array if volume group is created
isPresent = volume_group_create_status(volGrp_uid)
assert isPresent is True , "Volume group not created on array"
logging.getLogger().info("Volume group {0} created on the array".format(volGrp_uid))
#Creating sc and pvc
sc = manager.create_sc(yml)
count =0
with open(yml_pvc, "r") as ymlpvc:
el_pvc = list(yaml.safe_load_all(ymlpvc))
while True:
if count < 3:
el_pvc[0]['metadata']['name'] = pvc_random_name()
pvc = manager.hpe_create_pvc_object(el_pvc[0])
count = count +1
logging.getLogger().info("Check in events if volume is created...")
flag, base_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..." % base_pvc_obj.metadata.name
yaml_values = manager.get_details_for_volume(volGrp)
vol_grp_name = yaml_values['name']
volume_name = base_pvc_obj.spec.volume_name[:31]
body = { 'metadata': { 'annotations': { 'csi.hpe.com/volume-group' : vol_grp_name} } }
patched_pvc_obj = manager.patch_pvc(pvc.metadata.name,globals.namespace,body)
#Checking in array if pvc is added to volume group
is_pvc_added = pvc_add_status(volGrp_uid, volume_name)
assert is_pvc_added is True, "Pvc {0} not added to volume group".format(pvc.metadata.name)
logging.getLogger().info("Pvc {0} added to volume group {1} ".format(volume_name, volGrp_uid))
#pvc_list += [base_pvc_obj.spec.volume_name[:31]]
pvc_list += [el_pvc[0]['metadata']['name']]
time.sleep(10)
else:
break
# Export base volume
i =0
while True:
if i > 2:
break
else:
with open(ymlpod, 'w') as outfile, open(pod_vg, 'r') as infile:
for line in infile:
if line.startswith(" name:"):
line = " name: " + pod_random_name() + "\n"
if line.startswith(" claimName:"):
line = " claimName: " + pvc_list[i]
outfile.write(line)
pod = manager.create_pod(ymlpod)
flag, base_pod_obj = manager.check_status(timeout, pod.metadata.name, kind='pod', status='Running',
namespace=pod.metadata.namespace)
assert flag is True, "Pod %s status check timed out, not in Running state yet..." % pod.metadata.name
time.sleep(20)
# Checking base volume data
command = ['/bin/sh', '-c', 'ls -l /export']
data = manager.hpe_connect_pod_container(pod.metadata.name, command)
if any("mynewdata.txt" in x for x in data.split('\n')):
isFilePresent = True
assert isFilePresent is True, "File not present in base volume"
logging.getLogger().info("File present on base volume")
pod_list += [base_pod_obj.metadata.name]
i =i+1
# Deleting created resources
for pod in pod_list:
manager.hpe_delete_pod_object_by_name(pod, globals.namespace)
flag = manager.check_if_deleted(180, pod, "Pod", namespace=globals.namespace)
assert flag is True, "POD %s delete status check timedout..." % pod
for pvc in pvc_list:
manager.delete_pvc(pvc)
flag = manager.check_if_deleted(2, pvc, "PVC", namespace=globals.namespace)
assert flag is True, "PVC %s delete status check timedout..." % pvc
command = 'kubectl delete -f ' + volGrp
resp = manager.get_command_output_string(command)
time.sleep(10)
command = 'kubectl delete -f ' + volGrpClass
resp = manager.get_command_output_string(command)
time.sleep(10)
manager.delete_sc(sc.metadata.name)
flag = manager.check_if_deleted(2, sc.metadata.name, "SC", None)
assert flag is True, "SC %s delete status check timedout..." % sc.metadata.name
except Exception as e:
logging.getLogger().error("Exception in volume group testcase :: %s" % e)
raise e
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup_mul(sc, pvc, pod)
#C547907 Add/edit a volume that is already part of another vg
def test_volume_group_test_10():
yml = '%s/volume_group/sc_vg.yaml' % globals.yaml_dir
volGrp = '%s/volume_group/volume-group.yaml' % globals.yaml_dir
volGrpClass = '%s/volume_group/volume-group-class.yml' % globals.yaml_dir
volGrp_new = '%s/volume_group/volume-group_1.yaml' % globals.yaml_dir
volGrpClass_new = '%s/volume_group/volume-group-class_1.yml' % globals.yaml_dir
sc = None
pvc = None
pod = None
isFilePresent = False
try:
with open(volGrp, "r") as ymlfile:
elements = list(yaml.safe_load_all(ymlfile))
for el in elements:
if str(el.get('kind')) == "VolumeGroup":
volGrp_name = el['metadata']['name']
break
logging.getLogger().info("Pvc creating volume group and volume group class")
command = 'kubectl create -f ' + volGrpClass
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group class not created"
command = 'kubectl create -f ' + volGrp
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group not created"
command = 'kubectl describe volumegroup ' + volGrp_name + ' -n ' +globals.namespace
resp = manager.get_command_output_string(command)
#Getting volumegroup uid
id = [s for s in resp.split('\n') if "UID" in s]
volGrp_uid = id[0].split()[1][:27]
#Checking in array if volume group is created
isPresent = volume_group_create_status(volGrp_uid)
assert isPresent is True , "Volume group not created on array"
logging.getLogger().info("Volume group {0} created on array".format(volGrp_uid))
#Creating pvc and sc
sc = manager.create_sc(yml)
pvc = manager.create_pvc(yml)
logging.getLogger().info("Check in events if volume is created...")
flag, base_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..." % base_pvc_obj.metadata.name
yaml_values = manager.get_details_for_volume(volGrp)
vol_grp_name = yaml_values['name']
volume_name = base_pvc_obj.spec.volume_name[:31]
body = { 'metadata': { 'annotations': { 'csi.hpe.com/volume-group' : vol_grp_name} } }
patched_pvc_obj = manager.patch_pvc(pvc.metadata.name,globals.namespace,body)
#Checking in array if pvc is added to volume group
is_pvc_added = pvc_add_status(volGrp_uid, volume_name)
assert is_pvc_added is True, "Pvc {0} not added to volume group".format(pvc.metadata.name)
logging.getLogger().info("Pvc {0} added to volume group {1} ".format(volume_name, volGrp_uid))
time.sleep(10)
# Export base volume
pod = manager.create_pod(yml)
flag, base_pod_obj = manager.check_status(timeout, pod.metadata.name, kind='pod', status='Running',
namespace=pod.metadata.namespace)
assert flag is True, "Pod %s status check timed out, not in Running state yet..." % pod.metadata.name
time.sleep(20)
# Checking base volume data
command = ['/bin/sh', '-c', 'ls -l /export']
data = manager.hpe_connect_pod_container(pod.metadata.name, command)
if any("mynewdata.txt" in x for x in data.split('\n')):
isFilePresent = True
assert isFilePresent is True, "File not present in base volume"
logging.getLogger().info("File present on base volume")
#Creating the new volume set
with open(volGrp_new, "r") as ymlfile:
elements = list(yaml.safe_load_all(ymlfile))
for el in elements:
if str(el.get('kind')) == "VolumeGroup":
volGrp_name_new = el['metadata']['name']
break
logging.getLogger().info("Creating second volume set")
command = 'kubectl create -f ' + volGrpClass_new
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group class not created"
command = 'kubectl create -f ' + volGrp_new
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group not created"
command = 'kubectl describe volumegroup ' + volGrp_name_new + ' -n ' +globals.namespace
resp = manager.get_command_output_string(command)
# Getting volumegroup uid
id_new = [s for s in resp.split('\n') if "UID" in s]
volGrp_uid_new = id_new[0].split()[1][:27]
#Checking in array if volume group is created
isPresent = volume_group_create_status(volGrp_uid_new)
assert isPresent is True , "Volume group not created on array"
logging.getLogger().info("Second volume group {0} created on array ".format(volGrp_uid_new))
yaml_values_new = manager.get_details_for_volume(volGrp_new)
vol_grp_name_new = yaml_values_new['name']
new_volume_name = base_pvc_obj.spec.volume_name[:31]
body = { 'metadata': { 'annotations': { 'csi.hpe.com/volume-group' : vol_grp_name_new} } }
patched_pvc_obj = manager.patch_pvc(pvc.metadata.name,globals.namespace,body)
#Checking in array if pvc is added to volume group
is_pvc_added = pvc_add_status(volGrp_uid_new, new_volume_name)
assert is_pvc_added is True, "Pvc {0} not added to volume group".format(pvc.metadata.name)
logging.getLogger().info("Pvc {0} added to volume group {1} ".format(new_volume_name, volGrp_uid_new))
except Exception as e:
logging.getLogger().error("Exception in volume group testcase :: %s" % e)
raise e
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(sc, pvc, pod)
cleanup_volume_group(volGrp, volGrpClass, volGrp_uid)
cleanup_volume_group(volGrp_new, volGrpClass_new, volGrp_uid_new)
#C549392 clone volume which is part of volumegroup
def test_volume_group_test_13():
yml = '%s/volume_group/sc_vg.yaml' % globals.yaml_dir
volGrp = '%s/volume_group/volume-group.yaml' % globals.yaml_dir
volGrpClass = '%s/volume_group/volume-group-class.yml' % globals.yaml_dir
sc = None
pvc = None
pod = None
isFilePresent = True
try:
with open(volGrp, "r") as ymlfile:
elements = list(yaml.safe_load_all(ymlfile))
for el in elements:
if str(el.get('kind')) == "VolumeGroup":
volGrp_name = el['metadata']['name']
break
logging.getLogger().info("Creating volume group class and volume group")
command = 'kubectl create -f ' + volGrpClass
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group class not created"
command = 'kubectl create -f ' + volGrp
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group not created"
command = 'kubectl describe volumegroup ' + volGrp_name + ' -n ' +globals.namespace
resp = manager.get_command_output_string(command)
#Getting volumegroup uid
id = [s for s in resp.split('\n') if "UID" in s]
volGrp_uid = id[0].split()[1][:27]
#Checking in array if volume group is created
isPresent = volume_group_create_status(volGrp_uid)
assert isPresent is True , "Volume group not created on array"
logging.getLogger().info("Volume group {0} created on array".format(volGrp_uid))
# Creating sc and pvc
sc = manager.create_sc(yml)
pvc = manager.create_pvc(yml)
logging.getLogger().info("Check in events if volume is created...")
flag, base_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..." % base_pvc_obj.metadata.name
yaml_values = manager.get_details_for_volume(volGrp)
vol_grp_name = yaml_values['name']
volume_name = base_pvc_obj.spec.volume_name[:31]
body = { 'metadata': { 'annotations': { 'csi.hpe.com/volume-group' : vol_grp_name} } }
patched_pvc_obj = manager.patch_pvc(pvc.metadata.name,globals.namespace,body)
#Checking in array if pvc is added to volume group
is_pvc_added = pvc_add_status(volGrp_uid, volume_name)
assert is_pvc_added is True, "Pvc {0} not added to volume group".format(pvc.metadata.name)
logging.getLogger().info("Pvc {0} added to volume group {1}".format(pvc.metadata.name,volGrp_uid))
time.sleep(10)
# Checking base volume details on array
base_volume = manager.get_volume_from_array(globals.hpe3par_cli, volume_name)
# Export base volume
pod = manager.create_pod(yml)
flag, base_pod_obj = manager.check_status(timeout, pod.metadata.name, kind='pod', status='Running',
namespace=pod.metadata.namespace)
assert flag is True, "Pod %s status check timed out, not in Running state yet..." % pod.metadata.name
time.sleep(20)
# Checking base volume data
command = ['/bin/sh', '-c', 'ls -l /export']
data = manager.hpe_connect_pod_container(pod.metadata.name, command)
if any("mynewdata.txt" in x for x in data.split('\n')):
isFilePresent = True
assert isFilePresent is True, "File not present in base volume"
# Creating clone of pvc in vvset
yml_clone = '%s/volume_group/sc_clone.yaml' % globals.yaml_dir
sc_clone = manager.create_sc(yml_clone)
pvc_clone = manager.create_pvc(yml_clone)
logging.getLogger().info("Check in events if clone volume is created...")
flag, base_pvc_clone_obj = manager.check_status(30, pvc_clone.metadata.name, kind='pvc', status='Bound',
namespace=pvc_clone.metadata.namespace)
clone_volume = base_pvc_clone_obj.spec.volume_name[:31]
assert flag is True, "Clone PVC %s status check timed out, not in Bound state yet..." % base_pvc_clone_obj.metadata.name
# Checking in array if clone pvc is not part of volume group
volume_set = manager.get_volume_set_from_array(globals.hpe3par_cli, volGrp_uid)
assert clone_volume not in volume_set['setmembers'], "Pvc not added to volume group"
# Checking clone volume details on array
clone_volume_details = manager.get_volume_from_array(globals.hpe3par_cli, clone_volume)
# Export clone volume
pod_clone = manager.create_pod(yml_clone)
flag, base_pod_clone_obj = manager.check_status(timeout, pod_clone.metadata.name, kind='pod', status='Running',
namespace=pod_clone.metadata.namespace)
assert flag is True, "Pod %s status check timed out, not in Running state yet..." % pod_clone.metadata.name
time.sleep(20)
# Checking base volume data in cloned volume and new write to the cloned volume
command = ['/bin/sh', '-c', 'ls -l /export']
data = manager.hpe_connect_pod_container(pod_clone.metadata.name, command)
isFilePresent = False
if any("mynewdata.txt" in x for x in data.split('\n')):
isFilePresent = True
assert isFilePresent is True, "File not present in clone volume"
isFilePresent = False
if any("myclonedata.txt" in x for x in data.split('\n')):
isFilePresent = True
assert isFilePresent is True, "File not present in clone volume"
except Exception as e:
logging.getLogger().error("Exception in volume group testcase :: %s" % e)
raise e
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(sc, pvc, pod)
cleanup(sc_clone, pvc_clone, pod_clone)
cleanup_volume_group(volGrp, volGrpClass, volGrp_uid)
# C549381 expand volume which is part of volumegroup
def test_volume_group_test_14():
yml = '%s/volume_group/sc_expand.yaml' % globals.yaml_dir
volGrp = '%s/volume_group/volume-group.yaml' % globals.yaml_dir
volGrpClass = '%s/volume_group/volume-group-class.yml' % globals.yaml_dir
sc = None
pvc = None
pod = None
isFilePresent = False
try:
with open(volGrp, "r") as ymlfile:
elements = list(yaml.safe_load_all(ymlfile))
for el in elements:
if str(el.get('kind')) == "VolumeGroup":
volGrp_name = el['metadata']['name']
break
logging.getLogger().info("Creating volume group class and volume group")
command = 'kubectl create -f ' + volGrpClass
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group class not created"
command = 'kubectl create -f ' + volGrp
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group not created"
command = 'kubectl describe volumegroup ' + volGrp_name + ' -n ' + globals.namespace
resp = manager.get_command_output_string(command)
# Getting volumegroup uid
id = [s for s in resp.split('\n') if "UID" in s]
volGrp_uid = id[0].split()[1][:27]
# Checking in array if volume group is created
isPresent = volume_group_create_status(volGrp_uid)
assert isPresent is True, "Volume group not created on array"
logging.getLogger().info("Volume group {0} created on array".format(volGrp_uid))
# Creating sc and pvc
sc = manager.create_sc(yml)
pvc = manager.create_pvc(yml)
logging.getLogger().info("Check in events if volume is created...")
flag, base_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..." % base_pvc_obj.metadata.name
yaml_values = manager.get_details_for_volume(volGrp)
vol_grp_name = yaml_values['name']
volume_name = base_pvc_obj.spec.volume_name[:31]
body = {'metadata': {'annotations': {'csi.hpe.com/volume-group': vol_grp_name}}}
patched_pvc_obj = manager.patch_pvc(pvc.metadata.name, globals.namespace, body)
# Checking in array if pvc is added to volume group
is_pvc_added = pvc_add_status(volGrp_uid, volume_name)
assert is_pvc_added is True, "Pvc {0} not added to volume group".format(pvc.metadata.name)
logging.getLogger().info("Pvc {0} added to volume group {1}".format(pvc.metadata.name, volGrp_uid))
time.sleep(10)
# expanding volume size of the array
cap_vol = '30'
body = {'spec': {'resources': {'requests': {'storage': cap_vol + 'Gi'}}}}
patched_pvc_obj = manager.patch_pvc(pvc.metadata.name, globals.namespace, body)
time.sleep(30)
voldata = manager.get_volume_from_array(globals.hpe3par_cli, base_pvc_obj.spec.volume_name[:31])
assert voldata['sizeMiB'] == int(cap_vol) * 1024, "Volume expand failed"
# Export base volume
pod = manager.create_pod(yml)
flag, base_pod_obj = manager.check_status(timeout, pod.metadata.name, kind='pod', status='Running',
namespace=pod.metadata.namespace)
assert flag is True, "Pod %s status check timed out, not in Running state yet..." % pod.metadata.name
time.sleep(20)
# Checking base volume data
command = ['/bin/sh', '-c', 'ls -l /export']
data = manager.hpe_connect_pod_container(pod.metadata.name, command)
if any("mynewdata.txt" in x for x in data.split('\n')):
isFilePresent = True
assert isFilePresent is True, "File not present in base volume"
except Exception as e:
logging.getLogger().error("Exception in volume group testcase :: %s" % e)
raise e
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(sc, pvc, pod)
cleanup_volume_group(volGrp, volGrpClass, volGrp_uid)
# C547909 Add volume part of different domain to vg
def test_volume_group_test_15():
yml = '%s/volume_group/sc_expand.yaml' % globals.yaml_dir
volGrp = '%s/volume_group/volume-group.yaml' % globals.yaml_dir
volGrpClass = '%s/volume_group/volume-group-class-domain.yml' % globals.yaml_dir
sc = None
pvc = None
pod = None
isFilePresent = False
try:
with open(volGrp, "r") as ymlfile:
elements = list(yaml.safe_load_all(ymlfile))
for el in elements:
if str(el.get('kind')) == "VolumeGroup":
volGrp_name = el['metadata']['name']
break
logging.getLogger().info("Creating volume group class and volume group")
command = 'kubectl create -f ' + volGrpClass
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group class not created"
command = 'kubectl create -f ' + volGrp
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group not created"
command = 'kubectl describe volumegroup ' + volGrp_name + ' -n ' + globals.namespace
resp = manager.get_command_output_string(command)
# Getting volumegroup uid
id = [s for s in resp.split('\n') if "UID" in s]
volGrp_uid = id[0].split()[1][:27]
# Checking in array if volume group is created
isPresent = volume_group_create_status(volGrp_uid)
assert isPresent is True, "Volume group not created on array"
logging.getLogger().info("Volume group {0} created on array".format(volGrp_uid))
# Creating sc and pvc
sc = manager.create_sc(yml)
pvc = manager.create_pvc(yml)
logging.getLogger().info("Check in events if volume is created...")
flag, base_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..." % base_pvc_obj.metadata.name
yaml_values = manager.get_details_for_volume(volGrp)
vol_grp_name = yaml_values['name']
volume_name = base_pvc_obj.spec.volume_name[:31]
body = {'metadata': {'annotations': {'csi.hpe.com/volume-group': vol_grp_name}}}
patched_pvc_obj = manager.patch_pvc(pvc.metadata.name, globals.namespace, body)
# Checking if pvc is added to volume group
is_pvc_added = pvc_add_status(volGrp_uid, volume_name)
assert is_pvc_added is False, "Pvc added to volume group"
logging.getLogger().info("pvc {0} not added to volume group {1} ".format(pvc.metadata.name, vol_grp_name))
except Exception as e:
logging.getLogger().error("Exception in volume group testcase :: %s" % e)
raise e
finally:
# Now cleanup secret, sc, pv, pvc
cleanup(sc, pvc, pod)
cleanup_volume_group(volGrp, volGrpClass, volGrp_uid)
# C547900 Disassociate a pvc/volume from volumegroup by pvc edit
def test_volume_group_test_16():
yml = '%s/volume_group/sc_expand.yaml' % globals.yaml_dir
volGrp = '%s/volume_group/volume-group.yaml' % globals.yaml_dir
volGrpClass = '%s/volume_group/volume-group-class.yml' % globals.yaml_dir
sc = None
pvc = None
pod = None
try:
with open(volGrp, "r") as ymlfile:
elements = list(yaml.safe_load_all(ymlfile))
for el in elements:
if str(el.get('kind')) == "VolumeGroup":
volGrp_name = el['metadata']['name']
break
logging.getLogger().info("Creating volume group class and volume group")
command = 'kubectl create -f ' + volGrpClass
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group class not created"
command = 'kubectl create -f ' + volGrp
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group not created"
command = 'kubectl describe volumegroup ' + volGrp_name + ' -n ' + globals.namespace
resp = manager.get_command_output_string(command)
# Getting volumegroup uid
id = [s for s in resp.split('\n') if "UID" in s]
volGrp_uid = id[0].split()[1][:27]
# Checking in array if volume group is created
isPresent = volume_group_create_status(volGrp_uid)
assert isPresent is True, "Volume group not created on array"
logging.getLogger().info("Volume group {0} created on array".format(volGrp_uid))
# Creating sc and pvc
sc = manager.create_sc(yml)
pvc = manager.create_pvc(yml)
logging.getLogger().info("Check in events if volume is created...")
flag, base_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..." % base_pvc_obj.metadata.name
yaml_values = manager.get_details_for_volume(volGrp)
vol_grp_name = yaml_values['name']
volume_name = base_pvc_obj.spec.volume_name[:31]
body = {'metadata': {'annotations': {'csi.hpe.com/volume-group': vol_grp_name}}}
patched_pvc_obj = manager.patch_pvc(pvc.metadata.name, globals.namespace, body)
# Checking in array if pvc is added to volume group
is_pvc_added = pvc_add_status(volGrp_uid, volume_name)
assert is_pvc_added is True, "Pvc not added to volume group"
logging.getLogger().info("Pvc {0} added to volume group {1}".format(pvc.metadata.name, volGrp_uid))
time.sleep(10)
# disassociating pvc from volume group
body = {'metadata': {'annotations': {'csi.hpe.com/volume-group': ""}}}
patched_pvc_obj = manager.patch_pvc(pvc.metadata.name, globals.namespace, body)
Del_flag = pvc_delete_status(volGrp_uid, volume_name)
assert Del_flag is True, "Pvc not deleted from volume group"
logging.getLogger().info("Pvc {0} removed from volume group {1}".format(pvc.metadata.name, volGrp_uid))
time.sleep(10)
except Exception as e:
logging.getLogger().error("Exception in volume group testcase :: %s" % e)
raise e
finally:
# Now cleanup secret, sc, pv, pvc
cleanup(sc, pvc, pod)
cleanup_volume_group(volGrp, volGrpClass, volGrp_uid)
def test_volume_group_test_hostSeesVLUN():
yml = '%s/volume_group/sc_vg_hostSeesVLUN.yaml' % globals.yaml_dir
volGrp = '%s/volume_group/volume-group.yaml' % globals.yaml_dir
volGrpClass = '%s/volume_group/volume-group-class.yml' % globals.yaml_dir
sc = None
pvc = None
pod = None
try:
with open(volGrp, "r") as ymlfile:
elements = list(yaml.safe_load_all(ymlfile))
for el in elements:
if str(el.get('kind')) == "VolumeGroup":
volGrp_name = el['metadata']['name']
break
with open(yml, "r") as ymlfile:
elements = list(yaml.safe_load_all(ymlfile))
for el in elements:
if str(el.get('kind')) == "StorageClass":
if 'hostSeesVLUN' in el['parameters']:
hostSeesVLUN = el['parameters']['hostSeesVLUN']
break
logging.getLogger().info("Creating volume group class and volume group")
command = 'kubectl create -f ' + volGrpClass
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group class not created"
command = 'kubectl create -f ' + volGrp
resp = manager.get_command_output_string(command)
assert "created" in resp, "volume group not created"
command = 'kubectl describe volumegroup ' + volGrp_name + ' -n ' +globals.namespace
resp = manager.get_command_output_string(command)
# Getting volumegroup uid
id = [s for s in resp.split('\n') if "UID" in s]
volGrp_uid = id[0].split()[1][:27]
# Checking in array if volume group is created
isPresent = volume_group_create_status(volGrp_uid)
assert isPresent is True , "Volume group not created on array"
logging.getLogger().info("Volume group {0} created on array".format(volGrp_uid))
# Creating sc and pvc
sc = manager.create_sc(yml)
pvc = manager.create_pvc(yml)
logging.getLogger().info("Check in events if volume is created...")
flag, base_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.metadata.name
yaml_values = manager.get_details_for_volume(volGrp)
vol_grp_name = yaml_values['name']