/
csi_snapshot_basic.go
7610 lines (6493 loc) · 327 KB
/
csi_snapshot_basic.go
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
/*
Copyright 2022 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package e2e
import (
"context"
"fmt"
"math/rand"
"os"
"strconv"
"strings"
"time"
ginkgo "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
cnstypes "github.com/vmware/govmomi/cns/types"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/object"
"golang.org/x/crypto/ssh"
v1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/kubernetes/test/e2e/framework"
fdep "k8s.io/kubernetes/test/e2e/framework/deployment"
e2ekubectl "k8s.io/kubernetes/test/e2e/framework/kubectl"
fnodes "k8s.io/kubernetes/test/e2e/framework/node"
fpod "k8s.io/kubernetes/test/e2e/framework/pod"
e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"
fpv "k8s.io/kubernetes/test/e2e/framework/pv"
fss "k8s.io/kubernetes/test/e2e/framework/statefulset"
admissionapi "k8s.io/pod-security-admission/api"
snapV1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
snapclient "github.com/kubernetes-csi/external-snapshotter/client/v6/clientset/versioned"
)
var _ = ginkgo.Describe("Volume Snapshot Basic Test", func() {
f := framework.NewDefaultFramework("volume-snapshot")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
var (
client clientset.Interface
clientNewGc clientset.Interface
c clientset.Interface
namespace string
scParameters map[string]string
datastoreURL string
pandoraSyncWaitTime int
volumeOpsScale int
restConfig *restclient.Config
guestClusterRestConfig *restclient.Config
snapc *snapclient.Clientset
storagePolicyName string
clientIndex int
defaultDatastore *object.Datastore
defaultDatacenter *object.Datacenter
isVsanHealthServiceStopped bool
labels_ns map[string]string
)
ginkgo.BeforeEach(func() {
bootstrap()
client = f.ClientSet
namespace = getNamespaceToRunTests(f)
scParameters = make(map[string]string)
datastoreURL = GetAndExpectStringEnvVar(envSharedDatastoreURL)
nodeList, err := fnodes.GetReadySchedulableNodes(f.ClientSet)
framework.ExpectNoError(err, "Unable to find ready and schedulable Node")
if !(len(nodeList.Items) > 0) {
framework.Failf("Unable to find ready and schedulable Node")
}
//Get snapshot client using the rest config
if !guestCluster {
restConfig = getRestConfigClient()
snapc, err = snapclient.NewForConfig(restConfig)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
} else {
guestClusterRestConfig = getRestConfigClientForGuestCluster(guestClusterRestConfig)
snapc, err = snapclient.NewForConfig(guestClusterRestConfig)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
if os.Getenv(envPandoraSyncWaitTime) != "" {
pandoraSyncWaitTime, err = strconv.Atoi(os.Getenv(envPandoraSyncWaitTime))
gomega.Expect(err).NotTo(gomega.HaveOccurred())
} else {
pandoraSyncWaitTime = defaultPandoraSyncWaitTime
}
if os.Getenv("VOLUME_OPS_SCALE") != "" {
volumeOpsScale, err = strconv.Atoi(os.Getenv(envVolumeOperationsScale))
gomega.Expect(err).NotTo(gomega.HaveOccurred())
} else {
if vanillaCluster {
volumeOpsScale = 25
}
}
framework.Logf("VOLUME_OPS_SCALE is set to %v", volumeOpsScale)
controllerClusterConfig := os.Getenv(contollerClusterKubeConfig)
c = client
if controllerClusterConfig != "" {
framework.Logf("Creating client for remote kubeconfig")
remoteC, err := createKubernetesClientFromConfig(controllerClusterConfig)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
c = remoteC
}
if guestCluster {
storagePolicyName = GetAndExpectStringEnvVar(envStoragePolicyNameForSharedDatastores)
svcClient, svNamespace := getSvcClientAndNamespace()
setResourceQuota(svcClient, svNamespace, rqLimit)
datastoreURL = GetAndExpectStringEnvVar(envSharedDatastoreURL)
var datacenters []string
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
finder := find.NewFinder(e2eVSphere.Client.Client, false)
cfg, err := getConfig()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
dcList := strings.Split(cfg.Global.Datacenters, ",")
for _, dc := range dcList {
dcName := strings.TrimSpace(dc)
if dcName != "" {
datacenters = append(datacenters, dcName)
}
}
for _, dc := range datacenters {
defaultDatacenter, err = finder.Datacenter(ctx, dc)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
finder.SetDatacenter(defaultDatacenter)
defaultDatastore, err = getDatastoreByURL(ctx, datastoreURL, defaultDatacenter)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
}
labels_ns = map[string]string{}
labels_ns[admissionapi.EnforceLevelLabel] = string(admissionapi.LevelPrivileged)
labels_ns["e2e-framework"] = f.BaseName
})
ginkgo.AfterEach(func() {
vcAddress := e2eVSphere.Config.Global.VCenterHostname + ":" + sshdPort
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if guestCluster {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
framework.Logf("Collecting supervisor PVC events before performing PV/PVC cleanup")
eventList, err := svcClient.CoreV1().Events(svcNamespace).List(ctx, metav1.ListOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
for _, item := range eventList.Items {
framework.Logf(fmt.Sprintf(item.Message))
}
}
if isVsanHealthServiceStopped {
startVCServiceWait4VPs(ctx, vcAddress, vsanhealthServiceName, &isVsanHealthServiceStopped)
}
})
/*
Create/Delete snapshot via k8s API using PVC (Dynamic Provisioning)
1. Create a storage class (eg: vsan default) and create a pvc using this sc
2. Create a VolumeSnapshot class with snapshotter as vsphere-csi-driver and set deletionPolicy to Delete
3. Create a volume-snapshot with labels, using the above snapshot-class and pvc (from step-1) as source
4. Ensure the snapshot is created, verify using get VolumeSnapshot
5. Also verify that VolumeSnapshotContent is auto-created
6. Verify the references to pvc and volume-snapshot on this object
7. Verify that the VolumeSnapshot has ready-to-use set to True
8. Verify that the Restore Size set on the snapshot is same as that of the source volume size
9. Query the snapshot from CNS side using volume id - should pass and return the snapshot entry
10. Delete the above snapshot from k8s side using kubectl delete, run a get and ensure it is removed
11. Also ensure that the VolumeSnapshotContent is deleted along with the
volume snapshot as the policy is delete
12. Query the snapshot from CNS side - should return 0 entries
13. Cleanup: Delete PVC, SC (validate they are removed)
*/
ginkgo.It("[block-vanilla-snapshot] [tkg-snapshot] Verify snapshot dynamic provisioning "+
"workflow", ginkgo.Label(p0, block, tkg, vanilla, snapshot, stable), func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var volHandle string
if vanillaCluster {
scParameters[scParamDatastoreURL] = datastoreURL
} else if guestCluster {
scParameters[svStorageClassName] = storagePolicyName
}
ginkgo.By("Create storage class and PVC")
storageclass, err := createStorageClass(client, scParameters, nil, "", "", false, "")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer func() {
err := client.StorageV1().StorageClasses().Delete(ctx, storageclass.Name, *metav1.NewDeleteOptions(0))
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
pvclaim, persistentVolumes := createPVCAndQueryVolumeInCNS(client, namespace, nil, "",
diskSize, storageclass, true)
volHandle = persistentVolumes[0].Spec.CSI.VolumeHandle
if guestCluster {
volHandle = getVolumeIDFromSupervisorCluster(volHandle)
}
gomega.Expect(volHandle).NotTo(gomega.BeEmpty())
defer func() {
err := fpv.DeletePersistentVolumeClaim(client, pvclaim.Name, namespace)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
err = e2eVSphere.waitForCNSVolumeToBeDeleted(volHandle)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
ginkgo.By("Create volume snapshot class")
volumeSnapshotClass, err := createVolumeSnapshotClass(ctx, snapc, deletionPolicy)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer func() {
if vanillaCluster {
err = snapc.SnapshotV1().VolumeSnapshotClasses().Delete(ctx, volumeSnapshotClass.Name,
metav1.DeleteOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
}()
ginkgo.By("Create a dynamic volume snapshot")
volumeSnapshot, snapshotContent, snapshotCreated,
snapshotContentCreated, snapshotId, err := createDynamicVolumeSnapshot(ctx, namespace, snapc, volumeSnapshotClass,
pvclaim, volHandle, diskSize, true)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer func() {
if snapshotContentCreated {
err = deleteVolumeSnapshotContent(ctx, snapshotContent, snapc, namespace, pandoraSyncWaitTime)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
if snapshotCreated {
framework.Logf("Deleting volume snapshot")
deleteVolumeSnapshotWithPandoraWait(ctx, snapc, namespace, volumeSnapshot.Name, pandoraSyncWaitTime)
framework.Logf("Wait till the volume snapshot is deleted")
err = waitForVolumeSnapshotContentToBeDeletedWithPandoraWait(ctx, snapc,
*volumeSnapshot.Status.BoundVolumeSnapshotContentName, pandoraSyncWaitTime)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
}()
ginkgo.By("Delete dynamic volume snapshot")
snapshotCreated, snapshotContentCreated, err = deleteVolumeSnapshot(ctx, snapc, namespace,
volumeSnapshot, pandoraSyncWaitTime, volHandle, snapshotId)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
/*
Create/Delete snapshot via k8s API using VolumeSnapshotContent (Pre-Provisioned Snapshots)
1. Create a storage class (eg: vsan default) and create a pvc using this sc
2. The volumesnapshotclass is set to delete
3. Create a VolumeSnapshotContent using snapshot-handle
a. get snapshotHandle by referring to an existing volume snapshot
b. this snapshot will be created dynamically, and the snapshot-content that is
created by that will be referred to get the snapshotHandle
4. Create a volume snapshot using source set to volumeSnapshotContentName above
5. Ensure the snapshot is created, verify using get VolumeSnapshot
6. Verify the restoreSize on the snapshot and the snapshotcontent is set to same as that of the pvcSize
7. Delete the above snapshot, run a get from k8s side and ensure its removed
8. Run QuerySnapshot from CNS side, the backend snapshot should be deleted
9. Also ensure that the VolumeSnapshotContent is deleted along with the
volume snapshot as the policy is delete
10. Cleanup the pvc
*/
ginkgo.It("[block-vanilla-snapshot] Verify snapshot static provisioning through K8s "+
"API workflow", ginkgo.Label(p0, block, vanilla, snapshot, stable), func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var storageclass *storagev1.StorageClass
var pvclaim *v1.PersistentVolumeClaim
var pvclaims []*v1.PersistentVolumeClaim
var err error
var snapshotContentCreated = false
ginkgo.By("Create storage class and PVC")
scParameters[scParamDatastoreURL] = datastoreURL
storageclass, pvclaim, err = createPVCAndStorageClass(client,
namespace, nil, scParameters, diskSize, nil, "", false, "")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer func() {
err := client.StorageV1().StorageClasses().Delete(ctx, storageclass.Name,
*metav1.NewDeleteOptions(0))
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
ginkgo.By("Expect claim to provision volume successfully")
pvclaims = append(pvclaims, pvclaim)
persistentvolumes, err := fpv.WaitForPVClaimBoundPhase(client, pvclaims, framework.ClaimProvisionTimeout)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
volHandle := persistentvolumes[0].Spec.CSI.VolumeHandle
gomega.Expect(volHandle).NotTo(gomega.BeEmpty())
defer func() {
err := fpv.DeletePersistentVolumeClaim(client, pvclaim.Name, namespace)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
err = e2eVSphere.waitForCNSVolumeToBeDeleted(volHandle)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
// Verify using CNS Query API if VolumeID retrieved from PV is present.
ginkgo.By(fmt.Sprintf("Invoking QueryCNSVolumeWithResult with VolumeID: %s", volHandle))
queryResult, err := e2eVSphere.queryCNSVolumeWithResult(volHandle)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(queryResult.Volumes).ShouldNot(gomega.BeEmpty())
gomega.Expect(queryResult.Volumes[0].VolumeId.Id).To(gomega.Equal(volHandle))
ginkgo.By("Create volume snapshot class")
volumeSnapshotClass, err := snapc.SnapshotV1().VolumeSnapshotClasses().Create(ctx,
getVolumeSnapshotClassSpec(snapV1.DeletionPolicy("Delete"), nil), metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer func() {
err := snapc.SnapshotV1().VolumeSnapshotClasses().Delete(ctx, volumeSnapshotClass.Name,
metav1.DeleteOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
ginkgo.By("Create a volume snapshot")
volumeSnapshot, err := snapc.SnapshotV1().VolumeSnapshots(namespace).Create(ctx,
getVolumeSnapshotSpec(namespace, volumeSnapshotClass.Name, pvclaim.Name), metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
framework.Logf("Volume snapshot name is : %s", volumeSnapshot.Name)
snapshotCreated := true
defer func() {
if snapshotCreated {
framework.Logf("Deleting volume snapshot")
deleteVolumeSnapshotWithPandoraWait(ctx, snapc, namespace, volumeSnapshot.Name, pandoraSyncWaitTime)
}
if snapshotContentCreated {
framework.Logf("Deleting volume snapshot content")
deleteVolumeSnapshotContentWithPandoraWait(ctx, snapc,
*volumeSnapshot.Status.BoundVolumeSnapshotContentName, pandoraSyncWaitTime)
}
}()
ginkgo.By("Verify volume snapshot is created")
volumeSnapshot, err = waitForVolumeSnapshotReadyToUse(*snapc, ctx, namespace, volumeSnapshot.Name)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(volumeSnapshot.Status.RestoreSize.Cmp(resource.MustParse(diskSize))).To(gomega.BeZero())
ginkgo.By("Verify volume snapshot content is created")
snapshotContent, err := snapc.SnapshotV1().VolumeSnapshotContents().Get(ctx,
*volumeSnapshot.Status.BoundVolumeSnapshotContentName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
snapshotContentCreated = true
gomega.Expect(*snapshotContent.Status.ReadyToUse).To(gomega.BeTrue())
framework.Logf("Get volume snapshot ID from snapshot handle")
snapshothandle := *snapshotContent.Status.SnapshotHandle
snapshotId := strings.Split(snapshothandle, "+")[1]
ginkgo.By("Query CNS and check the volume snapshot entry")
err = verifySnapshotIsCreatedInCNS(volHandle, snapshotId, false)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
ginkgo.By(fmt.Sprintf("Creating volume snapshot content by snapshotHandle %s", snapshothandle))
snapshotContent2, err := snapc.SnapshotV1().VolumeSnapshotContents().Create(ctx,
getVolumeSnapshotContentSpec(snapV1.DeletionPolicy("Delete"), snapshothandle,
"static-vs", namespace), metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
ginkgo.By("Verify volume snapshot content is created or not")
snapshotContentNew, err := snapc.SnapshotV1().VolumeSnapshotContents().Get(ctx,
snapshotContent2.Name, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
snapshotContentCreated2 := true
framework.Logf("Snapshotcontent name is %s", snapshotContentNew.ObjectMeta.Name)
defer func() {
if snapshotContentCreated2 {
deleteVolumeSnapshotContentWithPandoraWait(ctx, snapc,
snapshotContentNew.ObjectMeta.Name, pandoraSyncWaitTime)
}
}()
ginkgo.By("Create a volume snapshot by snapshotcontent")
volumeSnapshot2, err := snapc.SnapshotV1().VolumeSnapshots(namespace).Create(ctx,
getVolumeSnapshotSpecByName(namespace, "static-vs",
snapshotContentNew.ObjectMeta.Name), metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
framework.Logf("Volume snapshot name is : %s", volumeSnapshot2.Name)
snapshotCreated2 := true
defer func() {
if snapshotCreated2 {
deleteVolumeSnapshotWithPandoraWait(ctx, snapc, namespace, "static-vs", pandoraSyncWaitTime)
}
}()
ginkgo.By("Verify volume snapshot 2 is created")
staticSnapshot, err := waitForVolumeSnapshotReadyToUse(*snapc, ctx, namespace, volumeSnapshot2.Name)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(staticSnapshot.Status.RestoreSize.Cmp(resource.MustParse(diskSize))).To(gomega.BeZero())
framework.Logf("Snapshot details is %+v", staticSnapshot)
ginkgo.By("Deleted volume snapshot is created above")
deleteVolumeSnapshotWithPandoraWait(ctx, snapc, namespace, staticSnapshot.Name, pandoraSyncWaitTime)
snapshotCreated2 = false
framework.Logf("Wait till the volume snapshot is deleted")
err = waitForVolumeSnapshotContentToBeDeleted(*snapc, ctx, snapshotContentNew.ObjectMeta.Name)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
snapshotContentCreated2 = false
})
/*
Create pre-provisioned snapshot using backend snapshot (create via CNS)
1. Create a storage-class and create a pvc using this sc
2. Call CNS CreateSnapshot API on the above volume
3. Call CNS QuerySnapshot API on the above volume to get the snapshotHandle id
4. Use this snapshotHandle to create the VolumeSnapshotContent
5. Create a volume snapshot using source set to volumeSnapshotContentName above
6. Ensure the snapshot is created, verify using get VolumeSnapshot
7. Verify the restoreSize on the snapshot and the snapshotcontent is set to same as that of the pvcSize
8. Delete the above snapshot, run a get from k8s side and ensure its removed
9. Run QuerySnapshot from CNS side, the backend snapshot should be deleted
10. Also ensure that the VolumeSnapshotContent is deleted along with the
volume snapshot as the policy is delete
11. The snapshot that was created via CNS in step-2 should be deleted as part of k8s snapshot delete
12. Delete the pvc
*/
ginkgo.It("[block-vanilla-snapshot] Verify snapshot static provisioning "+
"via CNS", ginkgo.Label(p0, block, vanilla, snapshot, stable), func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var storageclass *storagev1.StorageClass
var pvclaim *v1.PersistentVolumeClaim
var pvclaims []*v1.PersistentVolumeClaim
var err error
ginkgo.By("Create storage class and PVC")
scParameters[scParamDatastoreURL] = datastoreURL
storageclass, pvclaim, err = createPVCAndStorageClass(client,
namespace, nil, scParameters, diskSize, nil, "", false, "")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer func() {
err := client.StorageV1().StorageClasses().Delete(ctx, storageclass.Name, *metav1.NewDeleteOptions(0))
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
ginkgo.By("Expect claim to provision volume successfully")
pvclaims = append(pvclaims, pvclaim)
persistentvolumes, err := fpv.WaitForPVClaimBoundPhase(client, pvclaims, framework.ClaimProvisionTimeout)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
volHandle := persistentvolumes[0].Spec.CSI.VolumeHandle
gomega.Expect(volHandle).NotTo(gomega.BeEmpty())
defer func() {
err := fpv.DeletePersistentVolumeClaim(client, pvclaim.Name, namespace)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
err = e2eVSphere.waitForCNSVolumeToBeDeleted(volHandle)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
// Verify using CNS Query API if VolumeID retrieved from PV is present.
ginkgo.By(fmt.Sprintf("Invoking QueryCNSVolumeWithResult with VolumeID: %s", volHandle))
queryResult, err := e2eVSphere.queryCNSVolumeWithResult(volHandle)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(queryResult.Volumes).ShouldNot(gomega.BeEmpty())
gomega.Expect(queryResult.Volumes[0].VolumeId.Id).To(gomega.Equal(volHandle))
ginkgo.By("Create volume snapshot class")
volumeSnapshotClass, err := snapc.SnapshotV1().VolumeSnapshotClasses().Create(ctx,
getVolumeSnapshotClassSpec(snapV1.DeletionPolicy("Delete"), nil), metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer func() {
err := snapc.SnapshotV1().VolumeSnapshotClasses().Delete(ctx,
volumeSnapshotClass.Name, metav1.DeleteOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
ginkgo.By("Create volume snapshot in CNS")
snapshotId, err := e2eVSphere.createVolumeSnapshotInCNS(volHandle)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
framework.Logf("Successfully created a snapshot in CNS %s", snapshotId)
snapshotCreated1 := true
defer func() {
if snapshotCreated1 {
err = e2eVSphere.deleteVolumeSnapshotInCNS(volHandle, snapshotId)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
}()
ginkgo.By("Query CNS and check the volume snapshot entry")
err = verifySnapshotIsCreatedInCNS(volHandle, snapshotId, false)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
snapshotHandle := volHandle + "+" + snapshotId
ginkgo.By(fmt.Sprintf("Creating volume snapshot content by snapshotHandle %s", snapshotHandle))
snapshotContentNew, err := snapc.SnapshotV1().VolumeSnapshotContents().Create(ctx,
getVolumeSnapshotContentSpec(snapV1.DeletionPolicy("Delete"), snapshotHandle,
"static-vs-cns", namespace), metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
ginkgo.By("Verify volume snapshot content is created or not")
snapshotContentNew, err = snapc.SnapshotV1().VolumeSnapshotContents().Get(ctx,
snapshotContentNew.Name, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
snapshotContentCreated2 := true
framework.Logf("Snapshotcontent name is %s", snapshotContentNew.ObjectMeta.Name)
defer func() {
if snapshotContentCreated2 {
deleteVolumeSnapshotContentWithPandoraWait(ctx, snapc,
snapshotContentNew.ObjectMeta.Name, pandoraSyncWaitTime)
}
}()
ginkgo.By("Create a volume snapshot by snapshotcontent")
volumeSnapshot2, err := snapc.SnapshotV1().VolumeSnapshots(namespace).Create(ctx,
getVolumeSnapshotSpecByName(namespace, "static-vs-cns",
snapshotContentNew.ObjectMeta.Name), metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
framework.Logf("Volume snapshot name is : %s", volumeSnapshot2.Name)
snapshotCreated2 := true
defer func() {
if snapshotCreated2 {
err = e2eVSphere.deleteVolumeSnapshotInCNS(volHandle, volumeSnapshot2.Name)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
}()
ginkgo.By("Verify volume snapshot is created")
staticSnapshot, err := waitForVolumeSnapshotReadyToUse(*snapc, ctx, namespace, volumeSnapshot2.Name)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(staticSnapshot.Status.RestoreSize.Cmp(resource.MustParse(diskSize))).To(gomega.BeZero())
framework.Logf("Snapshot details is %+v", staticSnapshot)
ginkgo.By("Deleted volume snapshot is created above")
deleteVolumeSnapshotWithPandoraWait(ctx, snapc, namespace, staticSnapshot.Name, pandoraSyncWaitTime)
snapshotCreated1 = false
snapshotCreated2 = false
framework.Logf("Wait till the volume snapshot is deleted")
err = waitForVolumeSnapshotContentToBeDeleted(*snapc, ctx, snapshotContentNew.ObjectMeta.Name)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
snapshotContentCreated2 = false
})
/*
Create/Delete snapshot via k8s API using VolumeSnapshotContent (Pre-Provisioned Snapshots)
1. Create a storage class (eg: vsan default) and create a pvc using this sc
2. The volumesnapshotclass is set to delete
3. Create a VolumeSnapshotContent using snapshot-handle with deletion policy Retain
a. get snapshotHandle by referring to an existing volume snapshot
b. this snapshot will be created dynamically, and the snapshot-content that is
created by that will be referred to get the snapshotHandle
4. Create a volume snapshot using source set to volumeSnapshotContentName above
5. Ensure the snapshot is created, verify using get VolumeSnapshot
6. Verify the restoreSize on the snapshot and the snapshotcontent is set to same as that of the pvcSize
7. Delete the above snapshot, run a get from k8s side and ensure its removed
8. Run QuerySnapshot from CNS side, the backend snapshot should be deleted
9. Verify the volume snaphsot content is not deleted
10. Delete dynamically created volume snapshot
11. Verify the volume snapshot content created by snapshot 1 is deleted automatically
12. Delete volume snapshot content 2
13. Cleanup the pvc, volume snapshot class and storage class
*/
ginkgo.It("[block-vanilla-snapshot] Verify snapshot static provisioning with "+
"deletion policy Retain", ginkgo.Label(p0, block, vanilla, snapshot, stable), func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var storageclass *storagev1.StorageClass
var pvclaim *v1.PersistentVolumeClaim
var pvclaims []*v1.PersistentVolumeClaim
var err error
var snapshotContentCreated = false
ginkgo.By("Create storage class and PVC")
scParameters[scParamDatastoreURL] = datastoreURL
storageclass, pvclaim, err = createPVCAndStorageClass(client,
namespace, nil, scParameters, diskSize, nil, "", false, "")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer func() {
err := client.StorageV1().StorageClasses().Delete(ctx, storageclass.Name, *metav1.NewDeleteOptions(0))
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
ginkgo.By("Expect claim to provision volume successfully")
pvclaims = append(pvclaims, pvclaim)
persistentvolumes, err := fpv.WaitForPVClaimBoundPhase(client, pvclaims, framework.ClaimProvisionTimeout)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
volHandle := persistentvolumes[0].Spec.CSI.VolumeHandle
gomega.Expect(volHandle).NotTo(gomega.BeEmpty())
defer func() {
err := fpv.DeletePersistentVolumeClaim(client, pvclaim.Name, namespace)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
err = e2eVSphere.waitForCNSVolumeToBeDeleted(volHandle)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
// Verify using CNS Query API if VolumeID retrieved from PV is present.
ginkgo.By(fmt.Sprintf("Invoking QueryCNSVolumeWithResult with VolumeID: %s", volHandle))
queryResult, err := e2eVSphere.queryCNSVolumeWithResult(volHandle)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(queryResult.Volumes).ShouldNot(gomega.BeEmpty())
gomega.Expect(queryResult.Volumes[0].VolumeId.Id).To(gomega.Equal(volHandle))
ginkgo.By("Create volume snapshot class")
volumeSnapshotClass, err := snapc.SnapshotV1().VolumeSnapshotClasses().Create(ctx,
getVolumeSnapshotClassSpec(snapV1.DeletionPolicy("Delete"), nil), metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer func() {
err := snapc.SnapshotV1().VolumeSnapshotClasses().Delete(ctx, volumeSnapshotClass.Name,
metav1.DeleteOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
ginkgo.By("Create a volume snapshot")
volumeSnapshot, err := snapc.SnapshotV1().VolumeSnapshots(namespace).Create(ctx,
getVolumeSnapshotSpec(namespace, volumeSnapshotClass.Name, pvclaim.Name), metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
framework.Logf("Volume snapshot name is : %s", volumeSnapshot.Name)
snapshotCreated := true
defer func() {
if snapshotContentCreated {
framework.Logf("Deleting volume snapshot content")
deleteVolumeSnapshotContentWithPandoraWait(ctx, snapc,
*volumeSnapshot.Status.BoundVolumeSnapshotContentName, pandoraSyncWaitTime)
framework.Logf("Wait till the volume snapshot is deleted")
err = waitForVolumeSnapshotContentToBeDeleted(*snapc, ctx, *volumeSnapshot.Status.BoundVolumeSnapshotContentName)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
if snapshotCreated {
framework.Logf("Deleting volume snapshot")
deleteVolumeSnapshotWithPandoraWait(ctx, snapc, namespace, volumeSnapshot.Name, pandoraSyncWaitTime)
}
}()
ginkgo.By("Verify volume snapshot is created")
volumeSnapshot, err = waitForVolumeSnapshotReadyToUse(*snapc, ctx, namespace, volumeSnapshot.Name)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(volumeSnapshot.Status.RestoreSize.Cmp(resource.MustParse(diskSize))).To(gomega.BeZero())
ginkgo.By("Verify volume snapshot content is created")
snapshotContent, err := snapc.SnapshotV1().VolumeSnapshotContents().Get(ctx,
*volumeSnapshot.Status.BoundVolumeSnapshotContentName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
snapshotContentCreated = true
gomega.Expect(*snapshotContent.Status.ReadyToUse).To(gomega.BeTrue())
framework.Logf("Get volume snapshot ID from snapshot handle")
snapshothandle := *snapshotContent.Status.SnapshotHandle
snapshotId := strings.Split(snapshothandle, "+")[1]
ginkgo.By("Query CNS and check the volume snapshot entry")
err = verifySnapshotIsCreatedInCNS(volHandle, snapshotId, false)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
ns, err := framework.CreateTestingNS(f.BaseName, client, labels_ns)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
ginkgo.By(fmt.Sprintf("Creating volume snapshot content by snapshotHandle %s", snapshothandle))
snapshotContent2, err := snapc.SnapshotV1().VolumeSnapshotContents().Create(ctx,
getVolumeSnapshotContentSpec(snapV1.DeletionPolicy("Retain"), snapshothandle,
"static-vs", ns.Name), metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
ginkgo.By("Verify volume snapshot content is created or not")
snapshotContentNew, err := snapc.SnapshotV1().VolumeSnapshotContents().Get(ctx,
snapshotContent2.Name, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
snapshotContentCreated2 := true
framework.Logf("Snapshotcontent name is %s", snapshotContentNew.ObjectMeta.Name)
defer func() {
if snapshotContentCreated2 {
deleteVolumeSnapshotContentWithPandoraWait(ctx, snapc,
snapshotContentNew.ObjectMeta.Name, pandoraSyncWaitTime)
}
}()
ginkgo.By("Create a volume snapshot by snapshotcontent")
volumeSnapshot2, err := snapc.SnapshotV1().VolumeSnapshots(ns.Name).Create(ctx,
getVolumeSnapshotSpecByName(ns.Name, "static-vs",
snapshotContentNew.ObjectMeta.Name), metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
framework.Logf("Volume snapshot name is : %s", volumeSnapshot2.Name)
snapshotCreated2 := true
defer func() {
if snapshotCreated2 {
err = snapc.SnapshotV1().VolumeSnapshots(ns.Name).Delete(ctx, "static-vs", metav1.DeleteOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
}()
ginkgo.By("Verify volume snapshot 2 is created")
staticSnapshot, err := waitForVolumeSnapshotReadyToUse(*snapc, ctx, ns.Name, volumeSnapshot2.Name)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(staticSnapshot.Status.RestoreSize.Cmp(resource.MustParse(diskSize))).To(gomega.BeZero())
framework.Logf("Snapshot details is %+v", staticSnapshot)
ginkgo.By("Deleted volume snapshot is created above")
err = snapc.SnapshotV1().VolumeSnapshots(ns.Name).Delete(ctx, staticSnapshot.Name, metav1.DeleteOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
snapshotCreated2 = false
ginkgo.By("Verify volume snapshot content is not deleted")
snapshotContentGetResult, err := snapc.SnapshotV1().VolumeSnapshotContents().Get(ctx,
snapshotContent2.Name, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(snapshotContentGetResult.Name).Should(gomega.Equal(snapshotContent2.Name))
framework.Logf("Snapshotcontent name is %s", snapshotContentGetResult.ObjectMeta.Name)
framework.Logf("Deleting volume snapshot 1")
deleteVolumeSnapshotWithPandoraWait(ctx, snapc, namespace, volumeSnapshot.Name, pandoraSyncWaitTime)
snapshotCreated = false
framework.Logf("Wait till the volume snapshot is deleted")
err = waitForVolumeSnapshotContentToBeDeleted(*snapc, ctx, snapshotContent.ObjectMeta.Name)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
snapshotContentCreated = false
framework.Logf("Delete volume snapshot content 2")
deleteVolumeSnapshotContentWithPandoraWait(ctx, snapc,
snapshotContentGetResult.ObjectMeta.Name, pandoraSyncWaitTime)
snapshotContentCreated2 = false
})
/*
Create/Delete volume snapshot with snapshot-class retention set to Retain
1. Create a storage class and create a pvc
2. Create a VolumeSnapshot class with deletionPoloicy to retain
3. Create a volume-snapshot using the above snapshot-class and pvc (from step-1) as source
4. Verify the VolumeSnashot and VolumeSnapshotClass are created
5. Query the Snapshot from CNS side - should pass
6. Delete the above snasphot, run a get from k8s side and ensure its removed
7. Verify that the underlying VolumeSnapshotContent is still not deleted
8. The backend CNS snapshot should still be present
9. Query the Snasphot from CNS side using the volumeId
10. Cleanup the snapshot and delete the volume
*/
ginkgo.It("[block-vanilla-snapshot] Verify snapshot static provisioning with deletion "+
"policy Retain - test2", ginkgo.Label(p0, block, vanilla, snapshot, stable), func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var storageclass *storagev1.StorageClass
var pvclaim *v1.PersistentVolumeClaim
var pvclaims []*v1.PersistentVolumeClaim
var err error
var snapshotContentCreated = false
var contentName string
ginkgo.By("Create storage class and PVC")
scParameters[scParamDatastoreURL] = datastoreURL
storageclass, pvclaim, err = createPVCAndStorageClass(client,
namespace, nil, scParameters, diskSize, nil, "", false, "")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer func() {
err := client.StorageV1().StorageClasses().Delete(ctx, storageclass.Name, *metav1.NewDeleteOptions(0))
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
ginkgo.By("Expect claim to provision volume successfully")
pvclaims = append(pvclaims, pvclaim)
persistentvolumes, err := fpv.WaitForPVClaimBoundPhase(client, pvclaims, framework.ClaimProvisionTimeout)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
volHandle := persistentvolumes[0].Spec.CSI.VolumeHandle
gomega.Expect(volHandle).NotTo(gomega.BeEmpty())
defer func() {
err := fpv.DeletePersistentVolumeClaim(client, pvclaim.Name, namespace)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
err = e2eVSphere.waitForCNSVolumeToBeDeleted(volHandle)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
// Verify using CNS Query API if VolumeID retrieved from PV is present.
ginkgo.By(fmt.Sprintf("Invoking QueryCNSVolumeWithResult with VolumeID: %s", volHandle))
queryResult, err := e2eVSphere.queryCNSVolumeWithResult(volHandle)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(queryResult.Volumes).ShouldNot(gomega.BeEmpty())
gomega.Expect(queryResult.Volumes[0].VolumeId.Id).To(gomega.Equal(volHandle))
ginkgo.By("Create volume snapshot class")
volumeSnapshotClass, err := snapc.SnapshotV1().VolumeSnapshotClasses().Create(ctx,
getVolumeSnapshotClassSpec(snapV1.DeletionPolicy("Retain"), nil), metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer func() {
err := snapc.SnapshotV1().VolumeSnapshotClasses().Delete(ctx, volumeSnapshotClass.Name,
metav1.DeleteOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
ginkgo.By("Create a volume snapshot")
snapshot1, err := snapc.SnapshotV1().VolumeSnapshots(namespace).Create(ctx,
getVolumeSnapshotSpec(namespace, volumeSnapshotClass.Name, pvclaim.Name), metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
framework.Logf("Volume snapshot name is : %s", snapshot1.Name)
snapshotCreated := true
defer func() {
if snapshotCreated {
framework.Logf("Deleting volume snapshot")
deleteVolumeSnapshotWithPandoraWait(ctx, snapc, namespace, snapshot1.Name, pandoraSyncWaitTime)
}
if snapshotContentCreated {
framework.Logf("Deleting volume snapshot content")
deleteVolumeSnapshotContentWithPandoraWait(ctx, snapc,
contentName, pandoraSyncWaitTime)
framework.Logf("Wait till the volume snapshot is deleted")
err = waitForVolumeSnapshotContentToBeDeleted(*snapc, ctx, contentName)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
}()
ginkgo.By("Verify volume snapshot is created")
snapshot1_updated, err := waitForVolumeSnapshotReadyToUse(*snapc, ctx, namespace, snapshot1.Name)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(snapshot1_updated.Status.RestoreSize.Cmp(resource.MustParse(diskSize))).To(gomega.BeZero())
ginkgo.By("Verify volume snapshot content is created")
content, err := snapc.SnapshotV1().VolumeSnapshotContents().Get(ctx,
*snapshot1_updated.Status.BoundVolumeSnapshotContentName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
snapshotContentCreated = true
gomega.Expect(*content.Status.ReadyToUse).To(gomega.BeTrue())
contentName = content.Name
framework.Logf("Get volume snapshot ID from snapshot handle")
snapshothandle := *content.Status.SnapshotHandle
snapshotId := strings.Split(snapshothandle, "+")[1]
ginkgo.By("Query CNS and check the volume snapshot entry")
err = verifySnapshotIsCreatedInCNS(volHandle, snapshotId, false)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
framework.Logf("Deleting volume snapshot 1 " + snapshot1.Name)
deleteVolumeSnapshotWithPandoraWait(ctx, snapc, namespace, snapshot1.Name, pandoraSyncWaitTime)
snapshotCreated = false
_, err = snapc.SnapshotV1().VolumeSnapshots(namespace).Get(ctx, snapshot1.Name,
metav1.GetOptions{})
gomega.Expect(err).To(gomega.HaveOccurred())
ginkgo.By("Delete snapshot entry from CNS")
err = e2eVSphere.deleteVolumeSnapshotInCNS(volHandle, snapshotId)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
ginkgo.By("Verify snapshot entry is deleted from CNS")
err = verifySnapshotIsDeletedInCNS(volHandle, snapshotId, false)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
ginkgo.By("Verify volume snapshot content is not deleted")
snapshotContentGetResult, err := snapc.SnapshotV1().VolumeSnapshotContents().Get(ctx,
content.Name, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(snapshotContentGetResult.Name).Should(gomega.Equal(content.Name))
framework.Logf("Snapshotcontent name is %s", snapshotContentGetResult.Name)
framework.Logf("Delete volume snapshot content")
deleteVolumeSnapshotContentWithPandoraWait(ctx, snapc,
snapshotContentGetResult.Name, pandoraSyncWaitTime)
snapshotContentCreated = false
framework.Logf("Wait till the volume snapshot content is deleted")
err = waitForVolumeSnapshotContentToBeDeleted(*snapc, ctx, snapshotContentGetResult.Name)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
/*
Volume restore using snapshot (a) dynamic snapshot (b) pre-provisioned snapshot
1. Create a sc, a pvc and attach the pvc to a pod, write a file
2. Create pre-provisioned and dynamically provisioned snapshots using this pvc
3. Create new volumes (pvcFromPreProvSS and pvcFromDynamicSS) using these
snapshots as source, use the same sc
4. Ensure the pvc gets provisioned and is Bound
5. Attach the pvc to a pod and ensure data from snapshot is available
(file that was written in step.1 should be available)
6. And also write new data to the restored volumes and it should succeed
7. Delete the snapshots and pvcs/pods created in steps 1,2,3
8. Continue to write new data to the restore volumes and it should succeed
9. Create new snapshots on restore volume and verify it succeeds
10. Run cleanup: Delete snapshots, restored-volumes, pods
*/
ginkgo.It("[block-vanilla-snapshot] Volume restore using snapshot a dynamic snapshot b "+
"pre-provisioned snapshot", ginkgo.Label(p0, block, vanilla, snapshot, stable), func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var storageclass *storagev1.StorageClass
var pvclaim *v1.PersistentVolumeClaim
var pvclaims []*v1.PersistentVolumeClaim
var err error
var snapshotContentCreated = false
ginkgo.By("Create storage class and PVC")
scParameters[scParamDatastoreURL] = datastoreURL
storageclass, pvclaim, err = createPVCAndStorageClass(client,
namespace, nil, scParameters, diskSize, nil, "", false, "")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer func() {
err := client.StorageV1().StorageClasses().Delete(ctx, storageclass.Name, *metav1.NewDeleteOptions(0))
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
ginkgo.By("Expect claim to provision volume successfully")
pvclaims = append(pvclaims, pvclaim)
persistentvolumes, err := fpv.WaitForPVClaimBoundPhase(client, pvclaims, framework.ClaimProvisionTimeout)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
volHandle := persistentvolumes[0].Spec.CSI.VolumeHandle
gomega.Expect(volHandle).NotTo(gomega.BeEmpty())
defer func() {
err := fpv.DeletePersistentVolumeClaim(client, pvclaim.Name, namespace)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
err = e2eVSphere.waitForCNSVolumeToBeDeleted(volHandle)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
// Verify using CNS Query API if VolumeID retrieved from PV is present.
ginkgo.By(fmt.Sprintf("Invoking QueryCNSVolumeWithResult with VolumeID: %s", volHandle))
queryResult, err := e2eVSphere.queryCNSVolumeWithResult(volHandle)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(queryResult.Volumes).ShouldNot(gomega.BeEmpty())
gomega.Expect(queryResult.Volumes[0].VolumeId.Id).To(gomega.Equal(volHandle))
ginkgo.By("Create volume snapshot class")
volumeSnapshotClass, err := snapc.SnapshotV1().VolumeSnapshotClasses().Create(ctx,
getVolumeSnapshotClassSpec(snapV1.DeletionPolicy("Delete"), nil), metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer func() {
err := snapc.SnapshotV1().VolumeSnapshotClasses().Delete(ctx, volumeSnapshotClass.Name,
metav1.DeleteOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
ginkgo.By("Create a volume snapshot")
volumeSnapshot, err := snapc.SnapshotV1().VolumeSnapshots(namespace).Create(ctx,
getVolumeSnapshotSpec(namespace, volumeSnapshotClass.Name, pvclaim.Name), metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
framework.Logf("Volume snapshot name is : %s", volumeSnapshot.Name)
snapshotCreated := true
defer func() {
if snapshotContentCreated {
framework.Logf("Deleting volume snapshot content")
deleteVolumeSnapshotContentWithPandoraWait(ctx, snapc,
*volumeSnapshot.Status.BoundVolumeSnapshotContentName, pandoraSyncWaitTime)
framework.Logf("Wait till the volume snapshot is deleted")
err = waitForVolumeSnapshotContentToBeDeleted(*snapc, ctx, *volumeSnapshot.Status.BoundVolumeSnapshotContentName)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
if snapshotCreated {
framework.Logf("Deleting volume snapshot")
deleteVolumeSnapshotWithPandoraWait(ctx, snapc, namespace, volumeSnapshot.Name, pandoraSyncWaitTime)
}
}()