Skip to content

Commit 9d1f864

Browse files
committed
sanity test
1 parent aeb7008 commit 9d1f864

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

pkg/cloud/fakes.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,14 @@ func (c *FakeCloudProvider) ResizeFileSystem(ctx context.Context, fileSystemId s
114114
}
115115

116116
func (c *FakeCloudProvider) DeleteFileSystem(ctx context.Context, parameters map[string]string) error {
117+
// parameters["FileSystemId"] in Sanity test is JSON string, eg: "\"fs-1234\""
118+
// While actual id is "fs-1234"
119+
// For backward compatibility, we can remove both the JSON string and the unquote string
120+
unquoteId := strings.Trim(parameters["FileSystemId"], "\"")
117121
delete(c.fileSystems, parameters["FileSystemId"])
122+
delete(c.fileSystems, unquoteId)
118123
delete(c.fileSystemsParameters, parameters["FileSystemId"])
124+
delete(c.fileSystemsParameters, unquoteId)
119125
return nil
120126
}
121127

@@ -168,8 +174,14 @@ func (c *FakeCloudProvider) CreateVolume(ctx context.Context, parameters map[str
168174
}
169175

170176
func (c *FakeCloudProvider) DeleteVolume(ctx context.Context, parameters map[string]string) (err error) {
177+
// parameters["VolumeId"] in Sanity test is JSON string, eg: "\"fsvol-1234\""
178+
// While actual id is "fsvol-1234"
179+
// For backward compatibility, we can remove both the JSON string and the unquote string
180+
unquoteId := strings.Trim(parameters["VolumeId"], "\"")
171181
delete(c.volumes, parameters["VolumeId"])
182+
delete(c.volumes, unquoteId)
172183
delete(c.volumesParameters, parameters["VolumeId"])
184+
delete(c.volumesParameters, unquoteId)
173185
return nil
174186
}
175187

pkg/driver/controller.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,18 +364,20 @@ func (d *controllerService) DeleteVolume(ctx context.Context, req *csi.DeleteVol
364364
describeRetry := func() error {
365365
if splitVolumeId[0] == cloud.FilesystemPrefix {
366366
_, err = d.cloud.DescribeFileSystem(ctx, volumeID)
367-
}
368-
if splitVolumeId[0] == cloud.VolumePrefix {
367+
} else if splitVolumeId[0] == cloud.VolumePrefix {
369368
_, err = d.cloud.DescribeVolume(ctx, volumeID)
369+
} else {
370+
// Invalid volume ID, return not found immediately
371+
return nil
370372
}
371373

372374
if err != nil {
373375
if err == cloud.ErrNotFound {
374376
return nil
375377
}
376-
return status.Error(codes.Internal, err.Error())
378+
return err
377379
}
378-
return status.Errorf(codes.Internal, "Volume ID %q still exists", volumeID)
380+
return fmt.Errorf("volume ID %q still exists", volumeID)
379381
}
380382

381383
err = backoff.RetryNotify(describeRetry, d.backoff, notifyRetryError)

pkg/driver/controller_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import (
3232
)
3333

3434
const (
35-
backoffMaxRetries = 10
35+
backoffMaxRetries = 10
36+
exceedBackoffMaxRetries = backoffMaxRetries + 1
3637
)
3738

3839
func defaultControllerService(mockCloud *mocks.MockCloud) controllerService {
@@ -1089,7 +1090,7 @@ func TestDeleteVolume(t *testing.T) {
10891090
mockCloud.EXPECT().GetDeleteParameters(gomock.Eq(ctx), gomock.Any()).Return(volumeParameters, nil)
10901091
mockCloud.EXPECT().DeleteFileSystem(gomock.Eq(ctx), gomock.Any()).Return(nil)
10911092

1092-
for i := 0; i < backoffMaxRetries+1; i++ {
1093+
for i := 0; i < exceedBackoffMaxRetries; i++ {
10931094
mockCloud.EXPECT().DescribeFileSystem(gomock.Eq(ctx), gomock.Any()).Return(&cloud.FileSystem{}, nil)
10941095
}
10951096

@@ -1199,7 +1200,7 @@ func TestDeleteVolume(t *testing.T) {
11991200
mockCloud.EXPECT().GetDeleteParameters(gomock.Eq(ctx), gomock.Any()).Return(volumeParameters, nil)
12001201
mockCloud.EXPECT().DeleteVolume(gomock.Eq(ctx), gomock.Any()).Return(nil)
12011202

1202-
for i := 0; i < backoffMaxRetries+1; i++ {
1203+
for i := 0; i < exceedBackoffMaxRetries; i++ {
12031204
mockCloud.EXPECT().DescribeVolume(gomock.Eq(ctx), gomock.Any()).Return(&cloud.Volume{}, nil)
12041205
}
12051206

pkg/driver/fakes.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616
package driver
1717

1818
import (
19+
"github.com/cenkalti/backoff/v4"
1920
"github.com/kubernetes-sigs/aws-fsx-openzfs-csi-driver/pkg/cloud"
2021
"github.com/kubernetes-sigs/aws-fsx-openzfs-csi-driver/pkg/driver/internal"
2122
"k8s.io/mount-utils"
@@ -42,6 +43,10 @@ func NewFakeDriver(endpoint string) *Driver {
4243
cloud: cloud.NewFakeCloudProvider(),
4344
inFlight: internal.NewInFlight(),
4445
driverOptions: &driverOptions,
46+
backoff: backoff.WithMaxRetries(
47+
backoff.NewExponentialBackOff(),
48+
3,
49+
),
4550
},
4651
nodeService: nodeService{
4752
metadata: &cloud.Metadata{

0 commit comments

Comments
 (0)