-
Notifications
You must be signed in to change notification settings - Fork 803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modify error message when request volume is in use with other node #698
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -286,19 +286,21 @@ func (d *controllerService) ControllerPublishVolume(ctx context.Context, req *cs | |
if !d.cloud.IsExistInstance(ctx, nodeID) { | ||
return nil, status.Errorf(codes.NotFound, "Instance %q not found", nodeID) | ||
} | ||
|
||
if _, err := d.cloud.GetDiskByID(ctx, volumeID); err != nil { | ||
disk, err := d.cloud.GetDiskByID(ctx, volumeID) | ||
if err != nil { | ||
if err == cloud.ErrNotFound { | ||
return nil, status.Error(codes.NotFound, "Volume not found") | ||
} | ||
return nil, status.Errorf(codes.Internal, "Could not get volume with ID %q: %v", volumeID, err) | ||
} | ||
|
||
// If given volumeId already assigned to given node, will directly return current device path | ||
devicePath, err := d.cloud.AttachDisk(ctx, volumeID, nodeID) | ||
if err != nil { | ||
if err == cloud.ErrAlreadyExists { | ||
return nil, status.Error(codes.AlreadyExists, err.Error()) | ||
if err == cloud.ErrVolumeInUse { | ||
return nil, status.Error(codes.FailedPrecondition, strings.Join(disk.Attachments, ",")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this is a good point, will update |
||
} | ||
// TODO: Check volume capability matches for ALREADY_EXISTS | ||
return nil, status.Errorf(codes.Internal, "Could not attach volume %q to node %q: %v", volumeID, nodeID, err) | ||
} | ||
klog.V(5).Infof("ControllerPublishVolume: volume %s attached to node %s through device %s", volumeID, nodeID, devicePath) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2669,8 +2669,12 @@ func TestControllerPublishVolume(t *testing.T) { | |
}, | ||
}, | ||
{ | ||
name: "fail attach disk with already exists error", | ||
name: "fail attach disk with volume already in use error", | ||
testFunc: func(t *testing.T) { | ||
attachedInstancId := "test-instance-id-attached" | ||
disk := &cloud.Disk{ | ||
Attachments: []string{attachedInstancId}, | ||
} | ||
req := &csi.ControllerPublishVolumeRequest{ | ||
VolumeId: "does-not-exist", | ||
NodeId: expInstanceID, | ||
|
@@ -2684,8 +2688,8 @@ func TestControllerPublishVolume(t *testing.T) { | |
|
||
mockCloud := mocks.NewMockCloud(mockCtl) | ||
mockCloud.EXPECT().IsExistInstance(gomock.Eq(ctx), gomock.Eq(req.NodeId)).Return(true) | ||
mockCloud.EXPECT().GetDiskByID(gomock.Eq(ctx), gomock.Any()).Return(&cloud.Disk{}, nil) | ||
mockCloud.EXPECT().AttachDisk(gomock.Eq(ctx), gomock.Any(), gomock.Eq(req.NodeId)).Return("", cloud.ErrAlreadyExists) | ||
mockCloud.EXPECT().GetDiskByID(gomock.Eq(ctx), gomock.Any()).Return(disk, nil) | ||
mockCloud.EXPECT().AttachDisk(gomock.Eq(ctx), gomock.Any(), gomock.Eq(req.NodeId)).Return("", cloud.ErrVolumeInUse) | ||
|
||
awsDriver := controllerService{ | ||
cloud: mockCloud, | ||
|
@@ -2697,8 +2701,11 @@ func TestControllerPublishVolume(t *testing.T) { | |
if !ok { | ||
t.Fatalf("Could not get error status code from error: %v", srvErr) | ||
} | ||
if srvErr.Code() != codes.AlreadyExists { | ||
t.Fatalf("Expected error code %d, got %d message %s", codes.AlreadyExists, srvErr.Code(), srvErr.Message()) | ||
if srvErr.Code() != codes.FailedPrecondition { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also check if we're returning the correct instance id in the error message? It's a requirement from the spec. |
||
t.Fatalf("Expected error code %d, got %d message %s", codes.FailedPrecondition, srvErr.Code(), srvErr.Message()) | ||
} | ||
if srvErr.Message() != attachedInstancId { | ||
t.Fatalf("Expected error message to contain previous attached instanceId %s, but get error message %s", attachedInstancId, srvErr.Message()) | ||
} | ||
} else { | ||
t.Fatalf("Expected error %v, got no error", codes.AlreadyExists) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not use this anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I see the TODO below.