e2e: add test case for snapshot metadata validation

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
Prasanna Kumar Kalever 2022-03-02 15:10:32 +05:30 committed by mergify[bot]
parent d870cb152a
commit 4100ad2406

View File

@ -96,6 +96,11 @@ var (
pvcNameKey = "csi.storage.k8s.io/pvc/name" pvcNameKey = "csi.storage.k8s.io/pvc/name"
pvcNamespaceKey = "csi.storage.k8s.io/pvc/namespace" pvcNamespaceKey = "csi.storage.k8s.io/pvc/namespace"
pvNameKey = "csi.storage.k8s.io/pv/name" pvNameKey = "csi.storage.k8s.io/pv/name"
// snapshot metadata keys.
volSnapNameKey = "csi.storage.k8s.io/volumesnapshot/name"
volSnapNamespaceKey = "csi.storage.k8s.io/volumesnapshot/namespace"
volSnapContentNameKey = "csi.storage.k8s.io/volumesnapshotcontent/name"
) )
func deployRBDPlugin() { func deployRBDPlugin() {
@ -422,7 +427,7 @@ var _ = Describe("RBD", func() {
} }
pvcName, stdErr, err := execCommandInToolBoxPod(f, pvcName, stdErr, err := execCommandInToolBoxPod(f,
fmt.Sprintf("rbd image-meta get %s/%s %s", fmt.Sprintf("rbd image-meta get %s --image=%s %s",
rbdOptions(defaultRBDPool), imageList[0], pvcNameKey), rbdOptions(defaultRBDPool), imageList[0], pvcNameKey),
rookNamespace) rookNamespace)
if err != nil || stdErr != "" { if err != nil || stdErr != "" {
@ -435,7 +440,7 @@ var _ = Describe("RBD", func() {
} }
pvcNamespace, stdErr, err := execCommandInToolBoxPod(f, pvcNamespace, stdErr, err := execCommandInToolBoxPod(f,
fmt.Sprintf("rbd image-meta get %s/%s %s", fmt.Sprintf("rbd image-meta get %s --image=%s %s",
rbdOptions(defaultRBDPool), imageList[0], pvcNamespaceKey), rbdOptions(defaultRBDPool), imageList[0], pvcNamespaceKey),
rookNamespace) rookNamespace)
if err != nil || stdErr != "" { if err != nil || stdErr != "" {
@ -458,7 +463,7 @@ var _ = Describe("RBD", func() {
e2elog.Logf("pv name is empty %q in namespace %q: %v", pvc.Name, pvc.Namespace, err) e2elog.Logf("pv name is empty %q in namespace %q: %v", pvc.Name, pvc.Namespace, err)
} }
pvName, stdErr, err := execCommandInToolBoxPod(f, pvName, stdErr, err := execCommandInToolBoxPod(f,
fmt.Sprintf("rbd image-meta get %s/%s %s", fmt.Sprintf("rbd image-meta get %s --image=%s %s",
rbdOptions(defaultRBDPool), imageList[0], pvNameKey), rbdOptions(defaultRBDPool), imageList[0], pvNameKey),
rookNamespace) rookNamespace)
if err != nil || stdErr != "" { if err != nil || stdErr != "" {
@ -497,7 +502,7 @@ var _ = Describe("RBD", func() {
} }
pvcName, stdErr, err := execCommandInToolBoxPod(f, pvcName, stdErr, err := execCommandInToolBoxPod(f,
fmt.Sprintf("rbd image-meta get %s/%s %s", fmt.Sprintf("rbd image-meta get %s --image=%s %s",
rbdOptions(defaultRBDPool), imageList[0], pvcNameKey), rbdOptions(defaultRBDPool), imageList[0], pvcNameKey),
rookNamespace) rookNamespace)
if err != nil || stdErr != "" { if err != nil || stdErr != "" {
@ -543,8 +548,10 @@ var _ = Describe("RBD", func() {
// validate created backend rbd images // validate created backend rbd images
validateRBDImageCount(f, 1, defaultRBDPool) validateRBDImageCount(f, 1, defaultRBDPool)
pvc.Name = "rbd-pvc-new" pvcObj.Name = "rbd-pvc-new"
err = createPVCAndvalidatePV(f.ClientSet, pvc, deployTimeout) // unset the resource version as should not be set on objects to be created
pvcObj.ResourceVersion = ""
err = createPVCAndvalidatePV(f.ClientSet, pvcObj, deployTimeout)
if err != nil { if err != nil {
e2elog.Failf("failed to create new PVC: %v", err) e2elog.Failf("failed to create new PVC: %v", err)
} }
@ -553,7 +560,7 @@ var _ = Describe("RBD", func() {
validateRBDImageCount(f, 1, defaultRBDPool) validateRBDImageCount(f, 1, defaultRBDPool)
pvcName, stdErr, err = execCommandInToolBoxPod(f, pvcName, stdErr, err = execCommandInToolBoxPod(f,
fmt.Sprintf("rbd image-meta get %s/%s %s", fmt.Sprintf("rbd image-meta get %s --image=%s %s",
rbdOptions(defaultRBDPool), imageList[0], pvcNameKey), rbdOptions(defaultRBDPool), imageList[0], pvcNameKey),
rookNamespace) rookNamespace)
if err != nil || stdErr != "" { if err != nil || stdErr != "" {
@ -561,8 +568,8 @@ var _ = Describe("RBD", func() {
rbdOptions(defaultRBDPool), imageList[0], pvcNameKey, err, stdErr) rbdOptions(defaultRBDPool), imageList[0], pvcNameKey, err, stdErr)
} }
pvcName = strings.TrimSuffix(pvcName, "\n") pvcName = strings.TrimSuffix(pvcName, "\n")
if pvcName != pvc.Name { if pvcName != pvcObj.Name {
e2elog.Failf("expected pvcName %q got %q", pvc.Name, pvcName) e2elog.Failf("expected pvcName %q got %q", pvcObj.Name, pvcName)
} }
patchBytes = []byte(`{"spec":{"persistentVolumeReclaimPolicy": "Delete"}}`) patchBytes = []byte(`{"spec":{"persistentVolumeReclaimPolicy": "Delete"}}`)
@ -575,6 +582,103 @@ var _ = Describe("RBD", func() {
if err != nil { if err != nil {
e2elog.Logf("error Patching PV %q for persistentVolumeReclaimPolicy: %v", pvcObj.Spec.VolumeName, err) e2elog.Logf("error Patching PV %q for persistentVolumeReclaimPolicy: %v", pvcObj.Spec.VolumeName, err)
} }
err = deletePVCAndValidatePV(f.ClientSet, pvcObj, deployTimeout)
if err != nil {
e2elog.Failf("failed to delete pvc: %v", err)
}
validateRBDImageCount(f, 0, defaultRBDPool)
})
By("create a snapshot and check metadata on RBD snapshot image", func() {
err := createRBDSnapshotClass(f)
if err != nil {
e2elog.Failf("failed to create storageclass: %v", err)
}
defer func() {
err = deleteRBDSnapshotClass()
if err != nil {
e2elog.Failf("failed to delete VolumeSnapshotClass: %v", err)
}
}()
pvc, app, err := createPVCAndAppBinding(pvcPath, appPath, f, deployTimeout)
if err != nil {
e2elog.Failf("failed to create pvc and application binding: %v", err)
}
// validate created backend rbd images
validateRBDImageCount(f, 1, defaultRBDPool)
// delete pod as we should not create snapshot for in-use pvc
err = deletePod(app.Name, app.Namespace, f.ClientSet, deployTimeout)
if err != nil {
e2elog.Failf("failed to delete application: %v", err)
}
snap := getSnapshot(snapshotPath)
snap.Namespace = f.UniqueName
snap.Spec.Source.PersistentVolumeClaimName = &pvc.Name
err = createSnapshot(&snap, deployTimeout)
if err != nil {
e2elog.Failf("failed to create snapshot: %v", err)
}
// validate created backend rbd images
// parent PVC + snapshot
totalImages := 2
validateRBDImageCount(f, totalImages, defaultRBDPool)
imageList, err := listRBDImages(f, defaultRBDPool)
if err != nil {
e2elog.Failf("failed to list rbd images: %v", err)
}
volSnapName, stdErr, err := execCommandInToolBoxPod(f,
fmt.Sprintf("rbd image-meta get %s --image=%s %s",
rbdOptions(defaultRBDPool), imageList[0], volSnapNameKey),
rookNamespace)
if err != nil || stdErr != "" {
e2elog.Failf("failed to get volume snapshot name %s/%s %s: err=%v stdErr=%q",
rbdOptions(defaultRBDPool), imageList[0], volSnapNameKey, err, stdErr)
}
volSnapName = strings.TrimSuffix(volSnapName, "\n")
if volSnapName != snap.Name {
e2elog.Failf("expected volSnapName %q got %q", snap.Name, volSnapName)
}
volSnapNamespace, stdErr, err := execCommandInToolBoxPod(f,
fmt.Sprintf("rbd image-meta get %s --image=%s %s",
rbdOptions(defaultRBDPool), imageList[0], volSnapNamespaceKey),
rookNamespace)
if err != nil || stdErr != "" {
e2elog.Failf("failed to get volume snapshot namespace %s/%s %s: err=%v stdErr=%q",
rbdOptions(defaultRBDPool), imageList[0], volSnapNamespaceKey, err, stdErr)
}
volSnapNamespace = strings.TrimSuffix(volSnapNamespace, "\n")
if volSnapNamespace != snap.Namespace {
e2elog.Failf("expected volSnapNamespace %q got %q", snap.Namespace, volSnapNamespace)
}
content, err := getVolumeSnapshotContent(snap.Namespace, snap.Name)
if err != nil {
e2elog.Failf("failed to get snapshotcontent for %s in namespace %s: %v",
snap.Name, snap.Namespace, err)
}
volSnapContentName, stdErr, err := execCommandInToolBoxPod(f,
fmt.Sprintf("rbd image-meta get %s --image=%s %s",
rbdOptions(defaultRBDPool), imageList[0], volSnapContentNameKey),
rookNamespace)
if err != nil || stdErr != "" {
e2elog.Failf("failed to get snapshotcontent name %s/%s %s: err=%v stdErr=%q",
rbdOptions(defaultRBDPool), imageList[0], volSnapContentNameKey, err, stdErr)
}
volSnapContentName = strings.TrimSuffix(volSnapContentName, "\n")
if volSnapContentName != content.Name {
e2elog.Failf("expected volSnapContentName %q got %q", content.Name, volSnapContentName)
}
err = deleteSnapshot(&snap, deployTimeout)
if err != nil {
e2elog.Failf("failed to delete snapshot: %v", err)
}
err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout) err = deletePVCAndValidatePV(f.ClientSet, pvc, deployTimeout)
if err != nil { if err != nil {
e2elog.Failf("failed to delete pvc: %v", err) e2elog.Failf("failed to delete pvc: %v", err)