Skip to content

Commit 015fa98

Browse files
authored
Merge pull request #476 from huww98/uniq-name
always use unique name for volume and snapshot
2 parents 22695a7 + 06d53d8 commit 015fa98

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

pkg/sanity/controller.go

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,7 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
543543
})
544544

545545
It("should not fail when creating volume with maximum-length name", func() {
546-
547-
nameBytes := make([]byte, MaxNameLength)
548-
for i := 0; i < MaxNameLength; i++ {
549-
nameBytes[i] = 'a'
550-
}
551-
name := string(nameBytes)
546+
name := UniqueStringWithLength("sanity-controller-create-maxlen", MaxNameLength)
552547
By("creating a volume")
553548
size := TestVolumeSize(sc)
554549

@@ -1136,18 +1131,18 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
11361131

11371132
By("creating first unrelated snapshot")
11381133
// Create volume source and afterwards the first unrelated snapshot.
1139-
volReq := MakeCreateVolumeReq(sc, "listSnapshots-volume-unrelated1")
1140-
r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, "listSnapshots-snapshot-unrelated1")
1134+
volReq := MakeCreateVolumeReq(sc, UniqueString("listSnapshots-volume-unrelated-s-1"))
1135+
r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, UniqueString("listSnapshots-snapshot-unrelated-s-1"))
11411136

11421137
By("creating target snapshot")
11431138
// Create volume source and afterwards the target snapshot.
1144-
volReq = MakeCreateVolumeReq(sc, "listSnapshots-volume-target")
1145-
snapshotTarget, _ := r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, "listSnapshots-snapshot-target")
1139+
volReq = MakeCreateVolumeReq(sc, UniqueString("listSnapshots-volume-target-s"))
1140+
snapshotTarget, _ := r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, UniqueString("listSnapshots-snapshot-target-s"))
11461141

11471142
By("creating second unrelated snapshot")
11481143
// Create volume source and afterwards the second unrelated snapshot.
1149-
volReq = MakeCreateVolumeReq(sc, "listSnapshots-volume-unrelated2")
1150-
r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, "listSnapshots-snapshot-unrelated2")
1144+
volReq = MakeCreateVolumeReq(sc, UniqueString("listSnapshots-volume-unrelated-s-2"))
1145+
r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, UniqueString("listSnapshots-snapshot-unrelated-s-2"))
11511146

11521147
By("listing snapshots")
11531148

@@ -1187,18 +1182,18 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
11871182

11881183
By("creating first unrelated snapshot")
11891184
// Create volume source and afterwards the first unrelated snapshot.
1190-
volReq := MakeCreateVolumeReq(sc, "listSnapshots-volume-unrelated1")
1191-
r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, "listSnapshots-snapshot-unrelated1")
1185+
volReq := MakeCreateVolumeReq(sc, UniqueString("listSnapshots-volume-unrelated-v-1"))
1186+
r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, UniqueString("listSnapshots-snapshot-unrelated-v-1"))
11921187

11931188
By("creating target snapshot")
11941189
// Create volume source and afterwards the target snapshot.
1195-
volReq = MakeCreateVolumeReq(sc, "listSnapshots-volume-target")
1196-
snapshotTarget, _ := r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, "listSnapshots-snapshot-target")
1190+
volReq = MakeCreateVolumeReq(sc, UniqueString("listSnapshots-volume-target-v"))
1191+
snapshotTarget, _ := r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, UniqueString("listSnapshots-snapshot-target-v"))
11971192

11981193
By("creating second unrelated snapshot")
11991194
// Create volume source and afterwards the second unrelated snapshot.
1200-
volReq = MakeCreateVolumeReq(sc, "listSnapshots-volume-unrelated2")
1201-
r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, "listSnapshots-snapshot-unrelated2")
1195+
volReq = MakeCreateVolumeReq(sc, UniqueString("listSnapshots-volume-unrelated-v-2"))
1196+
r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, UniqueString("listSnapshots-snapshot-unrelated-v-2"))
12021197

12031198
By("listing snapshots")
12041199

@@ -1247,8 +1242,8 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
12471242
totalSnapshots := len(snapshots.GetEntries())
12481243

12491244
By("creating a snapshot")
1250-
volReq := MakeCreateVolumeReq(sc, "listSnapshots-volume-3")
1251-
snapshot, _ := r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, "listSnapshots-snapshot-3")
1245+
volReq := MakeCreateVolumeReq(sc, UniqueString("listSnapshots-volume-3"))
1246+
snapshot, _ := r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, UniqueString("listSnapshots-snapshot-3"))
12521247
verifySnapshotInfo(snapshot.GetSnapshot())
12531248

12541249
snapshots, err = r.ListSnapshots(context.Background(), req)
@@ -1302,8 +1297,8 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext
13021297
requiredSnapshots := minSnapshotCount - initialTotalSnapshots
13031298

13041299
for i := 1; i <= requiredSnapshots; i++ {
1305-
volReq := MakeCreateVolumeReq(sc, "volume"+strconv.Itoa(i))
1306-
snapshot, _ := r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, "snapshot"+strconv.Itoa(i))
1300+
volReq := MakeCreateVolumeReq(sc, UniqueString("volume"+strconv.Itoa(i)))
1301+
snapshot, _ := r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, UniqueString("snapshot"+strconv.Itoa(i)))
13071302
verifySnapshotInfo(snapshot.GetSnapshot())
13081303
}
13091304

@@ -1389,13 +1384,13 @@ var _ = DescribeSanity("DeleteSnapshot [Controller Server]", func(sc *TestContex
13891384
It("should return appropriate values (no optional values added)", func() {
13901385

13911386
By("creating a volume")
1392-
volReq := MakeCreateVolumeReq(sc, "DeleteSnapshot-volume-1")
1387+
volReq := MakeCreateVolumeReq(sc, UniqueString("DeleteSnapshot-volume-1"))
13931388
volume, err := r.CreateVolume(context.Background(), volReq)
13941389
Expect(err).NotTo(HaveOccurred())
13951390

13961391
// Create Snapshot First
13971392
By("creating a snapshot")
1398-
snapshotReq := MakeCreateSnapshotReq(sc, "DeleteSnapshot-snapshot-1", volume.GetVolume().GetVolumeId())
1393+
snapshotReq := MakeCreateSnapshotReq(sc, UniqueString("DeleteSnapshot-snapshot-1"), volume.GetVolume().GetVolumeId())
13991394
r.MustCreateSnapshot(context.Background(), snapshotReq)
14001395
})
14011396
})
@@ -1456,29 +1451,30 @@ var _ = DescribeSanity("CreateSnapshot [Controller Server]", func(sc *TestContex
14561451
It("should succeed when requesting to create a snapshot with already existing name and same source volume ID", func() {
14571452

14581453
By("creating a volume")
1459-
volReq := MakeCreateVolumeReq(sc, "CreateSnapshot-volume-1")
1454+
volReq := MakeCreateVolumeReq(sc, UniqueString("CreateSnapshot-volume-1"))
14601455
volume := r.MustCreateVolume(context.Background(), volReq)
14611456

14621457
By("creating a snapshot")
1463-
snapReq1 := MakeCreateSnapshotReq(sc, "CreateSnapshot-snapshot-1", volume.GetVolume().GetVolumeId())
1458+
snapReq1 := MakeCreateSnapshotReq(sc, UniqueString("CreateSnapshot-snapshot-1"), volume.GetVolume().GetVolumeId())
14641459
r.MustCreateSnapshot(context.Background(), snapReq1)
14651460

14661461
By("creating a snapshot with the same name and source volume ID")
14671462
r.MustCreateSnapshot(context.Background(), snapReq1)
14681463
})
14691464

14701465
It("should fail when requesting to create a snapshot with already existing name and different source volume ID", func() {
1466+
snapshotName := UniqueString("CreateSnapshot-snapshot-2")
14711467

14721468
By("creating a snapshot")
1473-
volReq := MakeCreateVolumeReq(sc, "CreateSnapshot-volume-2")
1474-
r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, "CreateSnapshot-snapshot-2")
1469+
volReq := MakeCreateVolumeReq(sc, UniqueString("CreateSnapshot-volume-2"))
1470+
r.MustCreateSnapshotFromVolumeRequest(context.Background(), volReq, snapshotName)
14751471

14761472
By("creating a new source volume")
1477-
volReq = MakeCreateVolumeReq(sc, "CreateSnapshot-volume-3")
1473+
volReq = MakeCreateVolumeReq(sc, UniqueString("CreateSnapshot-volume-3"))
14781474
volume2 := r.MustCreateVolume(context.Background(), volReq)
14791475

14801476
By("creating a snapshot with the same name but different source volume ID")
1481-
req := MakeCreateSnapshotReq(sc, "CreateSnapshot-snapshot-2", volume2.GetVolume().GetVolumeId())
1477+
req := MakeCreateSnapshotReq(sc, snapshotName, volume2.GetVolume().GetVolumeId())
14821478
_, err := r.CreateSnapshot(context.Background(), req)
14831479
Expect(err).To(HaveOccurred())
14841480
serverError, ok := status.FromError(err)
@@ -1489,14 +1485,10 @@ var _ = DescribeSanity("CreateSnapshot [Controller Server]", func(sc *TestContex
14891485
It("should succeed when creating snapshot with maximum-length name", func() {
14901486

14911487
By("creating a volume")
1492-
volReq := MakeCreateVolumeReq(sc, "CreateSnapshot-volume-3")
1488+
volReq := MakeCreateVolumeReq(sc, UniqueString("CreateSnapshot-volume-maxlen-name"))
14931489
volume := r.MustCreateVolume(context.Background(), volReq)
14941490

1495-
nameBytes := make([]byte, MaxNameLength)
1496-
for i := 0; i < MaxNameLength; i++ {
1497-
nameBytes[i] = 'a'
1498-
}
1499-
name := string(nameBytes)
1491+
name := UniqueStringWithLength("CreateSnapshot-snapshot-maxlen", MaxNameLength)
15001492

15011493
By("creating a snapshot")
15021494
snapReq1 := MakeCreateSnapshotReq(sc, name, volume.GetVolume().GetVolumeId())
@@ -1693,7 +1685,7 @@ func VolumeLifecycle(r *Resources, sc *TestContext, count int) {
16931685

16941686
// Create Volume First
16951687
By("creating a single node writer volume")
1696-
name := UniqueString("sanity-controller-publish")
1688+
name := UniqueString(fmt.Sprintf("sanity-controller-publish-%d", count))
16971689

16981690
vol := r.MustCreateVolume(
16991691
context.Background(),

pkg/sanity/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func isPluginCapabilitySupported(c csi.IdentityClient,
6868

6969
func runControllerTest(sc *TestContext, r *Resources, controllerPublishSupported bool, nodeStageSupported bool, nodeVolumeStatsSupported bool, count int) {
7070

71-
name := UniqueString("sanity-node-full")
71+
name := UniqueString(fmt.Sprintf("sanity-node-full-%d", count))
7272

7373
By("getting node information")
7474
ni, err := r.NodeGetInfo(

pkg/sanity/sanity.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,14 @@ func UniqueString(prefix string) string {
453453
return prefix + uniqueSuffix
454454
}
455455

456+
func UniqueStringWithLength(prefix string, length int) string {
457+
str := UniqueString(prefix)
458+
if len(str) > length {
459+
panic(fmt.Sprintf("prefix %q is too long, use a shorter one", prefix))
460+
}
461+
return str + strings.Repeat("a", length-len(str))
462+
}
463+
456464
// Return codes for CheckPath
457465
type PathKind string
458466

0 commit comments

Comments
 (0)