Skip to content

Commit

Permalink
Add csi-sanity tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ElijahQuinones committed Dec 6, 2024
1 parent 73e6802 commit 508b90e
Show file tree
Hide file tree
Showing 7 changed files with 433 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ cluster/uninstall: bin/helm bin/aws
## E2E targets
# Targets to run e2e tests

.PHONY: test-sanity
test-sanity:
go test -v -race ./tests/sanity/...

.PHONY: e2e/single-az
e2e/single-az: bin/helm bin/ginkgo
AWS_AVAILABILITY_ZONES=us-west-2a \
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/kubernetes-csi/csi-test/v5 v5.3.1
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/moby/spdystream v0.5.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ github.com/kubernetes-csi/csi-proxy/client v1.1.3 h1:FdGU7NtxGhQX2wTfnuscmThG920
github.com/kubernetes-csi/csi-proxy/client v1.1.3/go.mod h1:SfK4HVKQdMH5KrffivddAWgX5hl3P5KmnuOTBbDNboU=
github.com/kubernetes-csi/csi-proxy/v2 v2.0.0-alpha.1 h1:tVPvlL5N5X598hrO3g9rhyoi6h0LP4RpSJlGHItsbEE=
github.com/kubernetes-csi/csi-proxy/v2 v2.0.0-alpha.1/go.mod h1:pacx+PW7lLlu6kAvpr8Lgq/5fdiAsKxOtXXFHMaLMb8=
github.com/kubernetes-csi/csi-test/v5 v5.3.1 h1:Wiukp1In+kif+BFo6q2ExjgB+MbrAz4jZWzGfijypuY=
github.com/kubernetes-csi/csi-test/v5 v5.3.1/go.mod h1:7hA2cSYJ6T8CraEZPA6zqkLZwemjBD54XAnPsPC3VpA=
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 h1:nHHjmvjitIiyPlUHk/ofpgvBcNcawJLtf4PYHORLjAA=
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0/go.mod h1:YBCo4DoEeDndqvAn6eeu0vWM7QdXmHEeI9cFWplmBys=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
Expand Down
2 changes: 2 additions & 0 deletions pkg/driver/controller_modify_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ func executeModifyVolumeRequest(c cloud.Cloud) func(string, modifyVolumeRequest)
if err != nil {
if errors.Is(err, cloud.ErrInvalidArgument) {
return 0, status.Errorf(codes.InvalidArgument, "Could not modify volume (invalid argument) %q: %v", volumeID, err)
} else if errors.Is(err, cloud.ErrNotFound) {
return 0, status.Errorf(codes.NotFound, "Could not modify volume (not found) %q: %v", volumeID, err)
}
return 0, status.Errorf(codes.Internal, "Could not modify volume %q: %v", volumeID, err)
} else {
Expand Down
7 changes: 7 additions & 0 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,13 @@ func (d *NodeService) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV
return &csi.NodeExpandVolumeResponse{CapacityBytes: bcap}, nil
}
}
exists, err := d.mounter.PathExists(req.GetVolumePath())
if err != nil {
return nil, status.Errorf(codes.Internal, "unknown error when stat on %s: %v", req.GetVolumePath(), err)
}
if !exists {
return nil, status.Errorf(codes.NotFound, "path %s does not exist", req.GetVolumePath())
}

deviceName, _, err := d.mounter.GetDeviceNameFromMount(volumePath)
if err != nil {
Expand Down
21 changes: 21 additions & 0 deletions pkg/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,7 @@ func TestNodeExpandVolume(t *testing.T) {
},
mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter {
m := mounter.NewMockMounter(ctrl)
m.EXPECT().PathExists(gomock.Eq("/volume/path")).Return(true, nil)
m.EXPECT().IsBlockDevice(gomock.Eq("/volume/path")).Return(false, nil)
m.EXPECT().GetDeviceNameFromMount(gomock.Eq("/volume/path")).Return("device-name", 1, nil)
m.EXPECT().FindDevicePath(gomock.Eq("device-name"), gomock.Eq("vol-test"), gomock.Eq(""), gomock.Eq("us-west-2")).Return("/dev/xvdba", nil)
Expand Down Expand Up @@ -2244,6 +2245,7 @@ func TestNodeExpandVolume(t *testing.T) {
},
mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter {
m := mounter.NewMockMounter(ctrl)
m.EXPECT().PathExists(gomock.Eq("/volume/path")).Return(true, nil)
m.EXPECT().IsBlockDevice(gomock.Eq("/volume/path")).Return(false, nil)
m.EXPECT().GetDeviceNameFromMount(gomock.Eq("/volume/path")).Return("", 0, errors.New("failed to get device name"))
return m
Expand All @@ -2260,6 +2262,7 @@ func TestNodeExpandVolume(t *testing.T) {
},
mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter {
m := mounter.NewMockMounter(ctrl)
m.EXPECT().PathExists(gomock.Eq("/volume/path")).Return(true, nil)
m.EXPECT().IsBlockDevice(gomock.Eq("/volume/path")).Return(false, nil)
m.EXPECT().GetDeviceNameFromMount(gomock.Eq("/volume/path")).Return("device-name", 1, nil)
m.EXPECT().FindDevicePath(gomock.Eq("device-name"), gomock.Eq("vol-test"), gomock.Eq(""), gomock.Eq("us-west-2")).Return("", errors.New("failed to find device path"))
Expand All @@ -2281,6 +2284,7 @@ func TestNodeExpandVolume(t *testing.T) {
},
mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter {
m := mounter.NewMockMounter(ctrl)
m.EXPECT().PathExists(gomock.Eq("/volume/path")).Return(true, nil)
m.EXPECT().IsBlockDevice(gomock.Eq("/volume/path")).Return(false, nil)
m.EXPECT().GetDeviceNameFromMount(gomock.Eq("/volume/path")).Return("device-name", 1, nil)
m.EXPECT().FindDevicePath(gomock.Eq("device-name"), gomock.Eq("vol-test"), gomock.Eq(""), gomock.Eq("us-west-2")).Return("/dev/xvdba", nil)
Expand All @@ -2303,6 +2307,7 @@ func TestNodeExpandVolume(t *testing.T) {
},
mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter {
m := mounter.NewMockMounter(ctrl)
m.EXPECT().PathExists(gomock.Eq("/volume/path")).Return(true, nil)
m.EXPECT().IsBlockDevice(gomock.Eq("/volume/path")).Return(false, nil)
m.EXPECT().GetDeviceNameFromMount(gomock.Eq("/volume/path")).Return("device-name", 1, nil)
m.EXPECT().FindDevicePath(gomock.Eq("device-name"), gomock.Eq("vol-test"), gomock.Eq(""), gomock.Eq("us-west-2")).Return("/dev/xvdba", nil)
Expand All @@ -2318,6 +2323,22 @@ func TestNodeExpandVolume(t *testing.T) {
expectedResp: nil,
expectedErr: status.Error(codes.Internal, "failed to get block capacity on path /volume/path: failed to get block size"),
},
{
name: "get_not_found_error",
req: &csi.NodeExpandVolumeRequest{
VolumeId: "vol-test",
VolumePath: "/volume/path",
},
mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter {
m := mounter.NewMockMounter(ctrl)
m.EXPECT().PathExists(gomock.Eq("/volume/path")).Return(false, nil)
m.EXPECT().IsBlockDevice(gomock.Eq("/volume/path")).Return(false, nil)
return m
},
metadataMock: nil,
expectedResp: nil,
expectedErr: status.Errorf(codes.NotFound, "path /volume/path does not exist"),
},
}

for _, tc := range testCases {
Expand Down
Loading

0 comments on commit 508b90e

Please sign in to comment.