From 7db0c3bfbf349c258a478ee9fb3f51d70a9b4d81 Mon Sep 17 00:00:00 2001 From: Marcel Lauhoff Date: Thu, 4 Aug 2022 18:12:33 +0200 Subject: [PATCH] e2e: Add PVC validator to ByFileAndBlockEncryption Signed-off-by: Marcel Lauhoff --- e2e/rbd.go | 6 +++--- e2e/rbd_helper.go | 14 ++++++++++++-- e2e/utils.go | 3 ++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/e2e/rbd.go b/e2e/rbd.go index 24559c419..032fb7e75 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -235,10 +235,10 @@ func checkClusternameInMetadata(f *framework.Framework, ns, pool, image string) // ByFileAndBlockEncryption wraps ginkgo's By to run the test body using file and block encryption specific validators. func ByFileAndBlockEncryption( text string, - callback func(validator encryptionValidateFunc, encryptionType string), + callback func(validator encryptionValidateFunc, pvcValidator validateFunc, encryptionType string), ) { - By(text+" (block)", func() { callback(validateEncryptedPVCAndAppBinding, "block") }) - By(text+" (file)", func() { callback(validateEncryptedFilesystemAndAppBinding, "file") }) + By(text+" (block)", func() { callback(validateEncryptedPVCAndAppBinding, isBlockEncryptedPVC, "block") }) + By(text+" (file)", func() { callback(validateEncryptedFilesystemAndAppBinding, isFileEncryptedPVC, "file") }) } var _ = Describe("RBD", func() { diff --git a/e2e/rbd_helper.go b/e2e/rbd_helper.go index ec2e0f479..c189737e7 100644 --- a/e2e/rbd_helper.go +++ b/e2e/rbd_helper.go @@ -588,14 +588,24 @@ type validateFunc func(f *framework.Framework, pvc *v1.PersistentVolumeClaim, ap // validation of the PVC is needed. var noPVCValidation validateFunc -func isEncryptedPVC(f *framework.Framework, pvc *v1.PersistentVolumeClaim, app *v1.Pod) error { +type imageValidateFunc func(f *framework.Framework, rbdImageSpec, pvName, appName string) error + +func isEncryptedPVC(f *framework.Framework, pvc *v1.PersistentVolumeClaim, app *v1.Pod, validateFunc imageValidateFunc) error { imageData, err := getImageInfoFromPVC(pvc.Namespace, pvc.Name, f) if err != nil { return err } rbdImageSpec := imageSpec(defaultRBDPool, imageData.imageName) - return validateEncryptedImage(f, rbdImageSpec, imageData.pvName, app.Name) + return validateFunc(f, rbdImageSpec, imageData.pvName, app.Name) +} + +func isBlockEncryptedPVC(f *framework.Framework, pvc *v1.PersistentVolumeClaim, app *v1.Pod) error { + return isEncryptedPVC(f, pvc, app, validateEncryptedImage) +} + +func isFileEncryptedPVC(f *framework.Framework, pvc *v1.PersistentVolumeClaim, app *v1.Pod) error { + return isEncryptedPVC(f, pvc, app, validateEncryptedFilesystem) } // validateEncryptedImage verifies that the RBD image is encrypted. The diff --git a/e2e/utils.go b/e2e/utils.go index 58ed04efa..f844bfae6 100644 --- a/e2e/utils.go +++ b/e2e/utils.go @@ -1025,6 +1025,7 @@ func validatePVCSnapshot( pvcPath, appPath, snapshotPath, pvcClonePath, appClonePath string, kms, restoreKMS kmsConfig, restoreSCName, dataPool string, f *framework.Framework, + isEncryptedPVC validateFunc, ) { var wg sync.WaitGroup wgErrs := make([]error, totalCount) @@ -1448,7 +1449,7 @@ func validateController( } if scParams["encrypted"] == strconv.FormatBool(true) { // check encryption - err = isEncryptedPVC(f, resizePvc, app) + err = isBlockEncryptedPVC(f, resizePvc, app) if err != nil { return err }