Skip to content

Commit 9d644b4

Browse files
committed
fix csi test case and bring back return string
1 parent d85c8a8 commit 9d644b4

6 files changed

Lines changed: 26 additions & 23 deletions

File tree

pkg/csi/blockstorage/controllerserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ func (cs *controllerServer) createSnapshot(ctx context.Context, name, volumeID s
629629
filters["Name"] = name
630630

631631
// List existing snapshots with the same name
632-
snapshots, err := cs.Instance.ListSnapshots(ctx, filters)
632+
snapshots, _, err := cs.Instance.ListSnapshots(ctx, filters)
633633
if err != nil {
634634
klog.Errorf("Failed to query for existing Snapshot during CreateSnapshot: %v", err)
635635
return nil, status.Error(codes.Internal, "Failed to get snapshots")
@@ -792,7 +792,7 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
792792

793793
// Only retrieve snapshots that are available
794794
filters["Status"] = stackitclient.SnapshotReadyStatus
795-
slist, err = cloud.ListSnapshots(ctx, filters)
795+
slist, nextPageToken, err = cloud.ListSnapshots(ctx, filters)
796796
if err != nil {
797797
klog.Errorf("Failed to ListSnapshots: %v", err)
798798
return nil, status.Errorf(codes.Internal, "ListSnapshots failed with error %v", err)

pkg/csi/blockstorage/controllerserver_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ var _ = Describe("ControllerServer test", Ordered, func() {
772772
iaasClient.EXPECT().ListBackups(gomock.Any(), gomock.Any()).Return([]iaas.Backup{}, nil)
773773

774774
// Backups are created from snapshots
775-
iaasClient.EXPECT().ListSnapshots(gomock.Any(), gomock.Any()).Return([]iaas.Snapshot{}, nil)
775+
iaasClient.EXPECT().ListSnapshots(gomock.Any(), gomock.Any()).Return([]iaas.Snapshot{}, "", nil)
776776
iaasClient.EXPECT().CreateSnapshot(gomock.Any(), gomock.Any()).Return(expectedSnap, nil)
777777
iaasClient.EXPECT().WaitSnapshotReady(gomock.Any(), "fake-snapshot").Return(expectedSnap.Status, nil)
778778

@@ -865,7 +865,7 @@ var _ = Describe("ControllerServer test", Ordered, func() {
865865
iaasClient.EXPECT().ListBackups(gomock.Any(), gomock.Any()).Return([]iaas.Backup{}, nil)
866866

867867
// Backups are created from snapshots
868-
iaasClient.EXPECT().ListSnapshots(gomock.Any(), gomock.Any()).Return([]iaas.Snapshot{}, nil)
868+
iaasClient.EXPECT().ListSnapshots(gomock.Any(), gomock.Any()).Return([]iaas.Snapshot{}, "", nil)
869869
iaasClient.EXPECT().CreateSnapshot(gomock.Any(), gomock.Any()).Return(expectedSnap, nil)
870870
iaasClient.EXPECT().WaitSnapshotReady(gomock.Any(), "fake-snapshot").Return(expectedSnap.Status, nil)
871871

@@ -899,7 +899,7 @@ var _ = Describe("ControllerServer test", Ordered, func() {
899899
CreatedAt: new(time.Now()),
900900
}
901901
// TODO: Again filters are not implemented yet by the API
902-
iaasClient.EXPECT().ListSnapshots(gomock.Any(), gomock.Any()).Return([]iaas.Snapshot{}, nil)
902+
iaasClient.EXPECT().ListSnapshots(gomock.Any(), gomock.Any()).Return([]iaas.Snapshot{}, "", nil)
903903
iaasClient.EXPECT().CreateSnapshot(gomock.Any(), gomock.Any()).Return(expectedSnap, nil)
904904
iaasClient.EXPECT().WaitSnapshotReady(gomock.Any(), "fake-snapshot").Return(expectedSnap.Status, nil)
905905
_, err := fakeCs.CreateSnapshot(context.Background(), req)
@@ -916,7 +916,7 @@ var _ = Describe("ControllerServer test", Ordered, func() {
916916
}
917917

918918
// TODO: Again filters are not implemented yet by the API
919-
iaasClient.EXPECT().ListSnapshots(gomock.Any(), gomock.Any()).Return([]iaas.Snapshot{*expectedSnap}, nil)
919+
iaasClient.EXPECT().ListSnapshots(gomock.Any(), gomock.Any()).Return([]iaas.Snapshot{*expectedSnap}, "", nil)
920920
iaasClient.EXPECT().WaitSnapshotReady(gomock.Any(), "fake-snapshot").Return(new("AVAILABLE"), nil)
921921
_, err := fakeCs.CreateSnapshot(context.Background(), req)
922922
Expect(err).ToNot(HaveOccurred())
@@ -930,7 +930,7 @@ var _ = Describe("ControllerServer test", Ordered, func() {
930930
{
931931
Id: new("fake-snapshot2"),
932932
},
933-
}, nil)
933+
}, "", nil)
934934
_, err := fakeCs.CreateSnapshot(context.Background(), req)
935935
Expect(err).To(HaveOccurred())
936936
Expect(status.Convert(err).Code()).To(Equal(codes.Internal))
@@ -943,7 +943,7 @@ var _ = Describe("ControllerServer test", Ordered, func() {
943943
Id: new("fake-snapshot"),
944944
VolumeId: "something-different",
945945
},
946-
}, nil)
946+
}, "", nil)
947947
_, err := fakeCs.CreateSnapshot(context.Background(), req)
948948
Expect(err).To(HaveOccurred())
949949
Expect(status.Convert(err).Code()).To(Equal(codes.AlreadyExists))
@@ -1001,7 +1001,7 @@ var _ = Describe("ControllerServer test", Ordered, func() {
10011001
VolumeId: "something-different",
10021002
Size: new(int64(10)),
10031003
CreatedAt: new(snapShotCreationTime),
1004-
}}, nil)
1004+
}}, "", nil)
10051005
resp, err := fakeCs.ListSnapshots(context.Background(), req)
10061006
Expect(err).To(Not(HaveOccurred()))
10071007
Expect(resp.GetEntries()).Should(Equal(expectedSnapshotListResponse))

pkg/csi/blockstorage/sanity_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ var _ = Describe("CSI sanity test", Ordered, func() {
189189
iaasClient.EXPECT().ListSnapshots(
190190
gomock.Any(), // context
191191
gomock.Any(), // filters
192-
).DoAndReturn(func(_ context.Context, filters map[string]string) ([]iaas.Snapshot, error) {
192+
).DoAndReturn(func(_ context.Context, filters map[string]string) ([]iaas.Snapshot, string, error) {
193193
var snapshots []iaas.Snapshot
194194

195195
markerFilter := filters["Marker"]
@@ -223,14 +223,16 @@ var _ = Describe("CSI sanity test", Ordered, func() {
223223
}
224224
}
225225

226+
retToken := ""
226227
if limitFilter != "" {
227228
limit, _ := strconv.Atoi(limitFilter)
228229

229230
if limit > 0 && limit <= len(snapshots) {
230231
snapshots = snapshots[:limit]
231232
}
233+
retToken = limitFilter
232234
}
233-
return snapshots, nil
235+
return snapshots, retToken, nil
234236
}).AnyTimes()
235237

236238
iaasClient.EXPECT().DeleteSnapshot(

pkg/stackit/client/iaas.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type IaaSClient interface {
2323
ListServers(ctx context.Context) (*[]iaas.Server, error)
2424

2525
CreateSnapshot(ctx context.Context, payload *iaas.CreateSnapshotPayload) (*iaas.Snapshot, error)
26-
ListSnapshots(ctx context.Context, filters map[string]string) ([]iaas.Snapshot, error)
26+
ListSnapshots(ctx context.Context, filters map[string]string) ([]iaas.Snapshot, string, error)
2727
DeleteSnapshot(ctx context.Context, snapshotID string) error
2828
GetSnapshot(ctx context.Context, snapshotID string) (*iaas.Snapshot, error)
2929
WaitSnapshotReady(ctx context.Context, snapshotID string) (*string, error)
@@ -149,15 +149,15 @@ func (i iaasClient) CreateSnapshot(ctx context.Context, payload *iaas.CreateSnap
149149
return snapshot, nil
150150
}
151151

152-
func (i iaasClient) ListSnapshots(ctx context.Context, filters map[string]string) ([]iaas.Snapshot, error) {
152+
func (i iaasClient) ListSnapshots(ctx context.Context, filters map[string]string) ([]iaas.Snapshot, string, error) {
153153
snaps, err := i.Client.ListSnapshotsInProject(ctx, i.projectID, i.region).Execute()
154154
if err != nil {
155-
return nil, err
155+
return nil, "", err
156156
}
157157

158158
filteredSnapshots := FilterSnapshots(snaps.Items, filters)
159159

160-
return filteredSnapshots, nil
160+
return filteredSnapshots, "", nil
161161
}
162162

163163
func (i iaasClient) DeleteSnapshot(ctx context.Context, snapshotID string) error {

pkg/stackit/client/iaas_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ var _ = Describe("Snapshot", func() {
177177
Return(iaas.ApiListSnapshotsInProjectRequest{ApiService: mockIaaSClient})
178178
mockIaaSClient.EXPECT().ListSnapshotsInProjectExecute(gomock.Any()).Return(mockItems, nil)
179179

180-
resp, err := client.ListSnapshots(context.Background(), nil)
180+
resp, _, err := client.ListSnapshots(context.Background(), nil)
181181
Expect(err).ToNot(HaveOccurred())
182182
Expect(resp).To(HaveLen(2))
183183
})

pkg/stackit/client/mock/iaas_mock.go

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)