From 66d6ac40eae1c029f3734f9f12dc5d640b3a8877 Mon Sep 17 00:00:00 2001 From: Alex Kalenyuk Date: Sun, 21 Apr 2024 17:00:26 +0300 Subject: [PATCH] Correct wrong check of resulting image sparsiness The first issue is that we look at content size since 2168, which is not beneficial in the sparseness check as opposed to disk usage. The second issue is that the check we have in tests for sparsiness is not honest because of the "equal to" part. The virtual size has to be strictly greater than the content (as the content is displayed by tools that understand sparseness). Signed-off-by: Alex Kalenyuk --- tests/framework/pvc.go | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/tests/framework/pvc.go b/tests/framework/pvc.go index 7c108c0fad..d08f8f00b3 100644 --- a/tests/framework/pvc.go +++ b/tests/framework/pvc.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "strconv" "strings" "time" @@ -284,22 +283,12 @@ func (f *Framework) VerifyBlankDisk(namespace *k8sv1.Namespace, pvc *k8sv1.Persi // VerifySparse checks a disk image being sparse after creation/resize. func (f *Framework) VerifySparse(namespace *k8sv1.Namespace, pvc *k8sv1.PersistentVolumeClaim, imagePath string) (bool, error) { var info image.ImgInfo - var imageContentSize int64 err := f.GetImageInfo(namespace, pvc, imagePath, &info) if err != nil { return false, err } - // qemu-img info gives us ActualSize but that is size on disk - // which isn't important to us in this comparison; we compare content size - err = f.GetImageContentSize(namespace, pvc, imagePath, &imageContentSize) - if err != nil { - return false, err - } - if info.ActualSize-imageContentSize >= units.MiB { - return false, fmt.Errorf("Diff between content size %d and size on disk %d is significant, something's not right", imageContentSize, info.ActualSize) - } - fmt.Fprintf(ginkgo.GinkgoWriter, "INFO: VerifySparse comparison: Virtual: %d vs Content: %d\n", info.VirtualSize, imageContentSize) - return info.VirtualSize >= imageContentSize, nil + // The content size of a sparse image is significantly lower than the image's virtual size + return info.VirtualSize-info.ActualSize >= units.MiB, nil } // VerifyFSOverhead checks whether virtual size is smaller than actual size. That means FS Overhead has been accounted for. @@ -546,26 +535,6 @@ func (f *Framework) GetImageInfo(namespace *k8sv1.Namespace, pvc *k8sv1.Persiste return err } -// GetImageContentSize returns the content size (as opposed to size on disk) of an image -func (f *Framework) GetImageContentSize(namespace *k8sv1.Namespace, pvc *k8sv1.PersistentVolumeClaim, imagePath string, imageSize *int64) error { - cmd := fmt.Sprintf("du -s --apparent-size -B 1 %s | cut -f 1", imagePath) - - _, err := f.verifyInPod(namespace, pvc, cmd, func(output, stderr string) (bool, error) { - fmt.Fprintf(ginkgo.GinkgoWriter, "CMD (%s) output %s\n", cmd, output) - - size, err := strconv.ParseInt(output, 10, 64) - if err != nil { - klog.Errorf("Invalid image content size:\n%s\n", output) - return false, err - } - *imageSize = size - - return true, nil - }) - - return err -} - func (f *Framework) startVerifierPod(namespace *k8sv1.Namespace, pvc *k8sv1.PersistentVolumeClaim) (*k8sv1.Pod, error) { var executorPod *k8sv1.Pod var err error