github.com/jmclong/azuredisk-csi-driver@v0.7.0/test/e2e/testsuites/dynamically_provisioned_volume_snapshot_tester.go (about) 1 /* 2 Copyright 2020 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package testsuites 18 19 import ( 20 "sigs.k8s.io/azuredisk-csi-driver/test/e2e/driver" 21 22 "github.com/onsi/ginkgo" 23 v1 "k8s.io/api/core/v1" 24 clientset "k8s.io/client-go/kubernetes" 25 restclientset "k8s.io/client-go/rest" 26 ) 27 28 // DynamicallyProvisionedVolumeSnapshotTest will provision required StorageClass(es),VolumeSnapshotClass(es), PVC(s) and Pod(s) 29 // Waiting for the PV provisioner to create a new PV 30 // Testing if the Pod(s) can write and read to mounted volumes 31 // Create a snapshot, validate the data is still on the disk, and then write and read to it again 32 // And finally delete the snapshot 33 // This test only supports a single volume 34 type DynamicallyProvisionedVolumeSnapshotTest struct { 35 CSIDriver driver.PVTestDriver 36 Pod PodDetails 37 PodWithSnapshot PodDetails 38 } 39 40 func (t *DynamicallyProvisionedVolumeSnapshotTest) Run(client clientset.Interface, restclient restclientset.Interface, namespace *v1.Namespace) { 41 tpod := NewTestPod(client, namespace, t.Pod.Cmd, t.Pod.IsWindows) 42 volume := t.Pod.Volumes[0] 43 tpvc, pvcCleanup := volume.SetupDynamicPersistentVolumeClaim(client, namespace, t.CSIDriver) 44 for i := range pvcCleanup { 45 defer pvcCleanup[i]() 46 } 47 tpod.SetupVolume(tpvc.persistentVolumeClaim, volume.VolumeMount.NameGenerate+"1", volume.VolumeMount.MountPathGenerate+"1", volume.VolumeMount.ReadOnly) 48 49 ginkgo.By("deploying the pod") 50 tpod.Create() 51 defer tpod.Cleanup() 52 ginkgo.By("checking that the pod's command exits with no error") 53 tpod.WaitForSuccess() 54 55 ginkgo.By("creating volume snapshot class") 56 tvsc, cleanup := CreateVolumeSnapshotClass(restclient, namespace, t.CSIDriver) 57 defer cleanup() 58 59 ginkgo.By("taking snapshots") 60 snapshot := tvsc.CreateSnapshot(tpvc.persistentVolumeClaim) 61 defer tvsc.DeleteSnapshot(snapshot) 62 tvsc.ReadyToUse(snapshot) 63 64 snapshotVolume := volume 65 snapshotVolume.DataSource = &DataSource{ 66 Kind: VolumeSnapshotKind, 67 Name: snapshot.Name, 68 } 69 t.PodWithSnapshot.Volumes = []VolumeDetails{snapshotVolume} 70 tPodWithSnapshot, tPodWithSnapshotCleanup := t.PodWithSnapshot.SetupWithDynamicVolumes(client, namespace, t.CSIDriver) 71 for i := range tPodWithSnapshotCleanup { 72 defer tPodWithSnapshotCleanup[i]() 73 } 74 ginkgo.By("deploying a second pod with a volume restored from the snapshot") 75 tPodWithSnapshot.Create() 76 defer tPodWithSnapshot.Cleanup() 77 ginkgo.By("checking that the pod's command exits with no error") 78 tPodWithSnapshot.WaitForSuccess() 79 }