From c750a2d3e96c17d445a2a0093703cfb34acbef07 Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Fri, 11 Oct 2024 19:32:30 +0200 Subject: [PATCH] Fix: checking available image size Signed-off-by: Andrei Kvapil --- pkg/image/qemu.go | 4 ++-- pkg/image/qemu_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/image/qemu.go b/pkg/image/qemu.go index 07eaf03272..e97365e6be 100644 --- a/pkg/image/qemu.go +++ b/pkg/image/qemu.go @@ -242,8 +242,8 @@ func checkIfURLIsValid(info *ImgInfo, availableSize int64, image string) error { } } - if availableSize < info.VirtualSize { - return errors.Errorf("virtual image size %d is larger than the reported available storage %d. A larger PVC is required", info.VirtualSize, availableSize) + if availableSize > info.VirtualSize { + return errors.Errorf("virtual image size %d is smaller than the reported available storage %d. A larger PVC is required", info.VirtualSize, availableSize) } return nil } diff --git a/pkg/image/qemu_test.go b/pkg/image/qemu_test.go index ae5c0bf7b8..c9a30fbb13 100644 --- a/pkg/image/qemu_test.go +++ b/pkg/image/qemu_test.go @@ -304,7 +304,7 @@ var _ = Describe("Validate", func() { Entry("should return error on bad json", mockExecFunction(badValidateJSON, "", expectedLimits), "unexpected end of JSON input", imageName), Entry("should return error on bad format", mockExecFunction(badFormatValidateJSON, "", expectedLimits), fmt.Sprintf("Invalid format raw2 for image %s", imageName), imageName), Entry("should return error on invalid backing file", mockExecFunction(backingFileValidateJSON, "", expectedLimits), fmt.Sprintf("Image %s is invalid because it has invalid backing file backing-file.qcow2", imageName), imageName), - Entry("should return error when PVC is too small", mockExecFunction(hugeValidateJSON, "", expectedLimits), fmt.Sprintf("virtual image size %d is larger than the reported available storage %d. A larger PVC is required", 52949672960, 42949672960), imageName), + Entry("should return error when PVC is too small", mockExecFunction(hugeValidateJSON, "", expectedLimits), fmt.Sprintf("virtual image size %d is smaller than the reported available storage %d. A larger PVC is required", 42949672960, 52949672960), imageName), ) })