diff --git a/e2e/rbd.go b/e2e/rbd.go index 94d3da1a2ba..99822a558fe 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -191,17 +191,17 @@ func validateRBDImageCount(f *framework.Framework, count int, pool string) { if len(imageList) != count { var imageDetails []string // To collect details for all images for _, image := range imageList { - _, imgInfoOutput, err := getImageInfo(f, image, pool) + imgInfoStr, err := getImageInfo(f, image, pool) if err != nil { framework.Logf("Error getting image info: %v", err) } - _, imgStatusOutput, err := getImageStatus(f, image, pool) + imgStatusOutput, err := getImageStatus(f, image, pool) if err != nil { framework.Logf("Error getting image status: %v", err) } // Collecting image details for printing imageDetails = append(imageDetails, fmt.Sprintf( - "Pool: %s, Image: %s, Info: %s, Status: %s", pool, image, imgInfoOutput, imgStatusOutput)) + "Pool: %s, Image: %s, Info: %s, Status: %s", pool, image, imgInfoStr, imgStatusOutput)) } framework.Failf( "backend images not matching kubernetes resource count,image count %d kubernetes resource count %d"+ @@ -490,7 +490,7 @@ var _ = Describe("RBD", func() { framework.Failf("failed to create PVC: %v", err) } // validate created backend rbd images - validateRBDImageCount(f, 11, defaultRBDPool) + validateRBDImageCount(f, 1, defaultRBDPool) validateOmapCount(f, 1, rbdType, defaultRBDPool, volumesType) imageList, err := listRBDImages(f, defaultRBDPool) diff --git a/e2e/rbd_helper.go b/e2e/rbd_helper.go index 7c8b777c28a..0e5c8b312e1 100644 --- a/e2e/rbd_helper.go +++ b/e2e/rbd_helper.go @@ -1069,64 +1069,39 @@ type imageInfo struct { ObjectSize int `json:"object_size"` } -// imageStatus strongly typed JSON spec for image status. -type imageStatus struct { - Name string `json:"name"` - Pool string `json:"pool"` - Watchers int `json:"watchers"` - InUse bool `json:"in_use"` // Indicates if the image is currently in use. - Size int64 `json:"size"` // Total size of the image in bytes. - Format string `json:"format"` // Format of the image (e.g., raw, qcow2). -} - // getImageInfo queries rbd about the given image and returns its metadata, and returns // error if provided image is not found. -func getImageInfo(f *framework.Framework, imageName, poolName string) (imageInfo, string, error) { +func getImageInfo(f *framework.Framework, imageName, poolName string) (string, error) { // rbd --format=json info [image-spec | snap-spec] - var imgInfo imageInfo - stdOut, stdErr, err := execCommandInToolBoxPod( f, fmt.Sprintf("rbd info %s %s --format json", rbdOptions(poolName), imageName), rookNamespace) if err != nil { - return imgInfo, stdOut, fmt.Errorf("failed to get rbd info: %w", err) + return stdOut, fmt.Errorf("failed to get rbd info: %w", err) } if stdErr != "" { - return imgInfo, stdOut, fmt.Errorf("failed to get rbd info: %v", stdErr) - } - err = json.Unmarshal([]byte(stdOut), &imgInfo) - if err != nil { - return imgInfo, stdOut, fmt.Errorf("unmarshal failed: %w. raw buffer response: %s", - err, stdOut) + return stdOut, fmt.Errorf("failed to get rbd info: %v", stdErr) } - return imgInfo, stdOut, nil + return stdOut, nil } // getImageStatus queries rbd about the given image and returns its metadata, and returns // error if provided image is not found. -func getImageStatus(f *framework.Framework, imageName, poolName string) (imageStatus, string, error) { +func getImageStatus(f *framework.Framework, imageName, poolName string) (string, error) { // rbd --format=json status [image-spec | snap-spec] - var imgStatus imageStatus - stdOut, stdErr, err := execCommandInToolBoxPod( f, fmt.Sprintf("rbd status %s %s --format json", rbdOptions(poolName), imageName), rookNamespace) if err != nil { - return imgStatus, stdOut, fmt.Errorf("error retrieving rbd status: %w", err) + return stdOut, fmt.Errorf("error retrieving rbd status: %w", err) } if stdErr != "" { - return imgStatus, stdOut, fmt.Errorf("failed to get rbd status: %v", stdErr) + return stdOut, fmt.Errorf("failed to get rbd info: %v", stdErr) } - err = json.Unmarshal([]byte(stdOut), &imgStatus) - if err != nil { - return imgStatus, stdOut, fmt.Errorf("unmarshal failed: %w. raw buffer response: %s", - err, stdOut) - } - - return imgStatus, stdOut, nil + return stdOut, nil } // validateStripe validate the stripe count, stripe unit and object size of the @@ -1137,15 +1112,22 @@ func validateStripe(f *framework.Framework, stripeCount, objectSize int, ) error { + var imgInfo imageInfo + imageData, err := getImageInfoFromPVC(pvc.Namespace, pvc.Name, f) if err != nil { return err } - - imgInfo, _, err := getImageInfo(f, imageData.imageName, defaultRBDPool) + + imgInfoStr, err := getImageInfo(f, imageData.imageName, defaultRBDPool) if err != nil { return err } + + err = json.Unmarshal([]byte(imgInfoStr), &imgInfo) + if err != nil { + return fmt.Errorf("unmarshal failed: %w. raw buffer response: %s", err, imgInfoStr) + } if imgInfo.ObjectSize != objectSize { return fmt.Errorf("objectSize %d does not match expected %d", imgInfo.ObjectSize, objectSize)