Skip to content

Commit fe50ac6

Browse files
authored
Merge pull request #2254 from ElijahQuinones/sanity
Add csi-sanity tests
2 parents 0db674b + ac2d236 commit fe50ac6

19 files changed

+562
-22
lines changed

.golangci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ issues:
2323
- path: tests/e2e
2424
linters:
2525
- gosec
26+
- path: tests/sanity
27+
linters:
28+
- gosec
2629
linters-settings:
2730
revive:
2831
rules:

Makefile

+4-7
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@ test/coverage:
8282
go tool cover -html=filtered_cover.out -o coverage.html
8383
rm cover.out filtered_cover.out
8484

85-
# TODO: Re-enable sanity tests
86-
# sanity tests have been disabled with the removal of NewFakeDriver, which was previously created to instantiate a fake driver utilized for testing.
87-
# to re-enable tests, implement sanity tests creating a new driver instance by injecting mocked dependencies.
88-
#.PHONY: test-sanity
89-
#test-sanity:
90-
# go test -v -race ./tests/sanity/...
91-
9285
.PHONY: tools
9386
tools: bin/aws bin/ct bin/eksctl bin/ginkgo bin/golangci-lint bin/gomplate bin/helm bin/kops bin/kubetest2 bin/mockgen bin/shfmt
9487

@@ -127,6 +120,10 @@ cluster/uninstall: bin/helm bin/aws
127120
## E2E targets
128121
# Targets to run e2e tests
129122

123+
.PHONY: sanity
124+
sanity:
125+
go test -v -race ./tests/sanity/...
126+
130127
.PHONY: e2e/single-az
131128
e2e/single-az: bin/helm bin/ginkgo
132129
AWS_AVAILABILITY_ZONES=us-west-2a \

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/google/uuid v1.6.0
1414
github.com/kubernetes-csi/csi-proxy/client v1.1.3
1515
github.com/kubernetes-csi/csi-proxy/v2 v2.0.0-alpha.1
16+
github.com/kubernetes-csi/csi-test/v5 v5.3.1
1617
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0
1718
github.com/onsi/ginkgo/v2 v2.22.1
1819
github.com/onsi/gomega v1.36.2
@@ -144,6 +145,7 @@ require (
144145
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
145146
gopkg.in/inf.v0 v0.9.1 // indirect
146147
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
148+
gopkg.in/yaml.v2 v2.4.0 // indirect
147149
gopkg.in/yaml.v3 v3.0.1 // indirect
148150
k8s.io/apiextensions-apiserver v0.32.0 // indirect
149151
k8s.io/apiserver v0.32.0 // indirect

go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ github.com/kubernetes-csi/csi-proxy/client v1.1.3 h1:FdGU7NtxGhQX2wTfnuscmThG920
249249
github.com/kubernetes-csi/csi-proxy/client v1.1.3/go.mod h1:SfK4HVKQdMH5KrffivddAWgX5hl3P5KmnuOTBbDNboU=
250250
github.com/kubernetes-csi/csi-proxy/v2 v2.0.0-alpha.1 h1:tVPvlL5N5X598hrO3g9rhyoi6h0LP4RpSJlGHItsbEE=
251251
github.com/kubernetes-csi/csi-proxy/v2 v2.0.0-alpha.1/go.mod h1:pacx+PW7lLlu6kAvpr8Lgq/5fdiAsKxOtXXFHMaLMb8=
252+
github.com/kubernetes-csi/csi-test/v5 v5.3.1 h1:Wiukp1In+kif+BFo6q2ExjgB+MbrAz4jZWzGfijypuY=
253+
github.com/kubernetes-csi/csi-test/v5 v5.3.1/go.mod h1:7hA2cSYJ6T8CraEZPA6zqkLZwemjBD54XAnPsPC3VpA=
252254
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 h1:nHHjmvjitIiyPlUHk/ofpgvBcNcawJLtf4PYHORLjAA=
253255
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0/go.mod h1:YBCo4DoEeDndqvAn6eeu0vWM7QdXmHEeI9cFWplmBys=
254256
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
@@ -737,6 +739,7 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
737739
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
738740
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
739741
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
742+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
740743
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
741744
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
742745
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

pkg/cloud/metadata/mock_metadata.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cloud/mock_cloud.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cloud/mock_ec2.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/driver/controller_modify_volume.go

+2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ func executeModifyVolumeRequest(c cloud.Cloud) func(string, modifyVolumeRequest)
150150
if err != nil {
151151
if errors.Is(err, cloud.ErrInvalidArgument) {
152152
return 0, status.Errorf(codes.InvalidArgument, "Could not modify volume (invalid argument) %q: %v", volumeID, err)
153+
} else if errors.Is(err, cloud.ErrNotFound) {
154+
return 0, status.Errorf(codes.NotFound, "Could not modify volume (not found) %q: %v", volumeID, err)
153155
}
154156
return 0, status.Errorf(codes.Internal, "Could not modify volume %q: %v", volumeID, err)
155157
} else {

pkg/driver/mock_k8s_client.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/driver/mock_k8s_corev1.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/driver/mock_k8s_storagev1.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/driver/mock_k8s_storagev1_csinode.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/driver/node.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func (d *NodeService) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
207207

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

213213
klog.V(4).InfoS("NodeStageVolume: find device path", "devicePath", devicePath, "source", source)
@@ -387,15 +387,14 @@ func (d *NodeService) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV
387387
return &csi.NodeExpandVolumeResponse{CapacityBytes: bcap}, nil
388388
}
389389
}
390-
391390
deviceName, _, err := d.mounter.GetDeviceNameFromMount(volumePath)
392391
if err != nil {
393392
return nil, status.Errorf(codes.Internal, "failed to get device name from mount %s: %v", volumePath, err)
394393
}
395394

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

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

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

632631
klog.V(4).InfoS("NodePublishVolume [block]: find device path", "devicePath", devicePath, "source", source)

pkg/driver/node_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ func TestNodeStageVolume(t *testing.T) {
642642
m.EXPECT().GetRegion().Return("us-west-2")
643643
return m
644644
},
645-
expectedErr: status.Errorf(codes.Internal, "Failed to find device path %s. %v", "/dev/xvdba", errors.New("find device path error")),
645+
expectedErr: status.Errorf(codes.NotFound, "Failed to find device path %s. %v", "/dev/xvdba", errors.New("find device path error")),
646646
},
647647
{
648648
name: "path_exists_error",
@@ -1743,7 +1743,7 @@ func TestNodePublishVolume(t *testing.T) {
17431743
m.EXPECT().GetRegion().Return("us-west-2")
17441744
return m
17451745
},
1746-
expectedErr: status.Error(codes.Internal, "Failed to find device path /dev/xvdba. device path error"),
1746+
expectedErr: status.Error(codes.NotFound, "Failed to find device path /dev/xvdba. device path error"),
17471747
},
17481748
}
17491749
for _, tc := range testCases {
@@ -2271,7 +2271,7 @@ func TestNodeExpandVolume(t *testing.T) {
22712271
return m
22722272
},
22732273
expectedResp: nil,
2274-
expectedErr: status.Error(codes.Internal, "failed to find device path for device name device-name for mount /volume/path: failed to find device path"),
2274+
expectedErr: status.Error(codes.NotFound, "failed to find device path for device name device-name for mount /volume/path: failed to find device path"),
22752275
},
22762276
{
22772277
name: "resize_error",

pkg/mounter/mock_mount.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)