From ac7cf70953f762e4f4ed94b58086a4cb0cd0880e Mon Sep 17 00:00:00 2001 From: Hans Rakers Date: Mon, 1 Jul 2024 16:19:06 +0200 Subject: [PATCH] fix: Fix & improve sanity tests --- pkg/driver/node.go | 9 ++++++++ pkg/mount/fake.go | 46 ++++++++++++++++++++++++++++++-------- test/sanity/sanity_test.go | 2 ++ 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/pkg/driver/node.go b/pkg/driver/node.go index b8381ba..6050af8 100644 --- a/pkg/driver/node.go +++ b/pkg/driver/node.go @@ -549,6 +549,15 @@ func (ns *nodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV } defer ns.volumeLocks.Release(volumeID) + _, err := ns.connector.GetVolumeByID(ctx, volumeID) + if err != nil { + if errors.Is(err, cloud.ErrNotFound) { + return nil, status.Error(codes.NotFound, fmt.Sprintf("Volume with ID %s not found", volumeID)) + } + + return nil, status.Error(codes.Internal, fmt.Sprintf("NodeExpandVolume failed with error %v", err)) + } + devicePath, err := ns.mounter.GetDevicePath(ctx, volumeID) if devicePath == "" { return nil, status.Error(codes.Internal, fmt.Sprintf("Unable to find Device path for volume %s: %v", volumeID, err)) diff --git a/pkg/mount/fake.go b/pkg/mount/fake.go index 5b3daf9..8129033 100644 --- a/pkg/mount/fake.go +++ b/pkg/mount/fake.go @@ -8,6 +8,10 @@ import ( exec "k8s.io/utils/exec/testing" ) +const ( + giB = 1 << 30 +) + type fakeMounter struct { mount.SafeFormatAndMount } @@ -35,7 +39,13 @@ func (m *fakeMounter) GetDeviceName(mountPath string) (string, int, error) { return mount.GetDeviceNameFromMount(m, mountPath) } -func (*fakeMounter) PathExists(_ string) (bool, error) { +func (*fakeMounter) PathExists(path string) (bool, error) { + if _, err := os.Stat(path); os.IsNotExist(err) { + return false, nil + } else if err != nil { + return false, err + } + return true, nil } @@ -50,16 +60,34 @@ func (*fakeMounter) MakeDir(pathname string) error { return nil } -func (*fakeMounter) MakeFile(_ string) error { +func (*fakeMounter) MakeFile(pathname string) error { + file, err := os.OpenFile(pathname, os.O_CREATE, os.FileMode(0o644)) + if err != nil { + if !os.IsExist(err) { + return err + } + } + if err = file.Close(); err != nil { + return err + } + return nil } func (m *fakeMounter) GetStatistics(_ string) (volumeStatistics, error) { - return volumeStatistics{}, nil + return volumeStatistics{ + AvailableBytes: 3 * giB, + TotalBytes: 10 * giB, + UsedBytes: 7 * giB, + + AvailableInodes: 3000, + TotalInodes: 10000, + UsedInodes: 7000, + }, nil } func (m *fakeMounter) IsBlockDevice(_ string) (bool, error) { - return true, nil + return false, nil } func (m *fakeMounter) IsCorruptedMnt(_ error) bool { @@ -67,17 +95,17 @@ func (m *fakeMounter) IsCorruptedMnt(_ error) bool { } func (m *fakeMounter) NeedResize(_ string, _ string) (bool, error) { - return true, nil + return false, nil } func (m *fakeMounter) Resize(_ string, _ string) (bool, error) { return true, nil } -func (m *fakeMounter) Unpublish(_ string) error { - return nil +func (m *fakeMounter) Unpublish(path string) error { + return m.Unstage(path) } -func (m *fakeMounter) Unstage(_ string) error { - return nil +func (m *fakeMounter) Unstage(path string) error { + return mount.CleanupMountPoint(path, m, true) } diff --git a/test/sanity/sanity_test.go b/test/sanity/sanity_test.go index ee1f4b8..2a6780b 100644 --- a/test/sanity/sanity_test.go +++ b/test/sanity/sanity_test.go @@ -35,6 +35,8 @@ func TestSanity(t *testing.T) { config.TestVolumeParameters = map[string]string{ driver.DiskOfferingKey: "9743fd77-0f5d-4ef9-b2f8-f194235c769c", } + config.IdempotentCount = 5 + config.TestNodeVolumeAttachLimit = true logger := klog.Background() ctx := klog.NewContext(context.Background(), logger)