From b69f5cdf4816847993355d624d21f2a784d3331c Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Tue, 5 Jan 2021 17:36:42 -0800 Subject: [PATCH] add volume stats metrics update tests --- pkg/driver/node.go | 14 ++++++++------ pkg/driver/sanity_test.go | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/driver/node.go b/pkg/driver/node.go index ae56f659df..e0c2405903 100644 --- a/pkg/driver/node.go +++ b/pkg/driver/node.go @@ -356,17 +356,19 @@ func (d *nodeService) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVo return nil, status.Error(codes.InvalidArgument, "NodeGetVolumeStats volume path was empty") } - exists, err := d.mounter.ExistsPath(req.VolumePath) + _, err := os.Stat(req.VolumePath) if err != nil { - return nil, status.Errorf(codes.Internal, "unknown error when stat on %s: %v", req.VolumePath, err) - } - if !exists { - return nil, status.Errorf(codes.NotFound, "path %s does not exist", req.VolumePath) + if os.IsNotExist(err) { + return nil, status.Errorf(codes.NotFound, "path %s does not exist", req.VolumePath) + } + return nil, status.Errorf(codes.Internal, "failed to stat file %s: %v", req.VolumePath, err) } isBlock, err := d.statter.IsBlockDevice(req.VolumePath) + + //isBlock, err := hostutil.NewHostUtil().PathIsDevice() if err != nil { - return nil, status.Errorf(codes.Internal, "failed to determine whether %s is block device: %v", req.VolumePath, err) + return nil, status.Errorf(codes.NotFound, "failed to determine whether %s is block device: %v", req.VolumePath, err) } if isBlock { bcap, err := d.getBlockSizeBytes(req.VolumePath) diff --git a/pkg/driver/sanity_test.go b/pkg/driver/sanity_test.go index d3e44d7e14..c146fcad7f 100644 --- a/pkg/driver/sanity_test.go +++ b/pkg/driver/sanity_test.go @@ -26,7 +26,7 @@ func TestSanity(t *testing.T) { } defer os.RemoveAll(dir) - targetPath := filepath.Join(dir, "target") + targetPath := filepath.Join(dir, "mount") stagingPath := filepath.Join(dir, "staging") endpoint := "unix://" + filepath.Join(dir, "csi.sock")