From 00ee8b1f1876adbcec67c082a08b06164b7682cc Mon Sep 17 00:00:00 2001 From: Oded Viner Date: Thu, 31 Oct 2024 16:14:02 +0200 Subject: [PATCH] rbd: added rbd info to validateRBDImageCount func Signed-off-by: Oded Viner --- e2e/rbd.go | 18 ++++++++++++++++-- e2e/rbd_helper.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/e2e/rbd.go b/e2e/rbd.go index a29c1f5c94d..7138ddafd0b 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -189,12 +189,26 @@ func validateRBDImageCount(f *framework.Framework, count int, pool string) { framework.Failf("failed to list rbd images: %v", err) } if len(imageList) != count { + var imageDetails []string // To collect details for all images + for _, image := range imageList { + imgInfo, err := getImageInfo(f, image, pool) + if err != nil { + return + } + imgStatus, err := getImageStatus(f, image, pool) + if err != nil { + return + } + // Collecting image details for printing + imageDetails = append(imageDetails, fmt.Sprintf("Pool Name: %s, Image Name: %s, Img Info: %v, Img Status: %v", pool, image, imgInfo, imgStatus)) + } framework.Failf( "backend images not matching kubernetes resource count,image count %d kubernetes resource count %d"+ - "\nbackend image Info:\n %v", + "\nbackend image Info:\n %v\n images information and status%v", len(imageList), count, - imageList) + imageList, + strings.Join(imageDetails, "\n")) } } diff --git a/e2e/rbd_helper.go b/e2e/rbd_helper.go index b35e38a432c..7f9b3562a4a 100644 --- a/e2e/rbd_helper.go +++ b/e2e/rbd_helper.go @@ -1069,6 +1069,16 @@ 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, error) { @@ -1094,6 +1104,31 @@ func getImageInfo(f *framework.Framework, imageName, poolName string) (imageInfo return imgInfo, 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, 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, fmt.Errorf("failed to get rbd status: %w", err) + } + if stdErr != "" { + return imgStatus, fmt.Errorf("failed to get rbd status: %v", stdErr) + } + err = json.Unmarshal([]byte(stdOut), &imgStatus) + if err != nil { + return imgStatus, fmt.Errorf("unmarshal failed: %w. raw buffer response: %s", + err, stdOut) + } + + return imgStatus, nil +} + // validateStripe validate the stripe count, stripe unit and object size of the // image. func validateStripe(f *framework.Framework,