e2e: add e2e for static PVC without imageFeature parameter

This commit adds e2e to make sure static PVC without imageFeatures
parameter fail with proper error event.

Signed-off-by: Rakshith R <rar@redhat.com>
This commit is contained in:
Rakshith R 2021-06-15 15:38:51 +05:30 committed by mergify[bot]
parent 7fc553a3a7
commit 82a204bfd3
8 changed files with 48 additions and 11 deletions

View File

@ -34,7 +34,7 @@ func deployVault(c kubernetes.Interface, deployTimeout int) {
Expect(err).Should(BeNil())
Expect(len(pods.Items)).Should(Equal(1))
name := pods.Items[0].Name
err = waitForPodInRunningState(name, cephCSINamespace, c, deployTimeout)
err = waitForPodInRunningState(name, cephCSINamespace, c, deployTimeout, noError)
Expect(err).Should(BeNil())
}

View File

@ -259,10 +259,18 @@ func createApp(c kubernetes.Interface, app *v1.Pod, timeout int) error {
if err != nil {
return fmt.Errorf("failed to create app: %w", err)
}
return waitForPodInRunningState(app.Name, app.Namespace, c, timeout)
return waitForPodInRunningState(app.Name, app.Namespace, c, timeout, noError)
}
func waitForPodInRunningState(name, ns string, c kubernetes.Interface, t int) error {
func createAppErr(c kubernetes.Interface, app *v1.Pod, timeout int, errString string) error {
_, err := c.CoreV1().Pods(app.Namespace).Create(context.TODO(), app, metav1.CreateOptions{})
if err != nil {
return err
}
return waitForPodInRunningState(app.Name, app.Namespace, c, timeout, errString)
}
func waitForPodInRunningState(name, ns string, c kubernetes.Interface, t int, expectedError string) error {
timeout := time.Duration(t) * time.Minute
start := time.Now()
e2elog.Logf("Waiting up to %v to be in Running state", name)
@ -276,6 +284,19 @@ func waitForPodInRunningState(name, ns string, c kubernetes.Interface, t int) er
return true, nil
case v1.PodFailed, v1.PodSucceeded:
return false, conditions.ErrPodCompleted
case v1.PodPending:
if expectedError != "" {
events, err := c.CoreV1().Events(ns).List(context.TODO(), metav1.ListOptions{
FieldSelector: fmt.Sprintf("involvedObject.name=%s", name),
})
if err != nil {
return false, err
}
if strings.Contains(events.String(), expectedError) {
e2elog.Logf("Expected Error %q found successfully", expectedError)
return true, err
}
}
}
e2elog.Logf("%s app is in %s phase expected to be in Running state (%d seconds elapsed)", name, pod.Status.Phase, int(time.Since(start).Seconds()))
return false, nil

View File

@ -1051,7 +1051,7 @@ var _ = Describe("RBD", func() {
})
By("validate RBD static FileSystem PVC", func() {
err := validateRBDStaticPV(f, appPath, false)
err := validateRBDStaticPV(f, appPath, false, false)
if err != nil {
e2elog.Failf("failed to validate rbd static pv with error %v", err)
}
@ -1060,7 +1060,7 @@ var _ = Describe("RBD", func() {
})
By("validate RBD static Block PVC", func() {
err := validateRBDStaticPV(f, rawAppPath, true)
err := validateRBDStaticPV(f, rawAppPath, true, false)
if err != nil {
e2elog.Failf("failed to validate rbd block pv with error %v", err)
}
@ -1068,6 +1068,15 @@ var _ = Describe("RBD", func() {
validateRBDImageCount(f, 0, defaultRBDPool)
})
By("validate failure of RBD static PVC without imageFeatures parameter", func() {
err := validateRBDStaticPV(f, rawAppPath, true, true)
if err != nil {
e2elog.Failf("Validation of static PVC without imageFeatures parameter failed with err %v", err)
}
// validate created backend rbd images
validateRBDImageCount(f, 0, defaultRBDPool)
})
By("validate mount options in app pod", func() {
mountFlags := []string{"discard"}
err := checkMountOptions(pvcPath, appPath, f, mountFlags)

View File

@ -113,7 +113,7 @@ func resizePVCAndValidateSize(pvcPath, appPath string, f *framework.Framework) e
return err
}
// wait for application pod to come up after resize
err = waitForPodInRunningState(app.Name, app.Namespace, f.ClientSet, deployTimeout)
err = waitForPodInRunningState(app.Name, app.Namespace, f.ClientSet, deployTimeout, noError)
if err != nil {
return err
}

View File

@ -77,7 +77,7 @@ func getStaticPVC(name, pvName, size, ns, sc string, blockPVC bool) *v1.Persiste
return pvc
}
func validateRBDStaticPV(f *framework.Framework, appPath string, isBlock bool) error {
func validateRBDStaticPV(f *framework.Framework, appPath string, isBlock, checkImgFeat bool) error {
opt := make(map[string]string)
var (
rbdImageName = "test-static-pv"
@ -112,7 +112,9 @@ func validateRBDStaticPV(f *framework.Framework, appPath string, isBlock bool) e
return fmt.Errorf("failed to create rbd image %s", e)
}
opt["clusterID"] = fsID
if !checkImgFeat {
opt["imageFeatures"] = "layering"
}
opt["pool"] = defaultRBDPool
opt["staticVolume"] = "true"
if radosNamespace != "" {
@ -140,7 +142,11 @@ func validateRBDStaticPV(f *framework.Framework, appPath string, isBlock bool) e
app.Namespace = namespace
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvcName
if checkImgFeat {
err = createAppErr(f.ClientSet, app, deployTimeout, "missing required parameter imageFeatures")
} else {
err = createApp(f.ClientSet, app, deployTimeout)
}
if err != nil {
return err
}

View File

@ -384,7 +384,7 @@ var _ = Describe("CephFS Upgrade Testing", func() {
e2elog.Failf("failed to expand pvc with error %v", err)
}
// wait for application pod to come up after resize
err = waitForPodInRunningState(app.Name, app.Namespace, f.ClientSet, deployTimeout)
err = waitForPodInRunningState(app.Name, app.Namespace, f.ClientSet, deployTimeout, noError)
if err != nil {
e2elog.Failf("timeout waiting for pod to be in running state with error %v", err)
}

View File

@ -391,7 +391,7 @@ var _ = Describe("RBD Upgrade Testing", func() {
e2elog.Failf("failed to expand pvc with error %v", err)
}
// wait for application pod to come up after resize
err = waitForPodInRunningState(app.Name, app.Namespace, f.ClientSet, deployTimeout)
err = waitForPodInRunningState(app.Name, app.Namespace, f.ClientSet, deployTimeout, noError)
if err != nil {
e2elog.Failf("timeout waiting for pod to be in running state with error %v", err)
}

View File

@ -46,6 +46,7 @@ const (
// vaultTokens KMS type
vaultTokens = "vaulttokens"
noError = ""
)
var (