Skip to content

Commit f71aad6

Browse files
committed
test: add e2e test "dynamically_provisioned_read_only_volume"
Signed-off-by: ZeroMagic <[email protected]>
1 parent 4a14d99 commit f71aad6

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

test/e2e/dynamic_provisioning.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,29 @@ var _ = Describe("Dynamic Provisioning", func() {
7373
}
7474
test.Run(cs, ns)
7575
})
76+
77+
// Track issue https://github.com/kubernetes/kubernetes/issues/70505
78+
It("should create a volume on demand and mount it as readOnly in a pod", func() {
79+
pods := []testsuites.PodDetails{
80+
{
81+
Cmd: "touch /mnt/test-1/data",
82+
Volumes: []testsuites.VolumeDetails{
83+
{
84+
FSType: "ext4",
85+
ClaimSize: "10Gi",
86+
VolumeMount: testsuites.VolumeMountDetails{
87+
NameGenerate: "test-volume-",
88+
MountPathGenerate: "/mnt/test-",
89+
ReadOnly: true,
90+
},
91+
},
92+
},
93+
},
94+
}
95+
test := testsuites.DynamicallyProvisionedReadOnlyVolumeTest{
96+
CSIDriver: testDriver,
97+
Pods: pods,
98+
}
99+
test.Run(cs, ns)
100+
})
76101
})
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
"github.com/csi-driver/blobfuse-csi-driver/test/e2e/driver"
22+
"k8s.io/kubernetes/test/e2e/framework"
23+
24+
"k8s.io/api/core/v1"
25+
clientset "k8s.io/client-go/kubernetes"
26+
27+
. "github.com/onsi/ginkgo"
28+
. "github.com/onsi/gomega"
29+
)
30+
31+
const expectedReadOnlyLog = "Read-only file system"
32+
33+
// DynamicallyProvisionedReadOnlyVolumeTest will provision required StorageClass(es), PVC(s) and Pod(s)
34+
// Waiting for the PV provisioner to create a new PV
35+
// Testing that the Pod(s) cannot write to the volume when mounted
36+
type DynamicallyProvisionedReadOnlyVolumeTest struct {
37+
CSIDriver driver.DynamicPVTestDriver
38+
Pods []PodDetails
39+
}
40+
41+
func (t *DynamicallyProvisionedReadOnlyVolumeTest) Run(client clientset.Interface, namespace *v1.Namespace) {
42+
for _, pod := range t.Pods {
43+
tpod, cleanup := pod.SetupWithDynamicVolumes(client, namespace, t.CSIDriver)
44+
// defer must be called here for resources not get removed before using them
45+
for i := range cleanup {
46+
defer cleanup[i]()
47+
}
48+
49+
By("deploying the pod")
50+
tpod.Create()
51+
defer tpod.Cleanup()
52+
By("checking that the pods command exits with an error")
53+
tpod.WaitForFailure()
54+
By("checking that pod logs contain expected message")
55+
body, err := tpod.Logs()
56+
framework.ExpectNoError(err, fmt.Sprintf("Error getting logs for pod %s: %v", tpod.pod.Name, err))
57+
Expect(string(body)).To(ContainSubstring(expectedReadOnlyLog))
58+
}
59+
}

0 commit comments

Comments
 (0)