From 0c6954531467b87522f39ac14bdd450b8837ecee Mon Sep 17 00:00:00 2001 From: Oded Viner Date: Mon, 11 Nov 2024 10:43:53 +0200 Subject: [PATCH] add attrubute to imageInfo struct Signed-off-by: Oded Viner --- e2e/rbd.go | 6 +++--- e2e/rbd_helper.go | 49 ++++++++++++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/e2e/rbd.go b/e2e/rbd.go index 94d3da1a2ba..5141f2f8ac9 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) + imgInfo, 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: %v, Status: %s", pool, image, imgInfo, imgStatusOutput)) } framework.Failf( "backend images not matching kubernetes resource count,image count %d kubernetes resource count %d"+ diff --git a/e2e/rbd_helper.go b/e2e/rbd_helper.go index 7c8b777c28a..f21bd76890b 100644 --- a/e2e/rbd_helper.go +++ b/e2e/rbd_helper.go @@ -1063,10 +1063,23 @@ func waitToRemoveImagesFromTrash(f *framework.Framework, poolName string, t int) // imageInfo strongly typed JSON spec for image info. type imageInfo struct { - Name string `json:"name"` - StripeUnit int `json:"stripe_unit"` - StripeCount int `json:"stripe_count"` - ObjectSize int `json:"object_size"` + Name string `json:"name"` + ID string `json:"id"` + Size int64 `json:"size"` + Objects int `json:"objects"` + Order int `json:"order"` + ObjectSize int `json:"object_size"` + SnapshotCount int `json:"snapshot_count"` + BlockNamePrefix string `json:"block_name_prefix"` + Format int `json:"format"` + Features []string `json:"features"` + OpFeatures []string `json:"op_features"` + Flags []string `json:"flags"` + CreateTimestamp string `json:"create_timestamp"` + AccessTimestamp string `json:"access_timestamp"` + ModifyTimestamp string `json:"modify_timestamp"` + StripeUnit int `json:"stripe_unit"` + StripeCount int `json:"stripe_count"` } // imageStatus strongly typed JSON spec for image status. @@ -1081,7 +1094,7 @@ type imageStatus struct { // 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) (imageInfo, error) { // rbd --format=json info [image-spec | snap-spec] var imgInfo imageInfo @@ -1090,43 +1103,35 @@ func getImageInfo(f *framework.Framework, imageName, poolName string) (imageInfo 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 imgInfo, fmt.Errorf("failed to get rbd info: %w", err) } if stdErr != "" { - return imgInfo, stdOut, fmt.Errorf("failed to get rbd info: %v", stdErr) + return imgInfo, 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", + return imgInfo, fmt.Errorf("unmarshal failed: %w. raw buffer response: %s", err, stdOut) } - return imgInfo, stdOut, nil + 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, 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) - } - err = json.Unmarshal([]byte(stdOut), &imgStatus) - if err != nil { - return imgStatus, stdOut, fmt.Errorf("unmarshal failed: %w. raw buffer response: %s", - err, stdOut) + return stdOut, fmt.Errorf("failed to get rbd info: %v", stdErr) } - - return imgStatus, stdOut, nil + return stdOut, nil } // validateStripe validate the stripe count, stripe unit and object size of the @@ -1142,7 +1147,7 @@ func validateStripe(f *framework.Framework, return err } - imgInfo, _, err := getImageInfo(f, imageData.imageName, defaultRBDPool) + imgInfo, err := getImageInfo(f, imageData.imageName, defaultRBDPool) if err != nil { return err }