Skip to content

Commit 89a739d

Browse files
committed
Pre provisioned volume test cases added
1 parent a0fffa8 commit 89a739d

File tree

4 files changed

+167
-4
lines changed

4 files changed

+167
-4
lines changed

tests/e2e/dynamic_provisioning.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ var _ = Describe("[powervs-csi-e2e]Dynamic Provisioning", func() {
3636
f := framework.NewDefaultFramework("powervs")
3737

3838
var (
39-
cs clientset.Interface
40-
ns *v1.Namespace
41-
//powervsDriver driver.PreProvisionedVolumeTestDriver
39+
cs clientset.Interface
40+
ns *v1.Namespace
4241
pvTestDriver driver.DynamicPVTestDriver
4342
volumeTypes = powervscloud.ValidVolumeTypes
4443
fsTypes = []string{powervscsidriver.FSTypeXfs}

tests/e2e/pre_provisioning.go

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
clientset "k8s.io/client-go/kubernetes"
2828
"k8s.io/kubernetes/test/e2e/framework"
2929
powervscloud "sigs.k8s.io/ibm-powervs-block-csi-driver/pkg/cloud"
30+
powervscsidriver "sigs.k8s.io/ibm-powervs-block-csi-driver/pkg/driver"
3031
"sigs.k8s.io/ibm-powervs-block-csi-driver/tests/e2e/driver"
3132
"sigs.k8s.io/ibm-powervs-block-csi-driver/tests/e2e/testsuites"
3233
)
@@ -51,14 +52,15 @@ var _ = Describe("[powervs-csi-e2e]Pre-Provisioned", func() {
5152
cloud powervscloud.Cloud
5253
volumeID string
5354
diskSize string
55+
powervsDriver driver.PreProvisionedVolumeTestDriver
5456
pvTestDriver driver.PVTestDriver
5557
skipManuallyDeletingVolume bool
5658
)
5759

5860
BeforeEach(func() {
5961
cs = f.ClientSet
6062
ns = f.Namespace
61-
63+
powervsDriver = driver.InitPowervsCSIDriver()
6264
diskOptions := &powervscloud.DiskOptions{
6365
CapacityBytes: defaultDiskSizeBytes,
6466
VolumeType: defaultVolumeType,
@@ -127,4 +129,64 @@ var _ = Describe("[powervs-csi-e2e]Pre-Provisioned", func() {
127129
}
128130
test.Run(cs, ns)
129131
})
132+
133+
It("[env] should use a pre-provisioned volume and mount it as readOnly in a pod", func() {
134+
pods := []testsuites.PodDetails{
135+
{
136+
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
137+
Volumes: []testsuites.VolumeDetails{
138+
{
139+
VolumeID: volumeID,
140+
FSType: powervscsidriver.FSTypeExt4,
141+
ClaimSize: diskSize,
142+
VolumeMount: testsuites.VolumeMountDetails{
143+
NameGenerate: "test-volume-",
144+
MountPathGenerate: "/mnt/test-",
145+
ReadOnly: true,
146+
},
147+
},
148+
},
149+
},
150+
}
151+
test := testsuites.PreProvisionedReadOnlyVolumeTest{
152+
CSIDriver: powervsDriver,
153+
Pods: pods,
154+
}
155+
test.Run(cs, ns)
156+
})
157+
158+
It(fmt.Sprintf("[env] should use a pre-provisioned volume and retain PV with reclaimPolicy %q", v1.PersistentVolumeReclaimRetain), func() {
159+
reclaimPolicy := v1.PersistentVolumeReclaimRetain
160+
volumes := []testsuites.VolumeDetails{
161+
{
162+
VolumeID: volumeID,
163+
FSType: powervscsidriver.FSTypeExt4,
164+
ClaimSize: diskSize,
165+
ReclaimPolicy: &reclaimPolicy,
166+
},
167+
}
168+
test := testsuites.PreProvisionedReclaimPolicyTest{
169+
CSIDriver: powervsDriver,
170+
Volumes: volumes,
171+
}
172+
test.Run(cs, ns)
173+
})
174+
175+
It(fmt.Sprintf("[env] should use a pre-provisioned volume and delete PV with reclaimPolicy %q", v1.PersistentVolumeReclaimDelete), func() {
176+
reclaimPolicy := v1.PersistentVolumeReclaimDelete
177+
skipManuallyDeletingVolume = true
178+
volumes := []testsuites.VolumeDetails{
179+
{
180+
VolumeID: volumeID,
181+
FSType: powervscsidriver.FSTypeExt4,
182+
ClaimSize: diskSize,
183+
ReclaimPolicy: &reclaimPolicy,
184+
},
185+
}
186+
test := testsuites.PreProvisionedReclaimPolicyTest{
187+
CSIDriver: powervsDriver,
188+
Volumes: volumes,
189+
}
190+
test.Run(cs, ns)
191+
})
130192
})
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright 2022 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+
v1 "k8s.io/api/core/v1"
23+
clientset "k8s.io/client-go/kubernetes"
24+
"k8s.io/kubernetes/test/e2e/framework"
25+
"sigs.k8s.io/ibm-powervs-block-csi-driver/tests/e2e/driver"
26+
27+
. "github.com/onsi/ginkgo"
28+
. "github.com/onsi/gomega"
29+
)
30+
31+
// PreProvisionedReadOnlyVolumeTest will provision required PV(s), PVC(s) and Pod(s)
32+
// Testing that the Pod(s) cannot write to the volume when mounted
33+
type PreProvisionedReadOnlyVolumeTest struct {
34+
CSIDriver driver.PreProvisionedVolumeTestDriver
35+
Pods []PodDetails
36+
}
37+
38+
func (t *PreProvisionedReadOnlyVolumeTest) Run(client clientset.Interface, namespace *v1.Namespace) {
39+
for _, pod := range t.Pods {
40+
tpod, cleanup := pod.SetupWithPreProvisionedVolumes(client, namespace, t.CSIDriver)
41+
// defer must be called here for resources not get removed before using them
42+
for i := range cleanup {
43+
defer cleanup[i]()
44+
}
45+
46+
By("deploying the pod")
47+
tpod.Create()
48+
defer tpod.Cleanup()
49+
By("checking that the pods command exits with an error")
50+
tpod.WaitForFailure()
51+
By("checking that pod logs contain expected message")
52+
body, err := tpod.Logs()
53+
framework.ExpectNoError(err, fmt.Sprintf("Error getting logs for pod %s: %v", tpod.pod.Name, err))
54+
Expect(string(body)).To(ContainSubstring(expectedReadOnlyLog))
55+
}
56+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright 2022 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/ibm-powervs-block-csi-driver/tests/e2e/driver"
21+
22+
v1 "k8s.io/api/core/v1"
23+
clientset "k8s.io/client-go/kubernetes"
24+
)
25+
26+
// PreProvisionedReclaimPolicyTest will provision required PV(s) and PVC(s)
27+
// Testing the correct behavior for different reclaimPolicies
28+
type PreProvisionedReclaimPolicyTest struct {
29+
CSIDriver driver.PreProvisionedVolumeTestDriver
30+
Volumes []VolumeDetails
31+
}
32+
33+
func (t *PreProvisionedReclaimPolicyTest) Run(client clientset.Interface, namespace *v1.Namespace) {
34+
for _, volume := range t.Volumes {
35+
tpvc, _ := volume.SetupPreProvisionedPersistentVolumeClaim(client, namespace, t.CSIDriver)
36+
37+
// will delete the PVC
38+
// will also wait for PV to be deleted when reclaimPolicy=Delete
39+
tpvc.Cleanup()
40+
// first check PV stills exists, then manually delete it
41+
if tpvc.ReclaimPolicy() == v1.PersistentVolumeReclaimRetain {
42+
tpvc.WaitForPersistentVolumePhase(v1.VolumeReleased)
43+
tpvc.DeleteBoundPersistentVolume()
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)