Skip to content

Commit

Permalink
test: add inline volume test
Browse files Browse the repository at this point in the history
use managed disk

skip delete volume in test
  • Loading branch information
andyzhangx committed Apr 14, 2021
1 parent 38b07eb commit 1b2f39d
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/e2e/pre_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,47 @@ var _ = ginkgo.Describe("Pre-Provisioned", func() {
}
test.Run(cs, ns)
})

ginkgo.It("should create an inline volume by in-tree driver [kubernetes.io/azure-disk]", func() {
if !isUsingInTreeVolumePlugin {
ginkgo.Skip("test case is only available for in-tree driver")
}

skipManuallyDeletingVolume = true
req := makeCreateVolumeReq("pre-provisioned-inline-volume", defaultDiskSize)
resp, err := azurediskDriver.CreateVolume(context.Background(), req)
if err != nil {
ginkgo.Fail(fmt.Sprintf("create volume error: %v", err))
}
volumeID = resp.Volume.VolumeId
ginkgo.By(fmt.Sprintf("Successfully provisioned AzureDisk volume: %q\n", volumeID))

diskSize := fmt.Sprintf("%dGi", defaultDiskSize)
pods := []testsuites.PodDetails{
{
Cmd: convertToPowershellorCmdCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
Volumes: []testsuites.VolumeDetails{
{
VolumeID: volumeID,
ClaimSize: diskSize,
VolumeMount: testsuites.VolumeMountDetails{
NameGenerate: "test-volume-",
MountPathGenerate: "/mnt/test-",
},
},
},
IsWindows: isWindowsCluster,
},
}

test := testsuites.PreProvisionedInlineVolumeTest{
CSIDriver: testDriver,
Pods: pods,
DiskURI: volumeID,
ReadOnly: false,
}
test.Run(cs, ns)
})
})
})

Expand Down
51 changes: 51 additions & 0 deletions test/e2e/testsuites/pre_provisioned_inline_volume_tester.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2019 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 testsuites

import (
"sigs.k8s.io/azuredisk-csi-driver/test/e2e/driver"

"github.com/onsi/ginkgo"
v1 "k8s.io/api/core/v1"
clientset "k8s.io/client-go/kubernetes"
)

// PreProvisionedInlineVolumeTest
// Waiting for the PV provisioner to create an inline volume
// Testing if the Pod(s) Cmd is run with a 0 exit code
type PreProvisionedInlineVolumeTest struct {
CSIDriver driver.PreProvisionedVolumeTestDriver
Pods []PodDetails
DiskURI string
ReadOnly bool
}

func (t *PreProvisionedInlineVolumeTest) Run(client clientset.Interface, namespace *v1.Namespace) {
for _, pod := range t.Pods {
tpod, cleanup := pod.SetupWithInlineVolumes(client, namespace, t.CSIDriver, t.DiskURI, t.ReadOnly)
// defer must be called here for resources not get removed before using them
for i := range cleanup {
defer cleanup[i]()
}

ginkgo.By("deploying the pod")
tpod.Create()
defer tpod.Cleanup()
ginkgo.By("checking that the pod's command exits with no error")
tpod.WaitForSuccess()
}
}
9 changes: 9 additions & 0 deletions test/e2e/testsuites/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ func (pod *PodDetails) SetupWithDynamicMultipleVolumes(client clientset.Interfac
return tpod, cleanupFuncs
}

func (pod *PodDetails) SetupWithInlineVolumes(client clientset.Interface, namespace *v1.Namespace, csiDriver driver.PreProvisionedVolumeTestDriver, diskURI string, readOnly bool) (*TestPod, []func()) {
tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows)
cleanupFuncs := make([]func(), 0)
for n, v := range pod.Volumes {
tpod.SetupInlineVolume(fmt.Sprintf("%s%d", v.VolumeMount.NameGenerate, n+1), fmt.Sprintf("%s%d", v.VolumeMount.MountPathGenerate, n+1), diskURI, readOnly)
}
return tpod, cleanupFuncs
}

func (pod *PodDetails) SetupWithPreProvisionedVolumes(client clientset.Interface, namespace *v1.Namespace, csiDriver driver.PreProvisionedVolumeTestDriver, volumeContext map[string]string) (*TestPod, []func()) {
tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows)
cleanupFuncs := make([]func(), 0)
Expand Down
24 changes: 24 additions & 0 deletions test/e2e/testsuites/testsuites.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,30 @@ func (t *TestPod) SetupVolume(pvc *v1.PersistentVolumeClaim, name, mountPath str
t.pod.Spec.Volumes = append(t.pod.Spec.Volumes, volume)
}

func (t *TestPod) SetupInlineVolume(name, mountPath, diskURI string, readOnly bool) {
volumeMount := v1.VolumeMount{
Name: name,
MountPath: mountPath,
ReadOnly: readOnly,
}
t.pod.Spec.Containers[0].VolumeMounts = append(t.pod.Spec.Containers[0].VolumeMounts, volumeMount)

kind := v1.AzureDataDiskKind("Managed")
diskName, _ := azuredisk.GetDiskName(diskURI)
volume := v1.Volume{
Name: name,
VolumeSource: v1.VolumeSource{
AzureDisk: &v1.AzureDiskVolumeSource{
DiskName: diskName,
DataDiskURI: diskURI,
ReadOnly: &readOnly,
Kind: &kind,
},
},
}
t.pod.Spec.Volumes = append(t.pod.Spec.Volumes, volume)
}

func (t *TestPod) SetupRawBlockVolume(pvc *v1.PersistentVolumeClaim, name, devicePath string) {
volumeDevice := v1.VolumeDevice{
Name: name,
Expand Down

0 comments on commit 1b2f39d

Please sign in to comment.