Skip to content

Commit 28a8f11

Browse files
authored
Merge pull request #57 from ZeroMagic/pre_provisioned_read_only_volume
test: add e2e test "pre_provisioned_read_only_volume"
2 parents 0018ccf + b9d10a7 commit 28a8f11

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

test/e2e/pre_provisioning.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,40 @@ var _ = Describe("[blobfuse-csi-e2e] [single-az] Pre-Provisioned", func() {
7777
}
7878
})
7979

80+
It("[env] should use a pre-provisioned volume and mount it as readOnly in a pod", func() {
81+
req := makeCreateVolumeReq("pre-provisioned-readOnly")
82+
resp, err := blobfuseDriver.CreateVolume(context.Background(), req)
83+
if err != nil {
84+
Fail(fmt.Sprintf("create volume error: %v", err))
85+
}
86+
volumeID = resp.Volume.VolumeId
87+
By(fmt.Sprintf("Successfully provisioned BloBFuse volume: %q\n", volumeID))
88+
89+
volumeSize := fmt.Sprintf("%dGi", defaultVolumeSize)
90+
pods := []testsuites.PodDetails{
91+
{
92+
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
93+
Volumes: []testsuites.VolumeDetails{
94+
{
95+
VolumeID: volumeID,
96+
FSType: "ext4",
97+
ClaimSize: volumeSize,
98+
VolumeMount: testsuites.VolumeMountDetails{
99+
NameGenerate: "test-volume-",
100+
MountPathGenerate: "/mnt/test-",
101+
ReadOnly: true,
102+
},
103+
},
104+
},
105+
},
106+
}
107+
test := testsuites.PreProvisionedReadOnlyVolumeTest{
108+
CSIDriver: testDriver,
109+
Pods: pods,
110+
}
111+
test.Run(cs, ns)
112+
})
113+
80114
It(fmt.Sprintf("[env] should use a pre-provisioned volume and retain PV with reclaimPolicy %q", v1.PersistentVolumeReclaimRetain), func() {
81115
req := makeCreateVolumeReq("pre-provisioned-retain-reclaimPolicy")
82116
resp, err := blobfuseDriver.CreateVolume(context.Background(), req)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Copyright 2019 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+
"fmt"
21+
22+
"github.com/csi-driver/blobfuse-csi-driver/test/e2e/driver"
23+
24+
"k8s.io/api/core/v1"
25+
clientset "k8s.io/client-go/kubernetes"
26+
"k8s.io/kubernetes/test/e2e/framework"
27+
28+
. "github.com/onsi/ginkgo"
29+
. "github.com/onsi/gomega"
30+
)
31+
32+
// PreProvisionedReadOnlyVolumeTest will provision required PV(s), PVC(s) and Pod(s)
33+
// Testing that the Pod(s) cannot write to the volume when mounted
34+
type PreProvisionedReadOnlyVolumeTest struct {
35+
CSIDriver driver.PreProvisionedVolumeTestDriver
36+
Pods []PodDetails
37+
}
38+
39+
func (t *PreProvisionedReadOnlyVolumeTest) Run(client clientset.Interface, namespace *v1.Namespace) {
40+
for _, pod := range t.Pods {
41+
tpod, cleanup := pod.SetupWithPreProvisionedVolumes(client, namespace, t.CSIDriver)
42+
// defer must be called here for resources not get removed before using them
43+
for i := range cleanup {
44+
defer cleanup[i]()
45+
}
46+
47+
By("deploying the pod")
48+
tpod.Create()
49+
defer tpod.Cleanup()
50+
By("checking that the pods command exits with an error")
51+
tpod.WaitForFailure()
52+
By("checking that pod logs contain expected message")
53+
body, err := tpod.Logs()
54+
framework.ExpectNoError(err, fmt.Sprintf("Error getting logs for pod %s: %v", tpod.pod.Name, err))
55+
Expect(string(body)).To(ContainSubstring(expectedReadOnlyLog))
56+
}
57+
}

0 commit comments

Comments
 (0)