e2e: add various testcases to validate unset of metadata

Validate that we:
* Unset the PVC metadata on the rbd image created for the snapshot
* snapshot metadata on CreateVolume from snapshot

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
Prasanna Kumar Kalever 2022-05-04 21:24:15 +05:30 committed by mergify[bot]
parent 27f503c144
commit 89a7ada12f
2 changed files with 83 additions and 6 deletions

View File

@ -196,6 +196,21 @@ func validateRBDImageCount(f *framework.Framework, count int, pool string) {
}
}
func formatImageMetaGetCmd(pool, image, key string) string {
return fmt.Sprintf("rbd image-meta get %s --image=%s %s", rbdOptions(pool), image, key)
}
// checkGetKeyError check for error conditions returned by get image-meta key,
// returns true if key exists.
func checkGetKeyError(err error, stdErr string) bool {
if err == nil || !strings.Contains(err.Error(), "command terminated with exit code 2") ||
!strings.Contains(stdErr, "failed to get metadata") {
return true
}
return false
}
var _ = Describe("RBD", func() {
f := framework.NewDefaultFramework("rbd")
var c clientset.Interface
@ -395,8 +410,7 @@ var _ = Describe("RBD", func() {
}
pvcName, stdErr, err := execCommandInToolBoxPod(f,
fmt.Sprintf("rbd image-meta get %s --image=%s %s",
rbdOptions(defaultRBDPool), imageList[0], pvcNameKey),
formatImageMetaGetCmd(defaultRBDPool, imageList[0], pvcNameKey),
rookNamespace)
if err != nil || stdErr != "" {
e2elog.Failf("failed to get PVC name %s/%s %s: err=%v stdErr=%q",
@ -408,8 +422,7 @@ var _ = Describe("RBD", func() {
}
pvcNamespace, stdErr, err := execCommandInToolBoxPod(f,
fmt.Sprintf("rbd image-meta get %s --image=%s %s",
rbdOptions(defaultRBDPool), imageList[0], pvcNamespaceKey),
formatImageMetaGetCmd(defaultRBDPool, imageList[0], pvcNamespaceKey),
rookNamespace)
if err != nil || stdErr != "" {
e2elog.Failf("failed to get PVC namespace %s/%s %s: err=%v stdErr=%q",
@ -427,8 +440,7 @@ var _ = Describe("RBD", func() {
e2elog.Logf("pv name is empty %q in namespace %q: %v", pvc.Name, pvc.Namespace, err)
}
pvName, stdErr, err := execCommandInToolBoxPod(f,
fmt.Sprintf("rbd image-meta get %s --image=%s %s",
rbdOptions(defaultRBDPool), imageList[0], pvNameKey),
formatImageMetaGetCmd(defaultRBDPool, imageList[0], pvNameKey),
rookNamespace)
if err != nil || stdErr != "" {
e2elog.Failf("failed to get PV name %s/%s %s: err=%v stdErr=%q",
@ -653,6 +665,33 @@ var _ = Describe("RBD", func() {
e2elog.Failf("expected volSnapContentName %q got %q", content.Name, volSnapContentName)
}
// make sure we had unset the PVC metadata on the rbd image created
// for the snapshot
pvcName, stdErr, err := execCommandInToolBoxPod(f,
fmt.Sprintf("rbd image-meta get %s --image=%s %s",
rbdOptions(defaultRBDPool), imageList[0], pvcNameKey),
rookNamespace)
if checkGetKeyError(err, stdErr) {
e2elog.Failf("PVC name found on %s/%s %s=%s: err=%v stdErr=%q",
rbdOptions(defaultRBDPool), imageList[0], pvcNameKey, pvcName, err, stdErr)
}
pvcNamespace, stdErr, err := execCommandInToolBoxPod(f,
fmt.Sprintf("rbd image-meta get %s --image=%s %s",
rbdOptions(defaultRBDPool), imageList[0], pvcNamespaceKey),
rookNamespace)
if checkGetKeyError(err, stdErr) {
e2elog.Failf("PVC namespace found on %s/%s %s=%s: err=%v stdErr=%q",
rbdOptions(defaultRBDPool), imageList[0], pvcNamespaceKey, pvcNamespace, err, stdErr)
}
pvName, stdErr, err := execCommandInToolBoxPod(f,
fmt.Sprintf("rbd image-meta get %s --image=%s %s",
rbdOptions(defaultRBDPool), imageList[0], pvNameKey),
rookNamespace)
if checkGetKeyError(err, stdErr) {
e2elog.Failf("PV name found on %s/%s %s=%s: err=%v stdErr=%q",
rbdOptions(defaultRBDPool), imageList[0], pvNameKey, pvName, err, stdErr)
}
err = deleteSnapshot(&snap, deployTimeout)
if err != nil {
e2elog.Failf("failed to delete snapshot: %v", err)

View File

@ -229,6 +229,7 @@ func getVolumeSnapshotContent(namespace, snapshotName string) (*snapapi.VolumeSn
return volumeSnapshotContent, nil
}
// nolint:gocyclo,cyclop // reduce complexity
func validateBiggerPVCFromSnapshot(f *framework.Framework,
pvcPath,
appPath,
@ -305,6 +306,43 @@ func validateBiggerPVCFromSnapshot(f *framework.Framework,
if err != nil {
return fmt.Errorf("failed to validate device size: %w", err)
}
// make sure we had unset snapshot metadata on CreateVolume
// from snapshot
var (
volSnapName string
volSnapNamespace string
volSnapContentName string
stdErr string
imageList []string
)
imageList, err = listRBDImages(f, defaultRBDPool)
if err != nil {
e2elog.Failf("failed to list rbd images: %v", err)
}
e2elog.Logf("list of rbd images: %v", imageList)
volSnapName, stdErr, err = execCommandInToolBoxPod(f,
formatImageMetaGetCmd(defaultRBDPool, imageList[0], volSnapNameKey),
rookNamespace)
if checkGetKeyError(err, stdErr) {
e2elog.Failf("found volume snapshot name %s/%s %s=%s: err=%v stdErr=%q",
rbdOptions(defaultRBDPool), imageList[0], volSnapNameKey, volSnapName, err, stdErr)
}
volSnapNamespace, stdErr, err = execCommandInToolBoxPod(f,
formatImageMetaGetCmd(defaultRBDPool, imageList[0], volSnapNamespaceKey),
rookNamespace)
if checkGetKeyError(err, stdErr) {
e2elog.Failf("found volume snapshot namespace %s/%s %s=%s: err=%v stdErr=%q",
rbdOptions(defaultRBDPool), imageList[0], volSnapNamespaceKey, volSnapNamespace, err, stdErr)
}
volSnapContentName, stdErr, err = execCommandInToolBoxPod(f,
formatImageMetaGetCmd(defaultRBDPool, imageList[0], volSnapContentNameKey),
rookNamespace)
if checkGetKeyError(err, stdErr) {
e2elog.Failf("found snapshotcontent name %s/%s %s=%s: err=%v stdErr=%q",
rbdOptions(defaultRBDPool), imageList[0], volSnapContentNameKey,
volSnapContentName, err, stdErr)
}
}
err = deletePVCAndApp("", f, pvcClone, appClone)
if err != nil {