Skip to content

Commit a838493

Browse files
authored
Merge pull request #171 from andyzhangx/invalid-mountoption-test
test: add negative mount options e2e test
2 parents 5b637cb + ec6269b commit a838493

File tree

6 files changed

+168
-0
lines changed

6 files changed

+168
-0
lines changed

test/e2e/dynamic_provisioning_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,32 @@ var _ = ginkgo.Describe("[blobfuse-csi-e2e] Dynamic Provisioning", func() {
232232
}
233233
test.Run(cs, ns)
234234
})
235+
236+
ginkgo.It("should receive FailedMount event with invalid mount options", func() {
237+
pods := []testsuites.PodDetails{
238+
{
239+
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
240+
Volumes: []testsuites.VolumeDetails{
241+
{
242+
ClaimSize: "10Gi",
243+
MountOptions: []string{
244+
"invalid",
245+
"mount",
246+
"options",
247+
},
248+
VolumeMount: testsuites.VolumeMountDetails{
249+
NameGenerate: "test-volume-",
250+
MountPathGenerate: "/mnt/test-",
251+
},
252+
},
253+
},
254+
},
255+
}
256+
test := testsuites.DynamicallyProvisionedInvalidMountOptions{
257+
CSIDriver: testDriver,
258+
Pods: pods,
259+
StorageClassParameters: map[string]string{"skuName": "Standard_LRS"},
260+
}
261+
test.Run(cs, ns)
262+
})
235263
})
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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/blobfuse-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+
)
26+
27+
// DynamicallyProvisionedInvalidMountOptions will provision a storage class with invalid mount options
28+
// Testing if the Pod(s) Cmd is run with a 0 exit code
29+
type DynamicallyProvisionedInvalidMountOptions struct {
30+
CSIDriver driver.DynamicPVTestDriver
31+
Pods []PodDetails
32+
StorageClassParameters map[string]string
33+
}
34+
35+
func (t *DynamicallyProvisionedInvalidMountOptions) Run(client clientset.Interface, namespace *v1.Namespace) {
36+
for _, pod := range t.Pods {
37+
tpod, cleanup := pod.SetupWithDynamicVolumes(client, namespace, t.CSIDriver, t.StorageClassParameters)
38+
// defer must be called here for resources not get removed before using them
39+
for i := range cleanup {
40+
defer cleanup[i]()
41+
}
42+
43+
ginkgo.By("deploying the pod")
44+
tpod.Create()
45+
defer tpod.Cleanup()
46+
ginkgo.By("checking that the pod has 'FailedMount' event")
47+
tpod.WaitForFailedMountError()
48+
}
49+
}

test/e2e/testsuites/testsuites.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ import (
3333
apierrs "k8s.io/apimachinery/pkg/api/errors"
3434
"k8s.io/apimachinery/pkg/api/resource"
3535
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
36+
"k8s.io/apimachinery/pkg/fields"
3637
clientset "k8s.io/client-go/kubernetes"
3738
deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
39+
"k8s.io/kubernetes/pkg/kubelet/events"
3840
"k8s.io/kubernetes/test/e2e/framework"
41+
e2eevents "k8s.io/kubernetes/test/e2e/framework/events"
3942
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
4043
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
4144
e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
@@ -456,6 +459,16 @@ func (t *TestPod) WaitForRunning() {
456459
framework.ExpectNoError(err)
457460
}
458461

462+
func (t *TestPod) WaitForFailedMountError() {
463+
err := e2eevents.WaitTimeoutForEvent(
464+
t.client,
465+
t.namespace.Name,
466+
fields.Set{"reason": events.FailedMountVolume}.AsSelector().String(),
467+
"",
468+
pollLongTimeout)
469+
framework.ExpectNoError(err)
470+
}
471+
459472
// Ideally this would be in "k8s.io/kubernetes/test/e2e/framework"
460473
// Similar to framework.WaitForPodSuccessInNamespaceSlow
461474
var podFailedCondition = func(pod *v1.Pod) (bool, error) {

vendor/k8s.io/kubernetes/test/e2e/framework/events/BUILD

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/k8s.io/kubernetes/test/e2e/framework/events/events.go

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ k8s.io/kubernetes/pkg/volume/util/volumepathhandler
744744
k8s.io/kubernetes/test/e2e/framework
745745
k8s.io/kubernetes/test/e2e/framework/auth
746746
k8s.io/kubernetes/test/e2e/framework/config
747+
k8s.io/kubernetes/test/e2e/framework/events
747748
k8s.io/kubernetes/test/e2e/framework/ginkgowrapper
748749
k8s.io/kubernetes/test/e2e/framework/kubectl
749750
k8s.io/kubernetes/test/e2e/framework/log

0 commit comments

Comments
 (0)