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 Jan 2, 2025
1 parent 0db674b commit 408dd82
Show file tree
Hide file tree
Showing 19 changed files with 563 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ issues:
- path: tests/e2e
linters:
- gosec
- path: tests/sanity
linters:
- gosec
linters-settings:
revive:
rules:
Expand Down
12 changes: 5 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ test/coverage:
go tool cover -html=filtered_cover.out -o coverage.html
rm cover.out filtered_cover.out

# TODO: Re-enable sanity tests
# sanity tests have been disabled with the removal of NewFakeDriver, which was previously created to instantiate a fake driver utilized for testing.
# to re-enable tests, implement sanity tests creating a new driver instance by injecting mocked dependencies.
#.PHONY: test-sanity
#test-sanity:
# go test -v -race ./tests/sanity/...

.PHONY: tools
tools: bin/aws bin/ct bin/eksctl bin/ginkgo bin/golangci-lint bin/gomplate bin/helm bin/kops bin/kubetest2 bin/mockgen bin/shfmt

Expand Down Expand Up @@ -127,6 +120,10 @@ cluster/uninstall: bin/helm bin/aws
## E2E targets
# Targets to run e2e tests

.PHONY: sanity
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 Expand Up @@ -296,6 +293,7 @@ verify/golangci-lint: bin/golangci-lint

.PHONY: verify/govet
verify/govet:
go env
go vet $$(go list ./...)

.PHONY: verify/update
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/google/uuid v1.6.0
github.com/kubernetes-csi/csi-proxy/client v1.1.3
github.com/kubernetes-csi/csi-proxy/v2 v2.0.0-alpha.1
github.com/kubernetes-csi/csi-test/v5 v5.3.1
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0
github.com/onsi/ginkgo/v2 v2.22.1
github.com/onsi/gomega v1.36.2
Expand Down Expand Up @@ -144,6 +145,7 @@ require (
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.32.0 // indirect
k8s.io/apiserver v0.32.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,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 Expand Up @@ -737,6 +739,7 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/metadata/mock_metadata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/cloud/mock_cloud.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/cloud/mock_ec2.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
2 changes: 1 addition & 1 deletion pkg/driver/mock_k8s_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/driver/mock_k8s_corev1.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/driver/mock_k8s_storagev1.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/driver/mock_k8s_storagev1_csinode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (d *NodeService) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol

source, err := d.mounter.FindDevicePath(devicePath, volumeID, partition, d.metadata.GetRegion())
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to find device path %s. %v", devicePath, err)
return nil, status.Errorf(codes.NotFound, "Failed to find device path %s. %v", devicePath, err)
}

klog.V(4).InfoS("NodeStageVolume: find device path", "devicePath", devicePath, "source", source)
Expand Down Expand Up @@ -387,15 +387,14 @@ func (d *NodeService) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV
return &csi.NodeExpandVolumeResponse{CapacityBytes: bcap}, nil
}
}

deviceName, _, err := d.mounter.GetDeviceNameFromMount(volumePath)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get device name from mount %s: %v", volumePath, err)
}

devicePath, err := d.mounter.FindDevicePath(deviceName, volumeID, "", d.metadata.GetRegion())
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to find device path for device name %s for mount %s: %v", deviceName, req.GetVolumePath(), err)
return nil, status.Errorf(codes.NotFound, "failed to find device path for device name %s for mount %s: %v", deviceName, req.GetVolumePath(), err)
}

// TODO: lock per volume ID to have some idempotency
Expand Down Expand Up @@ -626,7 +625,7 @@ func (d *NodeService) nodePublishVolumeForBlock(req *csi.NodePublishVolumeReques

source, err := d.mounter.FindDevicePath(devicePath, volumeID, partition, d.metadata.GetRegion())
if err != nil {
return status.Errorf(codes.Internal, "Failed to find device path %s. %v", devicePath, err)
return status.Errorf(codes.NotFound, "Failed to find device path %s. %v", devicePath, err)
}

klog.V(4).InfoS("NodePublishVolume [block]: find device path", "devicePath", devicePath, "source", source)
Expand Down
6 changes: 3 additions & 3 deletions pkg/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ func TestNodeStageVolume(t *testing.T) {
m.EXPECT().GetRegion().Return("us-west-2")
return m
},
expectedErr: status.Errorf(codes.Internal, "Failed to find device path %s. %v", "/dev/xvdba", errors.New("find device path error")),
expectedErr: status.Errorf(codes.NotFound, "Failed to find device path %s. %v", "/dev/xvdba", errors.New("find device path error")),
},
{
name: "path_exists_error",
Expand Down Expand Up @@ -1743,7 +1743,7 @@ func TestNodePublishVolume(t *testing.T) {
m.EXPECT().GetRegion().Return("us-west-2")
return m
},
expectedErr: status.Error(codes.Internal, "Failed to find device path /dev/xvdba. device path error"),
expectedErr: status.Error(codes.NotFound, "Failed to find device path /dev/xvdba. device path error"),
},
}
for _, tc := range testCases {
Expand Down Expand Up @@ -2271,7 +2271,7 @@ func TestNodeExpandVolume(t *testing.T) {
return m
},
expectedResp: nil,
expectedErr: status.Error(codes.Internal, "failed to find device path for device name device-name for mount /volume/path: failed to find device path"),
expectedErr: status.Error(codes.NotFound, "failed to find device path for device name device-name for mount /volume/path: failed to find device path"),
},
{
name: "resize_error",
Expand Down
2 changes: 1 addition & 1 deletion pkg/mounter/mock_mount.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 408dd82

Please sign in to comment.