mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-04-11 18:13:00 +00:00
e2e: validate RBD snapshot under temporary clone image is present
Signed-off-by: Praveen M <m.praveen@ibm.com>
This commit is contained in:
parent
0ed0af120b
commit
2af7269551
14
e2e/rbd.go
14
e2e/rbd.go
@ -185,6 +185,20 @@ func createORDeleteRbdResources(action kubectlAction) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateRBDSnapshotCount(f *framework.Framework, count int, pool, image string) error {
|
||||||
|
snapshotList, err := listRBDSnapshots(f, pool, image)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to list RBD snapshots: %w", err)
|
||||||
|
}
|
||||||
|
if len(snapshotList) != count {
|
||||||
|
return fmt.Errorf("RBD snapshots count not matching, snapshot count for image %s/%s %d, expected %d"+
|
||||||
|
"snapshots in cluster: %v",
|
||||||
|
pool, image, len(snapshotList), count, snapshotList)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func validateRBDImageCount(f *framework.Framework, count int, pool string) {
|
func validateRBDImageCount(f *framework.Framework, count int, pool string) {
|
||||||
imageList, err := listRBDImages(f, pool)
|
imageList, err := listRBDImages(f, pool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -248,6 +248,17 @@ type imageInfoFromPVC struct {
|
|||||||
pvName string
|
pvName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type snapInfo struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
Protected string `json:"protected"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s snapInfo) String() string {
|
||||||
|
return fmt.Sprintf("{id: %d, name: %s, protected: %s}", s.ID, s.Name, s.Protected)
|
||||||
|
}
|
||||||
|
|
||||||
// getImageInfoFromPVC reads volume handle of the bound PV to the passed in PVC,
|
// getImageInfoFromPVC reads volume handle of the bound PV to the passed in PVC,
|
||||||
// and returns imageInfoFromPVC or error.
|
// and returns imageInfoFromPVC or error.
|
||||||
func getImageInfoFromPVC(pvcNamespace, pvcName string, f *framework.Framework) (imageInfoFromPVC, error) {
|
func getImageInfoFromPVC(pvcNamespace, pvcName string, f *framework.Framework) (imageInfoFromPVC, error) {
|
||||||
@ -715,6 +726,25 @@ func librbdSupportsVolumeGroupSnapshot(f *framework.Framework) (bool, error) {
|
|||||||
return strings.TrimSpace(stdout) == "0", nil
|
return strings.TrimSpace(stdout) == "0", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func listRBDSnapshots(f *framework.Framework, pool, image string) ([]snapInfo, error) {
|
||||||
|
var snapInfos []snapInfo
|
||||||
|
command := fmt.Sprintf("rbd snap ls --format=json %s %s", rbdOptions(pool), image)
|
||||||
|
stdout, stdErr, err := execCommandInToolBoxPod(f, command, rookNamespace)
|
||||||
|
if err != nil {
|
||||||
|
return snapInfos, err
|
||||||
|
}
|
||||||
|
if stdErr != "" {
|
||||||
|
return snapInfos, fmt.Errorf("failed to list RBD snapshots %v", stdErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(stdout), &snapInfos)
|
||||||
|
if err != nil {
|
||||||
|
return snapInfos, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return snapInfos, nil
|
||||||
|
}
|
||||||
|
|
||||||
func listRBDImages(f *framework.Framework, pool string) ([]string, error) {
|
func listRBDImages(f *framework.Framework, pool string) ([]string, error) {
|
||||||
var imgInfos []string
|
var imgInfos []string
|
||||||
|
|
||||||
|
10
e2e/utils.go
10
e2e/utils.go
@ -1003,6 +1003,16 @@ func validatePVCClone(
|
|||||||
if wgErrs[n] == nil && validatePVC != nil && kms != noKMS {
|
if wgErrs[n] == nil && validatePVC != nil && kms != noKMS {
|
||||||
wgErrs[n] = validatePVC(f, &p, &a)
|
wgErrs[n] = validatePVC(f, &p, &a)
|
||||||
}
|
}
|
||||||
|
if wgErrs[n] == nil {
|
||||||
|
// validate RBD snapshot under temporary clone is not deleted.
|
||||||
|
imageData, imageInfoerr := getImageInfoFromPVC(p.Namespace, name, f)
|
||||||
|
if imageInfoerr != nil {
|
||||||
|
wgErrs[n] = imageInfoerr
|
||||||
|
} else {
|
||||||
|
tempRBDImageName := imageData.imageName + "-temp"
|
||||||
|
wgErrs[n] = validateRBDSnapshotCount(f, 1, defaultRBDPool, tempRBDImageName)
|
||||||
|
}
|
||||||
|
}
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}(i, *pvcClone, *appClone)
|
}(i, *pvcClone, *appClone)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user