Skip to content

Commit ac7cf70

Browse files
committed
fix: Fix & improve sanity tests
1 parent 106d416 commit ac7cf70

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

pkg/driver/node.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,15 @@ func (ns *nodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV
549549
}
550550
defer ns.volumeLocks.Release(volumeID)
551551

552+
_, err := ns.connector.GetVolumeByID(ctx, volumeID)
553+
if err != nil {
554+
if errors.Is(err, cloud.ErrNotFound) {
555+
return nil, status.Error(codes.NotFound, fmt.Sprintf("Volume with ID %s not found", volumeID))
556+
}
557+
558+
return nil, status.Error(codes.Internal, fmt.Sprintf("NodeExpandVolume failed with error %v", err))
559+
}
560+
552561
devicePath, err := ns.mounter.GetDevicePath(ctx, volumeID)
553562
if devicePath == "" {
554563
return nil, status.Error(codes.Internal, fmt.Sprintf("Unable to find Device path for volume %s: %v", volumeID, err))

pkg/mount/fake.go

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import (
88
exec "k8s.io/utils/exec/testing"
99
)
1010

11+
const (
12+
giB = 1 << 30
13+
)
14+
1115
type fakeMounter struct {
1216
mount.SafeFormatAndMount
1317
}
@@ -35,7 +39,13 @@ func (m *fakeMounter) GetDeviceName(mountPath string) (string, int, error) {
3539
return mount.GetDeviceNameFromMount(m, mountPath)
3640
}
3741

38-
func (*fakeMounter) PathExists(_ string) (bool, error) {
42+
func (*fakeMounter) PathExists(path string) (bool, error) {
43+
if _, err := os.Stat(path); os.IsNotExist(err) {
44+
return false, nil
45+
} else if err != nil {
46+
return false, err
47+
}
48+
3949
return true, nil
4050
}
4151

@@ -50,34 +60,52 @@ func (*fakeMounter) MakeDir(pathname string) error {
5060
return nil
5161
}
5262

53-
func (*fakeMounter) MakeFile(_ string) error {
63+
func (*fakeMounter) MakeFile(pathname string) error {
64+
file, err := os.OpenFile(pathname, os.O_CREATE, os.FileMode(0o644))
65+
if err != nil {
66+
if !os.IsExist(err) {
67+
return err
68+
}
69+
}
70+
if err = file.Close(); err != nil {
71+
return err
72+
}
73+
5474
return nil
5575
}
5676

5777
func (m *fakeMounter) GetStatistics(_ string) (volumeStatistics, error) {
58-
return volumeStatistics{}, nil
78+
return volumeStatistics{
79+
AvailableBytes: 3 * giB,
80+
TotalBytes: 10 * giB,
81+
UsedBytes: 7 * giB,
82+
83+
AvailableInodes: 3000,
84+
TotalInodes: 10000,
85+
UsedInodes: 7000,
86+
}, nil
5987
}
6088

6189
func (m *fakeMounter) IsBlockDevice(_ string) (bool, error) {
62-
return true, nil
90+
return false, nil
6391
}
6492

6593
func (m *fakeMounter) IsCorruptedMnt(_ error) bool {
6694
return false
6795
}
6896

6997
func (m *fakeMounter) NeedResize(_ string, _ string) (bool, error) {
70-
return true, nil
98+
return false, nil
7199
}
72100

73101
func (m *fakeMounter) Resize(_ string, _ string) (bool, error) {
74102
return true, nil
75103
}
76104

77-
func (m *fakeMounter) Unpublish(_ string) error {
78-
return nil
105+
func (m *fakeMounter) Unpublish(path string) error {
106+
return m.Unstage(path)
79107
}
80108

81-
func (m *fakeMounter) Unstage(_ string) error {
82-
return nil
109+
func (m *fakeMounter) Unstage(path string) error {
110+
return mount.CleanupMountPoint(path, m, true)
83111
}

test/sanity/sanity_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ func TestSanity(t *testing.T) {
3535
config.TestVolumeParameters = map[string]string{
3636
driver.DiskOfferingKey: "9743fd77-0f5d-4ef9-b2f8-f194235c769c",
3737
}
38+
config.IdempotentCount = 5
39+
config.TestNodeVolumeAttachLimit = true
3840

3941
logger := klog.Background()
4042
ctx := klog.NewContext(context.Background(), logger)

0 commit comments

Comments
 (0)