Commit 1b06ba50 authored by Masaki Kimura's avatar Masaki Kimura

Add e2e tests for volumeMode of persistent volume

This set of e2e tests is to confirm that persistent volume works well for all volumeModes. Coverage of the tests are shown in the figure of [Test cases], below. Once implementation policy is confirmed to be good, we can add plugins and test cases to this. [Test cases] # plugin volumeMode Test case Expectation --- ---------- -------------- ------------------------------------------------------ ------------ 1 iSCSI Block (a) Create Pod with PV and confirm Read/Write to PV Success 2 iSCSI FileSystem (a) Create Pod with PV and confirm Read/Write to PV Success 3 RBD Block (a) Create Pod with PV and confirm Read/Write to PV Success 4 RBD FileSystem (a) Create Pod with PV and confirm Read/Write to PV Success 5 CephFS Block (a) Create Pod with PV and confirm Read/Write to PV Fail 6 CephFS FileSystem (a) Create Pod with PV and confirm Read/Write to PV Success 7 NFS Block (a) Create Pod with PV and confirm Read/Write to PV Fail 8 NFS FileSystem (a) Create Pod with PV and confirm Read/Write to PV Success fixes: #56803
parent 24ab69d3
...@@ -48,6 +48,12 @@ const ( ...@@ -48,6 +48,12 @@ const (
VolumeSelectorKey = "e2e-pv-pool" VolumeSelectorKey = "e2e-pv-pool"
) )
var (
// Common selinux labels
SELinuxLabel = &v1.SELinuxOptions{
Level: "s0:c0,c1"}
)
// Map of all PVs used in the multi pv-pvc tests. The key is the PV's name, which is // Map of all PVs used in the multi pv-pvc tests. The key is the PV's name, which is
// guaranteed to be unique. The value is {} (empty struct) since we're only interested // guaranteed to be unique. The value is {} (empty struct) since we're only interested
// in the PV's name and if it is present. We must always Get the pv object before // in the PV's name and if it is present. We must always Get the pv object before
......
...@@ -15,6 +15,7 @@ go_library( ...@@ -15,6 +15,7 @@ go_library(
"persistent_volumes.go", "persistent_volumes.go",
"persistent_volumes-gce.go", "persistent_volumes-gce.go",
"persistent_volumes-local.go", "persistent_volumes-local.go",
"persistent_volumes-volumemode.go",
"pv_protection.go", "pv_protection.go",
"pvc_protection.go", "pvc_protection.go",
"regional_pd.go", "regional_pd.go",
......
...@@ -19,6 +19,7 @@ go_library( ...@@ -19,6 +19,7 @@ go_library(
"//test/e2e/framework:go_default_library", "//test/e2e/framework:go_default_library",
"//vendor/github.com/onsi/ginkgo:go_default_library", "//vendor/github.com/onsi/ginkgo:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library", "//vendor/github.com/onsi/gomega:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library",
], ],
) )
......
...@@ -27,6 +27,7 @@ import ( ...@@ -27,6 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
uexec "k8s.io/utils/exec"
) )
type KubeletOpt string type KubeletOpt string
...@@ -43,6 +44,41 @@ func PodExec(pod *v1.Pod, bashExec string) (string, error) { ...@@ -43,6 +44,41 @@ func PodExec(pod *v1.Pod, bashExec string) (string, error) {
return framework.RunKubectl("exec", fmt.Sprintf("--namespace=%s", pod.Namespace), pod.Name, "--", "/bin/sh", "-c", bashExec) return framework.RunKubectl("exec", fmt.Sprintf("--namespace=%s", pod.Namespace), pod.Name, "--", "/bin/sh", "-c", bashExec)
} }
// VerifyExecInPodSucceed verifies bash cmd in target pod succeed
func VerifyExecInPodSucceed(pod *v1.Pod, bashExec string) {
_, err := PodExec(pod, bashExec)
if err != nil {
if err, ok := err.(uexec.CodeExitError); ok {
exitCode := err.ExitStatus()
Expect(err).NotTo(HaveOccurred(),
"%q should succeed, but failed with exit code %d and error message %q",
bashExec, exitCode, err)
} else {
Expect(err).NotTo(HaveOccurred(),
"%q should succeed, but failed with error message %q",
bashExec, err)
}
}
}
// VerifyExecInPodFail verifies bash cmd in target pod fail with certain exit code
func VerifyExecInPodFail(pod *v1.Pod, bashExec string, exitCode int) {
_, err := PodExec(pod, bashExec)
if err != nil {
if err, ok := err.(uexec.CodeExitError); ok {
actualExitCode := err.ExitStatus()
Expect(actualExitCode).To(Equal(exitCode),
"%q should fail with exit code %d, but failed with exit code %d and error message %q",
bashExec, exitCode, actualExitCode, err)
} else {
Expect(err).NotTo(HaveOccurred(),
"%q should fail with exit code %d, but failed with error message %q",
bashExec, exitCode, err)
}
}
Expect(err).To(HaveOccurred(), "%q should fail with exit code %d, but exit without error", bashExec, exitCode)
}
// KubeletCommand performs `start`, `restart`, or `stop` on the kubelet running on the node of the target pod and waits // KubeletCommand performs `start`, `restart`, or `stop` on the kubelet running on the node of the target pod and waits
// for the desired statues.. // for the desired statues..
// - First issues the command via `systemctl` // - First issues the command via `systemctl`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment