Skip to content

Commit

Permalink
rbd: added rbd info to validateRBDImageCount func
Browse files Browse the repository at this point in the history
Signed-off-by: Oded Viner <[email protected]>
  • Loading branch information
OdedViner committed Nov 6, 2024
1 parent a7959d4 commit e19572a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 9 deletions.
21 changes: 18 additions & 3 deletions e2e/rbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,27 @@ 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 {
_, imgInfoOutput, err := getImageInfo(f, image, pool)
if err != nil {
framework.Logf("Error getting image info: %v", err)
}
_, 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))
}
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"))
}
}

Expand Down Expand Up @@ -475,7 +490,7 @@ var _ = Describe("RBD", func() {
framework.Failf("failed to create PVC: %v", err)
}
// validate created backend rbd images
validateRBDImageCount(f, 1, defaultRBDPool)
validateRBDImageCount(f, 11, defaultRBDPool)
validateOmapCount(f, 1, rbdType, defaultRBDPool, volumesType)

imageList, err := listRBDImages(f, defaultRBDPool)
Expand Down
47 changes: 41 additions & 6 deletions e2e/rbd_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1069,9 +1069,19 @@ 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) {
func getImageInfo(f *framework.Framework, imageName, poolName string) (imageInfo, string, error) {
// rbd --format=json info [image-spec | snap-spec]
var imgInfo imageInfo

Expand All @@ -1080,18 +1090,43 @@ 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, fmt.Errorf("failed to get rbd info: %w", err)
return imgInfo, stdOut, fmt.Errorf("failed to get rbd info: %w", err)
}
if stdErr != "" {
return imgInfo, fmt.Errorf("failed to get rbd info: %v", stdErr)
return imgInfo, stdOut, fmt.Errorf("failed to get rbd info: %v", stdErr)
}
err = json.Unmarshal([]byte(stdOut), &imgInfo)
if err != nil {
return imgInfo, fmt.Errorf("unmarshal failed: %w. raw buffer response: %s",
return imgInfo, stdOut, fmt.Errorf("unmarshal failed: %w. raw buffer response: %s",
err, stdOut)
}

return imgInfo, 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) {
// 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)
}
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 imgInfo, nil
return imgStatus, stdOut, nil
}

// validateStripe validate the stripe count, stripe unit and object size of the
Expand All @@ -1107,7 +1142,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
}
Expand Down

0 comments on commit e19572a

Please sign in to comment.