Skip to content

Commit d7989f4

Browse files
committed
feat(ListSnapshotsSecret): csi-sanity test suite now passes secrets to ListSnapshots
Signed-off-by: Joe Skazinski <joseph.skazinski@seagate.com>
1 parent db65255 commit d7989f4

File tree

4 files changed

+86
-39
lines changed

4 files changed

+86
-39
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ We have full documentation on how to get started contributing here:
1010

1111
- [Contributor License Agreement](https://git.k8s.io/community/CLA.md) Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests
1212
- [Kubernetes Contributor Guide](http://git.k8s.io/community/contributors/guide) - Main contributor documentation, or you can just jump directly to the [contributing section](http://git.k8s.io/community/contributors/guide#contributing)
13-
- [Contributor Cheat Sheet](https://git.k8s.io/community/contributors/guide/contributor-cheatsheet.md) - Common resources for existing developers
13+
- [Contributor Cheat Sheet](https://github.com/kubernetes/community/blob/master/contributors/guide/contributor-cheatsheet/README.md) - Common resources for existing developers
1414

1515
## Mentorship
1616

driver/driver.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type CSICreds struct {
6565
CreateSnapshotSecret string
6666
DeleteSnapshotSecret string
6767
ControllerValidateVolumeCapabilitiesSecret string
68+
ListSnapshotsSecret string
6869
}
6970

7071
type CSIDriver struct {
@@ -184,6 +185,7 @@ func setDefaultCreds(creds *CSICreds) {
184185
CreateSnapshotSecret: "secretval7",
185186
DeleteSnapshotSecret: "secretval8",
186187
ControllerValidateVolumeCapabilitiesSecret: "secretval9",
188+
ListSnapshotsSecret: "secretval10",
187189
}
188190
}
189191

@@ -262,6 +264,8 @@ func isAuthenticated(req interface{}, creds *CSICreds) (bool, error) {
262264
return authenticateDeleteSnapshot(r, creds)
263265
case *csi.ValidateVolumeCapabilitiesRequest:
264266
return authenticateControllerValidateVolumeCapabilities(r, creds)
267+
case *csi.ListSnapshotsRequest:
268+
return authenticateListSnapshots(r, creds)
265269
default:
266270
return true, nil
267271
}
@@ -303,6 +307,10 @@ func authenticateControllerValidateVolumeCapabilities(req *csi.ValidateVolumeCap
303307
return credsCheck(req.GetSecrets(), creds.ControllerValidateVolumeCapabilitiesSecret)
304308
}
305309

310+
func authenticateListSnapshots(req *csi.ListSnapshotsRequest, creds *CSICreds) (bool, error) {
311+
return credsCheck(req.GetSecrets(), creds.ListSnapshotsSecret)
312+
}
313+
306314
func credsCheck(secrets map[string]string, secretVal string) (bool, error) {
307315
if len(secrets) == 0 {
308316
return false, ErrNoCredentials

pkg/sanity/controller.go

Lines changed: 76 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,9 +1113,14 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
11131113
})
11141114

11151115
It("should return appropriate values (no optional values added)", func() {
1116-
snapshots, err := r.ListSnapshots(
1117-
context.Background(),
1118-
&csi.ListSnapshotsRequest{})
1116+
1117+
req := &csi.ListSnapshotsRequest{}
1118+
1119+
if sc.Secrets != nil {
1120+
req.Secrets = sc.Secrets.ListSnapshotsSecret
1121+
}
1122+
1123+
snapshots, err := r.ListSnapshots(context.Background(), req)
11191124
Expect(err).NotTo(HaveOccurred())
11201125
Expect(snapshots).NotTo(BeNil())
11211126

@@ -1145,9 +1150,14 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
11451150
r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, "listSnapshots-snapshot-unrelated2")
11461151

11471152
By("listing snapshots")
1148-
snapshots, err := r.ListSnapshots(
1149-
context.Background(),
1150-
&csi.ListSnapshotsRequest{SnapshotId: snapshotTarget.GetSnapshot().GetSnapshotId()})
1153+
1154+
req := &csi.ListSnapshotsRequest{SnapshotId: snapshotTarget.GetSnapshot().GetSnapshotId()}
1155+
1156+
if sc.Secrets != nil {
1157+
req.Secrets = sc.Secrets.ListSnapshotsSecret
1158+
}
1159+
1160+
snapshots, err := r.ListSnapshots(context.Background(), req)
11511161
Expect(err).NotTo(HaveOccurred())
11521162
Expect(snapshots).NotTo(BeNil())
11531163
Expect(snapshots.GetEntries()).To(HaveLen(1))
@@ -1157,9 +1167,13 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
11571167

11581168
It("should return empty when the specified snapshot id does not exist", func() {
11591169

1160-
snapshots, err := r.ListSnapshots(
1161-
context.Background(),
1162-
&csi.ListSnapshotsRequest{SnapshotId: "none-exist-id"})
1170+
req := &csi.ListSnapshotsRequest{SnapshotId: "none-exist-id"}
1171+
1172+
if sc.Secrets != nil {
1173+
req.Secrets = sc.Secrets.ListSnapshotsSecret
1174+
}
1175+
1176+
snapshots, err := r.ListSnapshots(context.Background(), req)
11631177
Expect(err).NotTo(HaveOccurred())
11641178
Expect(snapshots).NotTo(BeNil())
11651179
Expect(snapshots.GetEntries()).To(BeEmpty())
@@ -1187,9 +1201,14 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
11871201
r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, "listSnapshots-snapshot-unrelated2")
11881202

11891203
By("listing snapshots")
1190-
snapshots, err := r.ListSnapshots(
1191-
context.Background(),
1192-
&csi.ListSnapshotsRequest{SourceVolumeId: snapshotTarget.GetSnapshot().GetSourceVolumeId()})
1204+
1205+
req := &csi.ListSnapshotsRequest{SourceVolumeId: snapshotTarget.GetSnapshot().GetSourceVolumeId()}
1206+
1207+
if sc.Secrets != nil {
1208+
req.Secrets = sc.Secrets.ListSnapshotsSecret
1209+
}
1210+
1211+
snapshots, err := r.ListSnapshots(context.Background(), req)
11931212
Expect(err).NotTo(HaveOccurred())
11941213
Expect(snapshots).NotTo(BeNil())
11951214
Expect(snapshots.GetEntries()).To(HaveLen(1))
@@ -1200,19 +1219,28 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
12001219

12011220
It("should return empty when the specified source volume id does not exist", func() {
12021221

1203-
snapshots, err := r.ListSnapshots(
1204-
context.Background(),
1205-
&csi.ListSnapshotsRequest{SourceVolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID()})
1222+
req := &csi.ListSnapshotsRequest{SourceVolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID()}
1223+
1224+
if sc.Secrets != nil {
1225+
req.Secrets = sc.Secrets.ListSnapshotsSecret
1226+
}
1227+
1228+
snapshots, err := r.ListSnapshots(context.Background(), req)
12061229
Expect(err).NotTo(HaveOccurred())
12071230
Expect(snapshots).NotTo(BeNil())
12081231
Expect(snapshots.GetEntries()).To(BeEmpty())
12091232
})
12101233

12111234
It("check the presence of new snapshots in the snapshot list", func() {
12121235
// List Snapshots before creating new snapshots.
1213-
snapshots, err := r.ListSnapshots(
1214-
context.Background(),
1215-
&csi.ListSnapshotsRequest{})
1236+
1237+
req := &csi.ListSnapshotsRequest{}
1238+
1239+
if sc.Secrets != nil {
1240+
req.Secrets = sc.Secrets.ListSnapshotsSecret
1241+
}
1242+
1243+
snapshots, err := r.ListSnapshots(context.Background(), req)
12161244
Expect(err).NotTo(HaveOccurred())
12171245
Expect(snapshots).NotTo(BeNil())
12181246

@@ -1223,21 +1251,21 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
12231251
snapshot, _ := r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, "listSnapshots-snapshot-3")
12241252
verifySnapshotInfo(snapshot.GetSnapshot())
12251253

1226-
snapshots, err = r.ListSnapshots(
1227-
context.Background(),
1228-
&csi.ListSnapshotsRequest{})
1254+
snapshots, err = r.ListSnapshots(context.Background(), req)
12291255
Expect(err).NotTo(HaveOccurred())
12301256
Expect(snapshots).NotTo(BeNil())
12311257
Expect(snapshots.GetEntries()).To(HaveLen(totalSnapshots + 1))
12321258

12331259
By("deleting the snapshot")
1234-
_, err = r.DeleteSnapshot(context.Background(), &csi.DeleteSnapshotRequest{SnapshotId: snapshot.Snapshot.SnapshotId})
1260+
dreq := &csi.DeleteSnapshotRequest{SnapshotId: snapshot.Snapshot.SnapshotId}
1261+
if sc.Secrets != nil {
1262+
dreq.Secrets = sc.Secrets.DeleteSnapshotSecret
1263+
}
1264+
_, err = r.DeleteSnapshot(context.Background(), dreq)
12351265
Expect(err).NotTo(HaveOccurred())
12361266

12371267
By("checking if deleted snapshot is omitted")
1238-
snapshots, err = r.ListSnapshots(
1239-
context.Background(),
1240-
&csi.ListSnapshotsRequest{})
1268+
snapshots, err = r.ListSnapshots(context.Background(), req)
12411269
Expect(err).NotTo(HaveOccurred())
12421270
Expect(snapshots).NotTo(BeNil())
12431271
Expect(snapshots.GetEntries()).To(HaveLen(totalSnapshots))
@@ -1253,10 +1281,14 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
12531281
// is used to verify that all the snapshots have been listed.
12541282
currentTotalSnapshots := 0
12551283

1284+
req := &csi.ListSnapshotsRequest{}
1285+
1286+
if sc.Secrets != nil {
1287+
req.Secrets = sc.Secrets.ListSnapshotsSecret
1288+
}
1289+
12561290
// Get the number of existing volumes.
1257-
snapshots, err := r.ListSnapshots(
1258-
context.Background(),
1259-
&csi.ListSnapshotsRequest{})
1291+
snapshots, err := r.ListSnapshots(context.Background(), req)
12601292
Expect(err).NotTo(HaveOccurred())
12611293
Expect(snapshots).NotTo(BeNil())
12621294

@@ -1280,11 +1312,14 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
12801312
}
12811313

12821314
// Request list snapshots with max entries maxEntries.
1283-
snapshots, err = r.ListSnapshots(
1284-
context.Background(),
1285-
&csi.ListSnapshotsRequest{
1286-
MaxEntries: int32(maxEntries),
1287-
})
1315+
1316+
req = &csi.ListSnapshotsRequest{MaxEntries: int32(maxEntries)}
1317+
1318+
if sc.Secrets != nil {
1319+
req.Secrets = sc.Secrets.ListSnapshotsSecret
1320+
}
1321+
1322+
snapshots, err = r.ListSnapshots(context.Background(), req)
12881323
Expect(err).NotTo(HaveOccurred())
12891324
Expect(snapshots).NotTo(BeNil())
12901325

@@ -1293,11 +1328,14 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
12931328
Expect(snapshots.GetEntries()).To(HaveLen(maxEntries))
12941329

12951330
// Request list snapshots with starting_token and no max entries.
1296-
snapshots, err = r.ListSnapshots(
1297-
context.Background(),
1298-
&csi.ListSnapshotsRequest{
1299-
StartingToken: nextToken,
1300-
})
1331+
1332+
req = &csi.ListSnapshotsRequest{StartingToken: nextToken}
1333+
1334+
if sc.Secrets != nil {
1335+
req.Secrets = sc.Secrets.ListSnapshotsSecret
1336+
}
1337+
1338+
snapshots, err = r.ListSnapshots(context.Background(), req)
13011339
Expect(err).NotTo(HaveOccurred())
13021340
Expect(snapshots).NotTo(BeNil())
13031341

pkg/sanity/sanity.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type CSISecrets struct {
4848
CreateSnapshotSecret map[string]string `yaml:"CreateSnapshotSecret"`
4949
DeleteSnapshotSecret map[string]string `yaml:"DeleteSnapshotSecret"`
5050
ControllerExpandVolumeSecret map[string]string `yaml:"ControllerExpandVolumeSecret"`
51+
ListSnapshotsSecret map[string]string `yaml:"ListSnapshotsSecret"`
5152
}
5253

5354
// TestConfig provides the configuration for the sanity tests. It must be

0 commit comments

Comments
 (0)