Skip to content

Commit

Permalink
fix: Fix & improve sanity tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hrak committed Jul 1, 2024
1 parent 106d416 commit ac7cf70
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
9 changes: 9 additions & 0 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
46 changes: 37 additions & 9 deletions pkg/mount/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
exec "k8s.io/utils/exec/testing"
)

const (
giB = 1 << 30
)

type fakeMounter struct {
mount.SafeFormatAndMount
}
Expand Down Expand Up @@ -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
}

Expand All @@ -50,34 +60,52 @@ 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 {
return false
}

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)
}
2 changes: 2 additions & 0 deletions test/sanity/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ac7cf70

Please sign in to comment.