diff --git a/Makefile b/Makefile index 3e16805352..f8e62d0799 100644 --- a/Makefile +++ b/Makefile @@ -50,12 +50,12 @@ word-hyphen = $(word $2,$(subst -, ,$1)) .EXPORT_ALL_VARIABLES: -.PHONY: linux/$(ARCH) +.PHONY: linux/$(ARCH) bin/aws-ebs-csi-driver linux/$(ARCH): bin/aws-ebs-csi-driver bin/aws-ebs-csi-driver: | bin CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -mod=vendor -ldflags ${LDFLAGS} -o bin/aws-ebs-csi-driver ./cmd/ -.PHONY: windows/$(ARCH) +.PHONY: windows/$(ARCH) bin/aws-ebs-csi-driver.exe windows/$(ARCH): bin/aws-ebs-csi-driver.exe bin/aws-ebs-csi-driver.exe: | bin CGO_ENABLED=0 GOOS=windows GOARCH=$(ARCH) go build -mod=vendor -ldflags ${LDFLAGS} -o bin/aws-ebs-csi-driver.exe ./cmd/ diff --git a/hack/e2e/run.sh b/hack/e2e/run.sh index bbefc4fd54..ea87731701 100755 --- a/hack/e2e/run.sh +++ b/hack/e2e/run.sh @@ -42,7 +42,7 @@ REGION=${AWS_REGION:-us-west-2} ZONES=${AWS_AVAILABILITY_ZONES:-us-west-2a,us-west-2b,us-west-2c} FIRST_ZONE=$(echo "${ZONES}" | cut -d, -f1) NODE_COUNT=${NODE_COUNT:-3} -INSTANCE_TYPE=${INSTANCE_TYPE:-c4.large} +INSTANCE_TYPE=${INSTANCE_TYPE:-c5.large} AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) IMAGE_NAME=${IMAGE_NAME:-${AWS_ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/${DRIVER_NAME}} diff --git a/pkg/driver/mock_mount.go b/pkg/driver/mock_mount.go index 61e01dff89..d90ebec107 100644 --- a/pkg/driver/mock_mount.go +++ b/pkg/driver/mock_mount.go @@ -5,6 +5,7 @@ package driver import ( + os "os" reflect "reflect" gomock "github.com/golang/mock/gomock" @@ -236,3 +237,56 @@ func (mr *MockMounterMockRecorder) Unmount(target interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unmount", reflect.TypeOf((*MockMounter)(nil).Unmount), target) } + +// MockDeviceIdentifier is a mock of DeviceIdentifier interface. +type MockDeviceIdentifier struct { + ctrl *gomock.Controller + recorder *MockDeviceIdentifierMockRecorder +} + +// MockDeviceIdentifierMockRecorder is the mock recorder for MockDeviceIdentifier. +type MockDeviceIdentifierMockRecorder struct { + mock *MockDeviceIdentifier +} + +// NewMockDeviceIdentifier creates a new mock instance. +func NewMockDeviceIdentifier(ctrl *gomock.Controller) *MockDeviceIdentifier { + mock := &MockDeviceIdentifier{ctrl: ctrl} + mock.recorder = &MockDeviceIdentifierMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockDeviceIdentifier) EXPECT() *MockDeviceIdentifierMockRecorder { + return m.recorder +} + +// EvalSymlinks mocks base method. +func (m *MockDeviceIdentifier) EvalSymlinks(path string) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EvalSymlinks", path) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// EvalSymlinks indicates an expected call of EvalSymlinks. +func (mr *MockDeviceIdentifierMockRecorder) EvalSymlinks(path interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EvalSymlinks", reflect.TypeOf((*MockDeviceIdentifier)(nil).EvalSymlinks), path) +} + +// Lstat mocks base method. +func (m *MockDeviceIdentifier) Lstat(name string) (os.FileInfo, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Lstat", name) + ret0, _ := ret[0].(os.FileInfo) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Lstat indicates an expected call of Lstat. +func (mr *MockDeviceIdentifierMockRecorder) Lstat(name interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Lstat", reflect.TypeOf((*MockDeviceIdentifier)(nil).Lstat), name) +} diff --git a/pkg/driver/mount.go b/pkg/driver/mount.go index e82966dc88..9a22dbf599 100644 --- a/pkg/driver/mount.go +++ b/pkg/driver/mount.go @@ -17,6 +17,9 @@ limitations under the License. package driver import ( + "os" + "path/filepath" + "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/mounter" mountutils "k8s.io/mount-utils" ) @@ -54,3 +57,27 @@ func newNodeMounter() (Mounter, error) { } return &NodeMounter{safeMounter}, nil } + +// DeviceIdentifier is for mocking os io functions used for the driver to +// identify an EBS volume's corresponding device (in Linux, the path under +// /dev; in Windows, the volume number) so that it can mount it. For volumes +// already mounted, see GetDeviceNameFromMount. +// https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html#identify-nvme-ebs-device +type DeviceIdentifier interface { + Lstat(name string) (os.FileInfo, error) + EvalSymlinks(path string) (string, error) +} + +type nodeDeviceIdentifier struct{} + +func newNodeDeviceIdentifier() DeviceIdentifier { + return &nodeDeviceIdentifier{} +} + +func (i *nodeDeviceIdentifier) Lstat(name string) (os.FileInfo, error) { + return os.Lstat(name) +} + +func (i *nodeDeviceIdentifier) EvalSymlinks(path string) (string, error) { + return filepath.EvalSymlinks(path) +} diff --git a/pkg/driver/node.go b/pkg/driver/node.go index 068bfdd1e9..8c77227ee2 100644 --- a/pkg/driver/node.go +++ b/pkg/driver/node.go @@ -73,10 +73,11 @@ var ( // nodeService represents the node service of CSI driver type nodeService struct { - metadata cloud.MetadataService - mounter Mounter - inFlight *internal.InFlight - driverOptions *DriverOptions + metadata cloud.MetadataService + mounter Mounter + deviceIdentifier DeviceIdentifier + inFlight *internal.InFlight + driverOptions *DriverOptions } // newNodeService creates a new node service @@ -94,10 +95,11 @@ func newNodeService(driverOptions *DriverOptions) nodeService { } return nodeService{ - metadata: metadata, - mounter: nodeMounter, - inFlight: internal.NewInFlight(), - driverOptions: driverOptions, + metadata: metadata, + mounter: nodeMounter, + deviceIdentifier: newNodeDeviceIdentifier(), + inFlight: internal.NewInFlight(), + driverOptions: driverOptions, } } diff --git a/pkg/driver/node_linux.go b/pkg/driver/node_linux.go index 7ad539b541..fa72ba1658 100644 --- a/pkg/driver/node_linux.go +++ b/pkg/driver/node_linux.go @@ -33,41 +33,62 @@ import ( // findDevicePath finds path of device and verifies its existence // if the device is not nvme, return the path directly // if the device is nvme, finds and returns the nvme device path eg. /dev/nvme1n1 -func (d *nodeService) findDevicePath(devicePath, volumeID string, partition string) (string, error) { +func (d *nodeService) findDevicePath(devicePath, volumeID, partition string) (string, error) { + canonicalDevicePath := "" + + // If the given path exists, the device MAY be nvme. Further, it MAY be a + // symlink to the nvme device path like: + // | $ stat /dev/xvdba + // | File: ‘/dev/xvdba’ -> ‘nvme1n1’ + // Since these are maybes, not guarantees, the search for the nvme device + // path below must happen and must rely on volume ID exists, err := d.mounter.PathExists(devicePath) if err != nil { - return "", err + return "", fmt.Errorf("failed to check if path %q exists: %v", devicePath, err) } - // If the path exists, assume it is not nvme device if exists { if partition != "" { devicePath = devicePath + diskPartitionSuffix + partition } - return devicePath, nil + canonicalDevicePath = devicePath } - // Else find the nvme device path using volume ID - // This is the magic name on which AWS presents NVME devices under /dev/disk/by-id/ - // For example, vol-0fab1d5e3f72a5e23 creates a symlink at + // AWS recommends identifying devices by volume ID + // (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html), + // so find the nvme device path using volume ID. This is the magic name on + // which AWS presents NVME devices under /dev/disk/by-id/. For example, + // vol-0fab1d5e3f72a5e23 creates a symlink at // /dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_vol0fab1d5e3f72a5e23 nvmeName := "nvme-Amazon_Elastic_Block_Store_" + strings.Replace(volumeID, "-", "", -1) - nvmeDevicePath, err := findNvmeVolume(nvmeName) - if err != nil { - return "", err + nvmeDevicePath, err := findNvmeVolume(d.deviceIdentifier, nvmeName) + + if err == nil { + if partition != "" { + nvmeDevicePath = nvmeDevicePath + nvmeDiskPartitionSuffix + partition + } + canonicalDevicePath = nvmeDevicePath + } else { + klog.V(5).Infof("[Debug] error searching for nvme path %q: %v", nvmeName, err) } - if partition != "" { - nvmeDevicePath = nvmeDevicePath + nvmeDiskPartitionSuffix + partition + + if canonicalDevicePath == "" { + return "", errNoDevicePathFound(devicePath, volumeID) } - return nvmeDevicePath, nil + + return canonicalDevicePath, nil +} + +func errNoDevicePathFound(devicePath, volumeID string) error { + return fmt.Errorf("no device path for device %q volume %q found!", devicePath, volumeID) } // findNvmeVolume looks for the nvme volume with the specified name // It follows the symlink (if it exists) and returns the absolute path to the device -func findNvmeVolume(findName string) (device string, err error) { +func findNvmeVolume(deviceIdentifier DeviceIdentifier, findName string) (device string, err error) { p := filepath.Join("/dev/disk/by-id/", findName) - stat, err := os.Lstat(p) + stat, err := deviceIdentifier.Lstat(p) if err != nil { if os.IsNotExist(err) { klog.V(5).Infof("[Debug] nvme path %q not found", p) @@ -82,7 +103,7 @@ func findNvmeVolume(findName string) (device string, err error) { } // Find the target, resolving to an absolute path // For example, /dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_vol0fab1d5e3f72a5e23 -> ../../nvme2n1 - resolved, err := filepath.EvalSymlinks(p) + resolved, err := deviceIdentifier.EvalSymlinks(p) if err != nil { return "", fmt.Errorf("error reading target of symlink %q: %v", p, err) } diff --git a/pkg/driver/node_linux_test.go b/pkg/driver/node_linux_test.go new file mode 100644 index 0000000000..fa3a59007c --- /dev/null +++ b/pkg/driver/node_linux_test.go @@ -0,0 +1,181 @@ +//go:build linux +// +build linux + +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package driver + +import ( + "io/fs" + "os" + "testing" + "time" + + "github.com/golang/mock/gomock" + "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud" + "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver/internal" + "github.com/stretchr/testify/assert" +) + +func TestFindDevicePath(t *testing.T) { + devicePath := "/dev/xvbda" + nvmeDevicePath := "/dev/nvme1n1" + volumeID := "vol-test" + nvmeName := "/dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_voltest" + symlinkFileInfo := fs.FileInfo(&fakeFileInfo{nvmeName, os.ModeSymlink}) + type testCase struct { + name string + devicePath string + volumeID string + partition string + expectMock func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) + expectDevicePath string + expectError string + } + testCases := []testCase{ + { + name: "11: device path exists and nvme device path exists", + devicePath: devicePath, + volumeID: volumeID, + partition: "", + expectMock: func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) { + gomock.InOrder( + mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(true, nil), + + mockDeviceIdentifier.EXPECT().Lstat(gomock.Eq(nvmeName)).Return(symlinkFileInfo, nil), + mockDeviceIdentifier.EXPECT().EvalSymlinks(gomock.Eq(symlinkFileInfo.Name())).Return(nvmeDevicePath, nil), + ) + }, + expectDevicePath: nvmeDevicePath, + }, + { + name: "10: device path exists and nvme device path doesn't exist", + devicePath: devicePath, + volumeID: volumeID, + partition: "", + expectMock: func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) { + gomock.InOrder( + mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(true, nil), + + mockDeviceIdentifier.EXPECT().Lstat(gomock.Eq(nvmeName)).Return(nil, os.ErrNotExist), + ) + }, + expectDevicePath: devicePath, + }, + { + name: "01: device path doesn't exist and nvme device path exists", + devicePath: devicePath, + volumeID: volumeID, + partition: "", + expectMock: func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) { + gomock.InOrder( + mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(false, nil), + + mockDeviceIdentifier.EXPECT().Lstat(gomock.Eq(nvmeName)).Return(symlinkFileInfo, nil), + mockDeviceIdentifier.EXPECT().EvalSymlinks(gomock.Eq(symlinkFileInfo.Name())).Return(nvmeDevicePath, nil), + ) + }, + expectDevicePath: nvmeDevicePath, + }, + { + name: "00: device path doesn't exist and nvme device path doesn't exist", + devicePath: devicePath, + volumeID: volumeID, + partition: "", + expectMock: func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) { + gomock.InOrder( + mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(false, nil), + + mockDeviceIdentifier.EXPECT().Lstat(gomock.Eq(nvmeName)).Return(nil, os.ErrNotExist), + ) + }, + expectError: errNoDevicePathFound(devicePath, volumeID).Error(), + }, + } + // The partition variant of each case should be the same except the partition + // is expected to be appended to devicePath + generatedTestCases := []testCase{} + for _, tc := range testCases { + tc.name += " (with partition)" + tc.partition = "1" + if tc.expectDevicePath == devicePath { + tc.expectDevicePath += tc.partition + } else if tc.expectDevicePath == nvmeDevicePath { + tc.expectDevicePath += "p" + tc.partition + } + generatedTestCases = append(generatedTestCases, tc) + } + testCases = append(testCases, generatedTestCases...) + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + mockCtl := gomock.NewController(t) + defer mockCtl.Finish() + + mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) + + nodeDriver := nodeService{ + metadata: &cloud.Metadata{}, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), + driverOptions: &DriverOptions{}, + } + + if tc.expectMock != nil { + tc.expectMock(*mockMounter, *mockDeviceIdentifier) + } + + devicePath, err := nodeDriver.findDevicePath(tc.devicePath, tc.volumeID, tc.partition) + if tc.expectError != "" { + assert.EqualError(t, err, tc.expectError) + } else { + assert.Equal(t, tc.expectDevicePath, devicePath) + assert.NoError(t, err) + } + }) + } +} + +type fakeFileInfo struct { + name string + mode os.FileMode +} + +func (fi *fakeFileInfo) Name() string { + return fi.name +} + +func (fi *fakeFileInfo) Size() int64 { + return 0 +} + +func (fi *fakeFileInfo) Mode() os.FileMode { + return fi.mode +} + +func (fi *fakeFileInfo) ModTime() time.Time { + return time.Now() +} + +func (fi *fakeFileInfo) IsDir() bool { + return false +} + +func (fi *fakeFileInfo) Sys() interface{} { + return nil +} diff --git a/pkg/driver/node_test.go b/pkg/driver/node_test.go index c7273a6aa8..e075b966b3 100644 --- a/pkg/driver/node_test.go +++ b/pkg/driver/node_test.go @@ -19,6 +19,7 @@ package driver import ( "context" "errors" + "io/fs" "os" "reflect" "strings" @@ -33,12 +34,19 @@ import ( "google.golang.org/grpc/status" ) +var ( + volumeID = "voltest" + nvmeName = "/dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_voltest" + symlinkFileInfo = fs.FileInfo(&fakeFileInfo{nvmeName, os.ModeSymlink}) +) + func TestNodeStageVolume(t *testing.T) { var ( - targetPath = "/test/path" - devicePath = "/dev/fake" - stdVolCap = &csi.VolumeCapability{ + targetPath = "/test/path" + devicePath = "/dev/fake" + nvmeDevicePath = "/dev/fakenvme1n1" + stdVolCap = &csi.VolumeCapability{ AccessType: &csi.VolumeCapability_Mount{ Mount: &csi.VolumeCapability_MountVolume{ FsType: FSTypeExt4, @@ -50,12 +58,24 @@ func TestNodeStageVolume(t *testing.T) { } stdVolContext = map[string]string{VolumeAttributePartition: "1"} devicePathWithPartition = devicePath + "1" + // With few exceptions, all "success" non-block cases have roughly the same + // expected calls and only care about testing the FormatAndMount call. The + // exceptions should not call this, instead they should define expectMock + // from scratch. + successExpectMock = func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) { + mockMounter.EXPECT().PathExists(gomock.Eq(targetPath)).Return(false, nil) + mockMounter.EXPECT().MakeDir(targetPath).Return(nil) + mockMounter.EXPECT().GetDeviceNameFromMount(targetPath).Return("", 1, nil) + mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(true, nil) + mockDeviceIdentifier.EXPECT().Lstat(gomock.Eq(nvmeName)).Return(nil, os.ErrNotExist) + mockMounter.EXPECT().NeedResize(gomock.Eq(devicePath), gomock.Eq(targetPath)).Return(false, nil) + } ) testCases := []struct { name string request *csi.NodeStageVolumeRequest inFlightFunc func(*internal.InFlight) *internal.InFlight - expectMock func(mockMounter MockMounter) + expectMock func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) expectedCode codes.Code }{ { @@ -64,17 +84,11 @@ func TestNodeStageVolume(t *testing.T) { PublishContext: map[string]string{DevicePathKey: devicePath}, StagingTargetPath: targetPath, VolumeCapability: stdVolCap, - VolumeId: "vol-test", + VolumeId: volumeID, }, - expectMock: func(mockMounter MockMounter) { - gomock.InOrder( - mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(true, nil), - mockMounter.EXPECT().PathExists(gomock.Eq(targetPath)).Return(false, nil), - ) - mockMounter.EXPECT().MakeDir(targetPath).Return(nil) - mockMounter.EXPECT().GetDeviceNameFromMount(targetPath).Return("", 1, nil) + expectMock: func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) { + successExpectMock(mockMounter, mockDeviceIdentifier) mockMounter.EXPECT().FormatAndMount(gomock.Eq(devicePath), gomock.Eq(targetPath), gomock.Eq(defaultFsType), gomock.Any()) - mockMounter.EXPECT().NeedResize(gomock.Eq(devicePath), gomock.Eq(targetPath)).Return(false, nil) }, }, { @@ -90,9 +104,9 @@ func TestNodeStageVolume(t *testing.T) { Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - VolumeId: "vol-test", + VolumeId: volumeID, }, - expectMock: func(mockMounter MockMounter) { + expectMock: func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) { mockMounter.EXPECT().FormatAndMount(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(0) }, }, @@ -111,18 +125,11 @@ func TestNodeStageVolume(t *testing.T) { Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - VolumeId: "vol-test", + VolumeId: volumeID, }, - expectMock: func(mockMounter MockMounter) { - gomock.InOrder( - mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(true, nil), - mockMounter.EXPECT().PathExists(gomock.Eq(targetPath)).Return(false, nil), - ) - - mockMounter.EXPECT().MakeDir(targetPath).Return(nil) - mockMounter.EXPECT().GetDeviceNameFromMount(targetPath).Return("", 1, nil) + expectMock: func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) { + successExpectMock(mockMounter, mockDeviceIdentifier) mockMounter.EXPECT().FormatAndMount(gomock.Eq(devicePath), gomock.Eq(targetPath), gomock.Eq(FSTypeExt4), gomock.Eq([]string{"dirsync", "noexec"})) - mockMounter.EXPECT().NeedResize(gomock.Eq(devicePath), gomock.Eq(targetPath)).Return(false, nil) }, }, { @@ -140,18 +147,11 @@ func TestNodeStageVolume(t *testing.T) { Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - VolumeId: "vol-test", + VolumeId: volumeID, }, - expectMock: func(mockMounter MockMounter) { - gomock.InOrder( - mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(true, nil), - mockMounter.EXPECT().PathExists(gomock.Eq(targetPath)).Return(false, nil), - ) - - mockMounter.EXPECT().MakeDir(targetPath).Return(nil) - mockMounter.EXPECT().GetDeviceNameFromMount(targetPath).Return("", 1, nil) + expectMock: func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) { + successExpectMock(mockMounter, mockDeviceIdentifier) mockMounter.EXPECT().FormatAndMount(gomock.Eq(devicePath), gomock.Eq(targetPath), gomock.Eq(FSTypeExt3), gomock.Any()) - mockMounter.EXPECT().NeedResize(gomock.Eq(devicePath), gomock.Eq(targetPath)).Return(false, nil) }, }, { @@ -169,18 +169,90 @@ func TestNodeStageVolume(t *testing.T) { Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - VolumeId: "vol-test", + VolumeId: volumeID, }, - expectMock: func(mockMounter MockMounter) { - gomock.InOrder( - mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(true, nil), - mockMounter.EXPECT().PathExists(gomock.Eq(targetPath)).Return(false, nil), - ) + expectMock: func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) { + successExpectMock(mockMounter, mockDeviceIdentifier) + mockMounter.EXPECT().FormatAndMount(gomock.Eq(devicePath), gomock.Eq(targetPath), gomock.Eq(FSTypeExt4), gomock.Any()) + }, + }, + { + name: "success device already mounted at target", + request: &csi.NodeStageVolumeRequest{ + PublishContext: map[string]string{DevicePathKey: devicePath}, + StagingTargetPath: targetPath, + VolumeCapability: stdVolCap, + VolumeId: volumeID, + }, + expectMock: func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) { + mockMounter.EXPECT().PathExists(gomock.Eq(targetPath)).Return(true, nil) + mockMounter.EXPECT().GetDeviceNameFromMount(targetPath).Return(devicePath, 1, nil) + mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(true, nil) + mockDeviceIdentifier.EXPECT().Lstat(gomock.Eq(nvmeName)).Return(nil, os.ErrNotExist) + + mockMounter.EXPECT().FormatAndMount(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(0) + }, + }, + { + name: "success nvme device already mounted at target", + request: &csi.NodeStageVolumeRequest{ + PublishContext: map[string]string{DevicePathKey: devicePath}, + StagingTargetPath: targetPath, + VolumeCapability: stdVolCap, + VolumeId: volumeID, + }, + expectMock: func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) { + mockMounter.EXPECT().PathExists(gomock.Eq(targetPath)).Return(true, nil) + + // If the device is nvme GetDeviceNameFromMount should return the + // canonical device path + mockMounter.EXPECT().GetDeviceNameFromMount(targetPath).Return(nvmeDevicePath, 1, nil) + // The publish context device path may not exist but the driver should + // find the canonical device path (see TestFindDevicePath), compare it + // to the one returned by GetDeviceNameFromMount, and then skip + // FormatAndMount + mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(false, nil) + mockDeviceIdentifier.EXPECT().Lstat(gomock.Eq(nvmeName)).Return(symlinkFileInfo, nil) + mockDeviceIdentifier.EXPECT().EvalSymlinks(gomock.Eq(symlinkFileInfo.Name())).Return(nvmeDevicePath, nil) + + mockMounter.EXPECT().FormatAndMount(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(0) + }, + }, + { + name: "success with partition", + request: &csi.NodeStageVolumeRequest{ + PublishContext: map[string]string{DevicePathKey: devicePath}, + StagingTargetPath: targetPath, + VolumeCapability: stdVolCap, + VolumeContext: stdVolContext, + VolumeId: volumeID, + }, + expectMock: func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) { + mockMounter.EXPECT().PathExists(gomock.Eq(targetPath)).Return(false, nil) mockMounter.EXPECT().MakeDir(targetPath).Return(nil) mockMounter.EXPECT().GetDeviceNameFromMount(targetPath).Return("", 1, nil) - mockMounter.EXPECT().FormatAndMount(gomock.Eq(devicePath), gomock.Eq(targetPath), gomock.Eq(FSTypeExt4), gomock.Any()) - mockMounter.EXPECT().NeedResize(gomock.Eq(devicePath), gomock.Eq(targetPath)).Return(false, nil) + mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(true, nil) + mockDeviceIdentifier.EXPECT().Lstat(gomock.Eq(nvmeName)).Return(nil, os.ErrNotExist) + + // The device path argument should be canonicalized to contain the + // partition + mockMounter.EXPECT().NeedResize(gomock.Eq(devicePathWithPartition), gomock.Eq(targetPath)).Return(false, nil) + mockMounter.EXPECT().FormatAndMount(gomock.Eq(devicePathWithPartition), gomock.Eq(targetPath), gomock.Eq(defaultFsType), gomock.Any()) + }, + }, + { + name: "success with invalid partition config, will ignore partition", + request: &csi.NodeStageVolumeRequest{ + PublishContext: map[string]string{DevicePathKey: devicePath}, + StagingTargetPath: targetPath, + VolumeCapability: stdVolCap, + VolumeContext: map[string]string{VolumeAttributePartition: "0"}, + VolumeId: volumeID, + }, + expectMock: func(mockMounter MockMounter, mockDeviceIdentifier MockDeviceIdentifier) { + successExpectMock(mockMounter, mockDeviceIdentifier) + mockMounter.EXPECT().FormatAndMount(gomock.Eq(devicePath), gomock.Eq(targetPath), gomock.Eq(defaultFsType), gomock.Any()) }, }, { @@ -211,7 +283,7 @@ func TestNodeStageVolume(t *testing.T) { request: &csi.NodeStageVolumeRequest{ PublishContext: map[string]string{DevicePathKey: devicePath}, VolumeCapability: stdVolCap, - VolumeId: "vol-test", + VolumeId: volumeID, }, expectedCode: codes.InvalidArgument, }, @@ -220,7 +292,7 @@ func TestNodeStageVolume(t *testing.T) { request: &csi.NodeStageVolumeRequest{ PublishContext: map[string]string{DevicePathKey: devicePath}, StagingTargetPath: targetPath, - VolumeId: "vol-test", + VolumeId: volumeID, }, expectedCode: codes.InvalidArgument, }, @@ -234,16 +306,15 @@ func TestNodeStageVolume(t *testing.T) { Mode: csi.VolumeCapability_AccessMode_UNKNOWN, }, }, - VolumeId: "vol-test", + VolumeId: volumeID, }, expectedCode: codes.InvalidArgument, }, { name: "fail no devicePath", request: &csi.NodeStageVolumeRequest{ - StagingTargetPath: targetPath, - VolumeCapability: stdVolCap, - VolumeId: "vol-test", + VolumeCapability: stdVolCap, + VolumeId: volumeID, }, expectedCode: codes.InvalidArgument, }, @@ -254,79 +325,20 @@ func TestNodeStageVolume(t *testing.T) { StagingTargetPath: targetPath, VolumeCapability: stdVolCap, VolumeContext: map[string]string{VolumeAttributePartition: "partition1"}, - VolumeId: "vol-test", + VolumeId: volumeID, }, expectedCode: codes.InvalidArgument, }, - { - name: "success device already mounted at target", - request: &csi.NodeStageVolumeRequest{ - PublishContext: map[string]string{DevicePathKey: devicePath}, - StagingTargetPath: targetPath, - VolumeCapability: stdVolCap, - VolumeId: "vol-test", - }, - expectMock: func(mockMounter MockMounter) { - gomock.InOrder( - mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(true, nil), - mockMounter.EXPECT().PathExists(gomock.Eq(targetPath)).Return(false, nil), - ) - - mockMounter.EXPECT().MakeDir(targetPath).Return(nil) - mockMounter.EXPECT().GetDeviceNameFromMount(targetPath).Return(devicePath, 1, nil) - mockMounter.EXPECT().FormatAndMount(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(0) - }, - }, - { - name: "success with partition", - request: &csi.NodeStageVolumeRequest{ - PublishContext: map[string]string{DevicePathKey: devicePath}, - StagingTargetPath: targetPath, - VolumeCapability: stdVolCap, - VolumeContext: stdVolContext, - VolumeId: "vol-test", - }, - expectMock: func(mockMounter MockMounter) { - gomock.InOrder( - mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(true, nil), - mockMounter.EXPECT().PathExists(gomock.Eq(targetPath)).Return(false, nil), - ) - mockMounter.EXPECT().MakeDir(targetPath).Return(nil) - mockMounter.EXPECT().GetDeviceNameFromMount(targetPath).Return("", 1, nil) - mockMounter.EXPECT().FormatAndMount(gomock.Eq(devicePathWithPartition), gomock.Eq(targetPath), gomock.Eq(defaultFsType), gomock.Any()) - mockMounter.EXPECT().NeedResize(gomock.Eq(devicePathWithPartition), gomock.Eq(targetPath)).Return(false, nil) - }, - }, - { - name: "success with invalid partition config, will ignore partition", - request: &csi.NodeStageVolumeRequest{ - PublishContext: map[string]string{DevicePathKey: devicePath}, - StagingTargetPath: targetPath, - VolumeCapability: stdVolCap, - VolumeContext: map[string]string{VolumeAttributePartition: "0"}, - VolumeId: "vol-test", - }, - expectMock: func(mockMounter MockMounter) { - gomock.InOrder( - mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(true, nil), - mockMounter.EXPECT().PathExists(gomock.Eq(targetPath)).Return(false, nil), - ) - mockMounter.EXPECT().MakeDir(targetPath).Return(nil) - mockMounter.EXPECT().GetDeviceNameFromMount(targetPath).Return("", 1, nil) - mockMounter.EXPECT().FormatAndMount(gomock.Eq(devicePath), gomock.Eq(targetPath), gomock.Eq(defaultFsType), gomock.Any()) - mockMounter.EXPECT().NeedResize(gomock.Eq(devicePath), gomock.Eq(targetPath)).Return(false, nil) - }, - }, { name: "fail with in-flight request", request: &csi.NodeStageVolumeRequest{ PublishContext: map[string]string{DevicePathKey: devicePath}, StagingTargetPath: targetPath, VolumeCapability: stdVolCap, - VolumeId: "vol-test", + VolumeId: volumeID, }, inFlightFunc: func(inFlight *internal.InFlight) *internal.InFlight { - inFlight.Insert("vol-test") + inFlight.Insert(volumeID) return inFlight }, expectedCode: codes.Aborted, @@ -340,6 +352,7 @@ func TestNodeStageVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) inFlight := internal.NewInFlight() if tc.inFlightFunc != nil { @@ -347,13 +360,14 @@ func TestNodeStageVolume(t *testing.T) { } awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: inFlight, + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: inFlight, } if tc.expectMock != nil { - tc.expectMock(*mockMounter) + tc.expectMock(*mockMounter, *mockDeviceIdentifier) } _, err := awsDriver.NodeStageVolume(context.TODO(), tc.request) @@ -382,11 +396,13 @@ func TestNodeUnstageVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } mockMounter.EXPECT().GetDeviceNameFromMount(gomock.Eq(targetPath)).Return(devicePath, 1, nil) @@ -394,7 +410,7 @@ func TestNodeUnstageVolume(t *testing.T) { req := &csi.NodeUnstageVolumeRequest{ StagingTargetPath: targetPath, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodeUnstageVolume(context.TODO(), req) @@ -411,18 +427,20 @@ func TestNodeUnstageVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } mockMounter.EXPECT().GetDeviceNameFromMount(gomock.Eq(targetPath)).Return(devicePath, 0, nil) req := &csi.NodeUnstageVolumeRequest{ StagingTargetPath: targetPath, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodeUnstageVolume(context.TODO(), req) if err != nil { @@ -438,11 +456,13 @@ func TestNodeUnstageVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } mockMounter.EXPECT().GetDeviceNameFromMount(gomock.Eq(targetPath)).Return(devicePath, 2, nil) @@ -450,7 +470,7 @@ func TestNodeUnstageVolume(t *testing.T) { req := &csi.NodeUnstageVolumeRequest{ StagingTargetPath: targetPath, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodeUnstageVolume(context.TODO(), req) @@ -467,11 +487,13 @@ func TestNodeUnstageVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodeUnstageVolumeRequest{ @@ -490,15 +512,17 @@ func TestNodeUnstageVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodeUnstageVolumeRequest{ - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodeUnstageVolume(context.TODO(), req) expectErr(t, err, codes.InvalidArgument) @@ -512,18 +536,20 @@ func TestNodeUnstageVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } mockMounter.EXPECT().GetDeviceNameFromMount(gomock.Eq(targetPath)).Return("", 0, errors.New("GetDeviceName faield")) req := &csi.NodeUnstageVolumeRequest{ StagingTargetPath: targetPath, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodeUnstageVolume(context.TODO(), req) @@ -538,19 +564,21 @@ func TestNodeUnstageVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodeUnstageVolumeRequest{ StagingTargetPath: targetPath, - VolumeId: "vol-test", + VolumeId: volumeID, } - awsDriver.inFlight.Insert("vol-test") + awsDriver.inFlight.Insert(volumeID) _, err := awsDriver.NodeUnstageVolume(context.TODO(), req) expectErr(t, err, codes.Aborted) }, @@ -588,11 +616,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } mockMounter.EXPECT().MakeDir(gomock.Eq(targetPath)).Return(nil) @@ -604,7 +634,7 @@ func TestNodePublishVolume(t *testing.T) { StagingTargetPath: stagingTargetPath, TargetPath: targetPath, VolumeCapability: stdVolCap, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -621,11 +651,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } mockMounter.EXPECT().MakeDir(gomock.Eq(targetPath)).Return(nil) @@ -636,7 +668,7 @@ func TestNodePublishVolume(t *testing.T) { StagingTargetPath: stagingTargetPath, TargetPath: targetPath, VolumeCapability: stdVolCap, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -653,11 +685,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } gomock.InOrder( @@ -671,7 +705,7 @@ func TestNodePublishVolume(t *testing.T) { StagingTargetPath: stagingTargetPath, TargetPath: targetPath, VolumeCapability: stdVolCap, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -686,11 +720,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } mockMounter.EXPECT().PathExists(gomock.Eq(targetPath)).Return(true, errors.New("CorruptedMntError")) @@ -706,7 +742,7 @@ func TestNodePublishVolume(t *testing.T) { StagingTargetPath: stagingTargetPath, TargetPath: targetPath, VolumeCapability: stdVolCap, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -723,11 +759,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } mockMounter.EXPECT().MakeDir(gomock.Eq(targetPath)).Return(nil) @@ -748,7 +786,7 @@ func TestNodePublishVolume(t *testing.T) { Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -765,11 +803,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } mockMounter.EXPECT().MakeDir(gomock.Eq(targetPath)).Return(nil) @@ -782,7 +822,7 @@ func TestNodePublishVolume(t *testing.T) { StagingTargetPath: stagingTargetPath, TargetPath: targetPath, VolumeCapability: stdVolCap, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -799,11 +839,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } mockMounter.EXPECT().MakeDir(gomock.Eq(targetPath)).Return(nil) @@ -828,7 +870,7 @@ func TestNodePublishVolume(t *testing.T) { Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -845,11 +887,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } gomock.InOrder( @@ -860,6 +904,7 @@ func TestNodePublishVolume(t *testing.T) { mockMounter.EXPECT().MakeFile(targetPath).Return(nil) mockMounter.EXPECT().Mount(gomock.Eq(devicePath), gomock.Eq(targetPath), gomock.Eq(""), gomock.Eq([]string{"bind"})).Return(nil) mockMounter.EXPECT().IsLikelyNotMountPoint(gomock.Eq(targetPath)).Return(true, nil) + mockDeviceIdentifier.EXPECT().Lstat(gomock.Eq(nvmeName)).Return(nil, os.ErrNotExist) req := &csi.NodePublishVolumeRequest{ PublishContext: map[string]string{DevicePathKey: "/dev/fake"}, @@ -873,7 +918,7 @@ func TestNodePublishVolume(t *testing.T) { Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -890,11 +935,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } gomock.InOrder( @@ -904,6 +951,7 @@ func TestNodePublishVolume(t *testing.T) { mockMounter.EXPECT().MakeDir(gomock.Eq("/test")).Return(nil) mockMounter.EXPECT().MakeFile(targetPath).Return(nil) mockMounter.EXPECT().IsLikelyNotMountPoint(gomock.Eq(targetPath)).Return(false, nil) + mockDeviceIdentifier.EXPECT().Lstat(gomock.Eq(nvmeName)).Return(nil, os.ErrNotExist) req := &csi.NodePublishVolumeRequest{ PublishContext: map[string]string{DevicePathKey: "/dev/fake"}, @@ -917,7 +965,7 @@ func TestNodePublishVolume(t *testing.T) { Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -934,11 +982,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } gomock.InOrder( @@ -950,6 +1000,7 @@ func TestNodePublishVolume(t *testing.T) { mockMounter.EXPECT().MakeDir(gomock.Eq("/test")).Return(nil) mockMounter.EXPECT().MakeFile(targetPath).Return(nil) mockMounter.EXPECT().IsLikelyNotMountPoint(gomock.Eq(targetPath)).Return(true, errors.New("Internal System Error")) + mockDeviceIdentifier.EXPECT().Lstat(gomock.Eq(nvmeName)).Return(nil, os.ErrNotExist) req := &csi.NodePublishVolumeRequest{ PublishContext: map[string]string{DevicePathKey: "/dev/fake"}, @@ -963,7 +1014,7 @@ func TestNodePublishVolume(t *testing.T) { Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -978,11 +1029,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } gomock.InOrder( @@ -998,6 +1051,7 @@ func TestNodePublishVolume(t *testing.T) { mockMounter.EXPECT().Unmount(gomock.Eq(targetPath)).Return(nil) mockMounter.EXPECT().IsLikelyNotMountPoint(gomock.Eq(targetPath)).Return(true, errors.New("Internal System Error")) mockMounter.EXPECT().Mount(gomock.Eq(devicePath), gomock.Eq(targetPath), gomock.Any(), gomock.Any()).Return(nil) + mockDeviceIdentifier.EXPECT().Lstat(gomock.Eq(nvmeName)).Return(nil, os.ErrNotExist) req := &csi.NodePublishVolumeRequest{ PublishContext: map[string]string{DevicePathKey: "/dev/fake"}, @@ -1011,7 +1065,7 @@ func TestNodePublishVolume(t *testing.T) { Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -1028,11 +1082,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } gomock.InOrder( @@ -1043,6 +1099,7 @@ func TestNodePublishVolume(t *testing.T) { mockMounter.EXPECT().MakeFile(targetPath).Return(nil) mockMounter.EXPECT().Mount(gomock.Eq(devicePathWithPartition), gomock.Eq(targetPath), gomock.Eq(""), gomock.Eq([]string{"bind"})).Return(nil) mockMounter.EXPECT().IsLikelyNotMountPoint(gomock.Eq(targetPath)).Return(true, nil) + mockDeviceIdentifier.EXPECT().Lstat(gomock.Eq(nvmeName)).Return(nil, os.ErrNotExist) req := &csi.NodePublishVolumeRequest{ PublishContext: map[string]string{DevicePathKey: "/dev/fake"}, @@ -1057,7 +1114,7 @@ func TestNodePublishVolume(t *testing.T) { }, }, VolumeContext: stdVolContext, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -1074,11 +1131,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } gomock.InOrder( @@ -1089,6 +1148,7 @@ func TestNodePublishVolume(t *testing.T) { mockMounter.EXPECT().MakeFile(targetPath).Return(nil) mockMounter.EXPECT().Mount(gomock.Eq(devicePath), gomock.Eq(targetPath), gomock.Eq(""), gomock.Eq([]string{"bind"})).Return(nil) mockMounter.EXPECT().IsLikelyNotMountPoint(gomock.Eq(targetPath)).Return(true, nil) + mockDeviceIdentifier.EXPECT().Lstat(gomock.Eq(nvmeName)).Return(nil, os.ErrNotExist) req := &csi.NodePublishVolumeRequest{ PublishContext: map[string]string{DevicePathKey: "/dev/fake"}, @@ -1103,7 +1163,7 @@ func TestNodePublishVolume(t *testing.T) { }, }, VolumeContext: map[string]string{VolumeAttributePartition: "0"}, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -1120,11 +1180,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodePublishVolumeRequest{ @@ -1140,7 +1202,7 @@ func TestNodePublishVolume(t *testing.T) { }, }, VolumeContext: map[string]string{VolumeAttributePartition: "partition1"}, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -1155,11 +1217,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodePublishVolumeRequest{ @@ -1173,7 +1237,7 @@ func TestNodePublishVolume(t *testing.T) { Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -1189,11 +1253,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodePublishVolumeRequest{ @@ -1208,7 +1274,7 @@ func TestNodePublishVolume(t *testing.T) { Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, }, }, - VolumeId: "vol-test", + VolumeId: volumeID, } mockMounter.EXPECT().PathExists(gomock.Eq(devicePath)).Return(false, errors.New("findDevicePath failed")) @@ -1226,11 +1292,13 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodePublishVolumeRequest{ @@ -1253,18 +1321,20 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodePublishVolumeRequest{ PublishContext: map[string]string{DevicePathKey: devicePath}, TargetPath: targetPath, VolumeCapability: stdVolCap, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -1280,18 +1350,20 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodePublishVolumeRequest{ PublishContext: map[string]string{DevicePathKey: devicePath}, StagingTargetPath: stagingTargetPath, VolumeCapability: stdVolCap, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) @@ -1307,18 +1379,20 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodePublishVolumeRequest{ PublishContext: map[string]string{DevicePathKey: devicePath}, StagingTargetPath: stagingTargetPath, TargetPath: targetPath, - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodePublishVolume(context.TODO(), req) expectErr(t, err, codes.InvalidArgument) @@ -1333,18 +1407,20 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodePublishVolumeRequest{ PublishContext: map[string]string{DevicePathKey: "/dev/fake"}, StagingTargetPath: "/test/staging/path", TargetPath: "/test/target/path", - VolumeId: "vol-test", + VolumeId: volumeID, VolumeCapability: &csi.VolumeCapability{ AccessMode: &csi.VolumeCapability_AccessMode{ Mode: csi.VolumeCapability_AccessMode_UNKNOWN, @@ -1365,18 +1441,20 @@ func TestNodePublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodePublishVolumeRequest{ PublishContext: map[string]string{DevicePathKey: "/dev/fake"}, StagingTargetPath: "/test/staging/path", TargetPath: "/test/target/path", - VolumeId: "vol-test", + VolumeId: volumeID, VolumeCapability: &csi.VolumeCapability{ AccessType: &csi.VolumeCapability_Block{ Block: &csi.VolumeCapability_BlockVolume{}, @@ -1386,7 +1464,7 @@ func TestNodePublishVolume(t *testing.T) { }, }, } - awsDriver.inFlight.Insert("vol-test") + awsDriver.inFlight.Insert(volumeID) _, err := awsDriver.NodePublishVolume(context.TODO(), req) expectErr(t, err, codes.Aborted) @@ -1405,11 +1483,13 @@ func TestNodeExpandVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } tests := []struct { @@ -1501,16 +1581,18 @@ func TestNodeUnpublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodeUnpublishVolumeRequest{ TargetPath: targetPath, - VolumeId: "vol-test", + VolumeId: volumeID, } mockMounter.EXPECT().Unmount(gomock.Eq(targetPath)).Return(nil) @@ -1528,11 +1610,13 @@ func TestNodeUnpublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodeUnpublishVolumeRequest{ @@ -1551,15 +1635,17 @@ func TestNodeUnpublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodeUnpublishVolumeRequest{ - VolumeId: "vol-test", + VolumeId: volumeID, } _, err := awsDriver.NodeUnpublishVolume(context.TODO(), req) @@ -1574,16 +1660,18 @@ func TestNodeUnpublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodeUnpublishVolumeRequest{ TargetPath: targetPath, - VolumeId: "vol-test", + VolumeId: volumeID, } mockMounter.EXPECT().Unmount(gomock.Eq(targetPath)).Return(errors.New("test Unmount error")) @@ -1599,19 +1687,21 @@ func TestNodeUnpublishVolume(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodeUnpublishVolumeRequest{ TargetPath: targetPath, - VolumeId: "vol-test", + VolumeId: volumeID, } - awsDriver.inFlight.Insert("vol-test") + awsDriver.inFlight.Insert(volumeID) _, err := awsDriver.NodeUnpublishVolume(context.TODO(), req) expectErr(t, err, codes.Aborted) }, @@ -1636,6 +1726,7 @@ func TestNodeGetVolumeStats(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) VolumePath := "./test" err := os.MkdirAll(VolumePath, 0644) if err != nil { @@ -1646,13 +1737,14 @@ func TestNodeGetVolumeStats(t *testing.T) { mockMounter.EXPECT().PathExists(VolumePath).Return(true, nil) awsDriver := nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodeGetVolumeStatsRequest{ - VolumeId: "vol-test", + VolumeId: volumeID, VolumePath: VolumePath, } _, err = awsDriver.NodeGetVolumeStats(context.TODO(), req) @@ -1669,18 +1761,20 @@ func TestNodeGetVolumeStats(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) VolumePath := "/test" mockMounter.EXPECT().PathExists(VolumePath).Return(false, nil) awsDriver := nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodeGetVolumeStatsRequest{ - VolumeId: "vol-test", + VolumeId: volumeID, VolumePath: VolumePath, } _, err := awsDriver.NodeGetVolumeStats(context.TODO(), req) @@ -1695,18 +1789,20 @@ func TestNodeGetVolumeStats(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) VolumePath := "/test" mockMounter.EXPECT().PathExists(VolumePath).Return(true, nil) awsDriver := nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodeGetVolumeStatsRequest{ - VolumeId: "vol-test", + VolumeId: volumeID, VolumePath: VolumePath, } _, err := awsDriver.NodeGetVolumeStats(context.TODO(), req) @@ -1721,18 +1817,20 @@ func TestNodeGetVolumeStats(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) VolumePath := "/test" mockMounter.EXPECT().PathExists(VolumePath).Return(false, errors.New("get existsPath call fail")) awsDriver := nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } req := &csi.NodeGetVolumeStatsRequest{ - VolumeId: "vol-test", + VolumeId: volumeID, VolumePath: VolumePath, } _, err := awsDriver.NodeGetVolumeStats(context.TODO(), req) @@ -1753,11 +1851,13 @@ func TestNodeGetCapabilities(t *testing.T) { mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) awsDriver := nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), } caps := []*csi.NodeServiceCapability{ @@ -1867,6 +1967,7 @@ func TestNodeGetInfo(t *testing.T) { } mockMounter := NewMockMounter(mockCtl) + mockDeviceIdentifier := NewMockDeviceIdentifier(mockCtl) mockMetadata := cloud.NewMockMetadataService(mockCtl) mockMetadata.EXPECT().GetInstanceID().Return(tc.instanceID) @@ -1878,10 +1979,11 @@ func TestNodeGetInfo(t *testing.T) { } awsDriver := &nodeService{ - metadata: mockMetadata, - mounter: mockMounter, - inFlight: internal.NewInFlight(), - driverOptions: driverOptions, + metadata: mockMetadata, + mounter: mockMounter, + deviceIdentifier: mockDeviceIdentifier, + inFlight: internal.NewInFlight(), + driverOptions: driverOptions, } resp, err := awsDriver.NodeGetInfo(context.TODO(), &csi.NodeGetInfoRequest{}) diff --git a/pkg/driver/node_windows.go b/pkg/driver/node_windows.go index 533fd4e36e..dca292eda9 100644 --- a/pkg/driver/node_windows.go +++ b/pkg/driver/node_windows.go @@ -35,7 +35,6 @@ import ( // findDevicePath finds disk number of device // https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-windows-volumes.html#list-nvme-powershell func (d *nodeService) findDevicePath(devicePath, volumeID, _ string) (string, error) { - diskClient, err := diskclient.NewClient() if err != nil { return "", fmt.Errorf("error creating csi-proxy disk client: %q", err) diff --git a/pkg/driver/sanity_test.go b/pkg/driver/sanity_test.go index 35c15578eb..ce661d7b24 100644 --- a/pkg/driver/sanity_test.go +++ b/pkg/driver/sanity_test.go @@ -57,9 +57,10 @@ func TestSanity(t *testing.T) { Region: "region", AvailabilityZone: "az", }, - mounter: newFakeMounter(), - inFlight: internal.NewInFlight(), - driverOptions: &DriverOptions{}, + mounter: newFakeMounter(), + deviceIdentifier: newNodeDeviceIdentifier(), + inFlight: internal.NewInFlight(), + driverOptions: &DriverOptions{}, }, } defer func() {