Skip to content

Commit 2e6ca14

Browse files
author
Stephen Schmitt
committed
Add pending test for multi-writer attach. Updated for minimum multi-writer PD size of 200GB.
1 parent 99c4619 commit 2e6ca14

File tree

5 files changed

+123
-39
lines changed

5 files changed

+123
-39
lines changed

examples/kubernetes/demo-pod-shared-pd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
storageClassName: csi-gce-pd
1010
resources:
1111
requests:
12-
storage: 6Gi
12+
storage: 200Gi
1313

1414
---
1515

pkg/gce-cloud-provider/compute/gce-compute.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,15 @@ func (cloud *CloudProvider) insertRegionalDisk(ctx context.Context, volKey *meta
335335
alphaDiskToCreate := convertV1DiskToAlphaDisk(diskToCreate)
336336
alphaDiskToCreate.MultiWriter = multiWriter
337337
insertOp, err = cloud.alphaService.RegionDisks.Insert(cloud.project, volKey.Region, alphaDiskToCreate).Context(ctx).Do()
338-
opName = insertOp.Name
338+
if err == nil {
339+
opName = insertOp.Name
340+
}
339341
} else {
340342
var insertOp *computev1.Operation
341343
insertOp, err = cloud.service.RegionDisks.Insert(cloud.project, volKey.Region, diskToCreate).Context(ctx).Do()
342-
opName = insertOp.Name
344+
if err == nil {
345+
opName = insertOp.Name
346+
}
343347
}
344348
if err != nil {
345349
if IsGCEError(err, "alreadyExists") {
@@ -415,11 +419,15 @@ func (cloud *CloudProvider) insertZonalDisk(ctx context.Context, volKey *meta.Ke
415419
alphaDiskToCreate := convertV1DiskToAlphaDisk(diskToCreate)
416420
alphaDiskToCreate.MultiWriter = multiWriter
417421
insertOp, err = cloud.alphaService.Disks.Insert(cloud.project, volKey.Zone, alphaDiskToCreate).Context(ctx).Do()
418-
opName = insertOp.Name
422+
if err == nil {
423+
opName = insertOp.Name
424+
}
419425
} else {
420426
var insertOp *computev1.Operation
421427
insertOp, err = cloud.service.Disks.Insert(cloud.project, volKey.Zone, diskToCreate).Context(ctx).Do()
422-
opName = insertOp.Name
428+
if err == nil {
429+
opName = insertOp.Name
430+
}
423431
}
424432

425433
if err != nil {

test/e2e/tests/multi_zone_e2e_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ func testLifecycleWithVerify(volID string, volName string, instance *remote.Inst
256256
if secondMountVerify != nil {
257257
// Mount disk somewhere else
258258
secondPublishDir := filepath.Join("/tmp/", volName, "secondmount")
259-
err = client.NodePublishVolume(volID, stageDir, secondPublishDir)
259+
if useBlock {
260+
err = client.NodePublishBlockVolume(volID, stageDir, secondPublishDir)
261+
} else {
262+
err = client.NodePublishVolume(volID, stageDir, secondPublishDir)
263+
}
260264
if err != nil {
261265
return fmt.Errorf("NodePublishVolume failed with error: %v", err)
262266
}
@@ -268,7 +272,10 @@ func testLifecycleWithVerify(volID string, volName string, instance *remote.Inst
268272
b := verifyArgs{
269273
publishDir: secondPublishDir,
270274
}
271-
secondMountVerify(b)
275+
err = secondMountVerify(b)
276+
if err != nil {
277+
return fmt.Errorf("failed to verify after second mount to %s: %v", publishDir, err)
278+
}
272279

273280
// Unmount Disk
274281
err = client.NodeUnpublishVolume(volID, secondPublishDir)

test/e2e/tests/single_zone_e2e_test.go

Lines changed: 84 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ import (
3333
"google.golang.org/api/iterator"
3434
kmspb "google.golang.org/genproto/googleapis/cloud/kms/v1"
3535
fieldmask "google.golang.org/genproto/protobuf/field_mask"
36+
testutils "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/e2e/utils"
3637
)
3738

3839
const (
3940
testNamePrefix = "gcepd-csi-e2e-"
4041

4142
defaultSizeGb int64 = 5
4243
defaultRepdSizeGb int64 = 200
44+
defaultMwSizeGb int64 = 200
4345
readyState = "READY"
4446
standardDiskType = "pd-standard"
4547
ssdDiskType = "pd-ssd"
@@ -582,48 +584,63 @@ var _ = Describe("GCE PD CSI Driver", func() {
582584
// Hardcode to us-east1-a while feature is in alpha
583585
zone := "us-east1-a"
584586

585-
// Create Disk
586-
volName := testNamePrefix + string(uuid.NewUUID())
587-
volID, err := client.CreateVolumeWithCaps(volName, nil, defaultSizeGb,
588-
&csi.TopologyRequirement{
589-
Requisite: []*csi.Topology{
590-
{
591-
Segments: map[string]string{common.TopologyKeyZone: zone},
592-
},
593-
},
594-
},
595-
[]*csi.VolumeCapability{
596-
{
597-
AccessType: &csi.VolumeCapability_Block{
598-
Block: &csi.VolumeCapability_BlockVolume{},
599-
},
600-
AccessMode: &csi.VolumeCapability_AccessMode{
601-
Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
602-
},
603-
},
604-
},
605-
)
606-
Expect(err).To(BeNil(), "CreateVolume failed with error: %v", err)
607-
608-
// Validate Disk Created
609-
cloudDisk, err := computeAlphaService.Disks.Get(p, zone, volName).Do()
610-
Expect(err).To(BeNil(), "Could not get disk from cloud directly")
611-
Expect(cloudDisk.Type).To(ContainSubstring(standardDiskType))
612-
Expect(cloudDisk.Status).To(Equal(readyState))
613-
Expect(cloudDisk.SizeGb).To(Equal(defaultSizeGb))
614-
Expect(cloudDisk.Name).To(Equal(volName))
615-
Expect(cloudDisk.MultiWriter).To(Equal(true))
587+
// Create and Validate Disk
588+
volName, volID := createAndValidateUniqueZonalMultiWriterDisk(client, p, zone)
616589

617590
defer func() {
618591
// Delete Disk
619-
client.DeleteVolume(volID)
592+
err := client.DeleteVolume(volID)
620593
Expect(err).To(BeNil(), "DeleteVolume failed")
621594

622595
// Validate Disk Deleted
623596
_, err = computeAlphaService.Disks.Get(p, zone, volName).Do()
624597
Expect(gce.IsGCEError(err, "notFound")).To(BeTrue(), "Expected disk to not be found")
625598
}()
626599
})
600+
601+
// Pending while multi-writer feature is in Alpha
602+
PIt("Should complete entire disk lifecycle with multi-writer disk", func() {
603+
testContext := getRandomTestContext()
604+
605+
p, z, _ := testContext.Instance.GetIdentity()
606+
client := testContext.Client
607+
instance := testContext.Instance
608+
609+
// Create and Validate Disk
610+
volName, volID := createAndValidateUniqueZonalMultiWriterDisk(client, p, z)
611+
612+
defer func() {
613+
// Delete Disk
614+
err := client.DeleteVolume(volID)
615+
Expect(err).To(BeNil(), "DeleteVolume failed")
616+
617+
// Validate Disk Deleted
618+
_, err = computeService.Disks.Get(p, z, volName).Do()
619+
Expect(gce.IsGCEError(err, "notFound")).To(BeTrue(), "Expected disk to not be found")
620+
}()
621+
622+
// Attach Disk
623+
testFileContents := "test"
624+
writeFunc := func(a verifyArgs) error {
625+
err := testutils.WriteBlock(instance, a.publishDir, testFileContents)
626+
if err != nil {
627+
return fmt.Errorf("Failed to write file: %v", err)
628+
}
629+
return nil
630+
}
631+
verifyReadFunc := func(a verifyArgs) error {
632+
readContents, err := testutils.ReadBlock(instance, a.publishDir, len(testFileContents))
633+
if err != nil {
634+
return fmt.Errorf("ReadFile failed with error: %v", err)
635+
}
636+
if strings.TrimSpace(string(readContents)) != testFileContents {
637+
return fmt.Errorf("wanted test file content: %s, got content: %s", testFileContents, readContents)
638+
}
639+
return nil
640+
}
641+
err := testLifecycleWithVerify(volID, volName, instance, client, false /* readOnly */, true /* block */, writeFunc, verifyReadFunc)
642+
Expect(err).To(BeNil(), "Failed to go through volume lifecycle")
643+
})
627644
})
628645

629646
func equalWithinEpsilon(a, b, epsiolon int64) bool {
@@ -656,3 +673,38 @@ func createAndValidateUniqueZonalDisk(client *remote.CsiClient, project, zone st
656673

657674
return volName, volID
658675
}
676+
677+
func createAndValidateUniqueZonalMultiWriterDisk(client *remote.CsiClient, project, zone string) (string, string) {
678+
// Create Disk
679+
volName := testNamePrefix + string(uuid.NewUUID())
680+
volID, err := client.CreateVolumeWithCaps(volName, nil, defaultMwSizeGb,
681+
&csi.TopologyRequirement{
682+
Requisite: []*csi.Topology{
683+
{
684+
Segments: map[string]string{common.TopologyKeyZone: zone},
685+
},
686+
},
687+
},
688+
[]*csi.VolumeCapability{
689+
{
690+
AccessType: &csi.VolumeCapability_Block{
691+
Block: &csi.VolumeCapability_BlockVolume{},
692+
},
693+
AccessMode: &csi.VolumeCapability_AccessMode{
694+
Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
695+
},
696+
},
697+
})
698+
Expect(err).To(BeNil(), "CreateVolume failed with error: %v", err)
699+
700+
// Validate Disk Created
701+
cloudDisk, err := computeAlphaService.Disks.Get(project, zone, volName).Do()
702+
Expect(err).To(BeNil(), "Could not get disk from cloud directly")
703+
Expect(cloudDisk.Type).To(ContainSubstring(standardDiskType))
704+
Expect(cloudDisk.Status).To(Equal(readyState))
705+
Expect(cloudDisk.SizeGb).To(Equal(defaultMwSizeGb))
706+
Expect(cloudDisk.Name).To(Equal(volName))
707+
Expect(cloudDisk.MultiWriter).To(Equal(true))
708+
709+
return volName, volID
710+
}

test/e2e/utils/utils.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,23 @@ func ReadFile(instance *remote.InstanceInfo, filePath string) (string, error) {
170170
return output, nil
171171
}
172172

173+
func WriteBlock(instance *remote.InstanceInfo, path, fileContents string) error {
174+
output, err := instance.SSHNoSudo("echo", fileContents, "|", "dd", "of="+path)
175+
if err != nil {
176+
return fmt.Errorf("failed to write test file %s. Output: %v, errror: %v", path, output, err)
177+
}
178+
return nil
179+
}
180+
181+
func ReadBlock(instance *remote.InstanceInfo, path string, length int) (string, error) {
182+
lengthStr := strconv.Itoa(length)
183+
output, err := instance.SSHNoSudo("dd", "if="+path, "bs="+lengthStr, "count=1", "2>", "/dev/null")
184+
if err != nil {
185+
return "", fmt.Errorf("failed to read test file %s. Output: %v, errror: %v", path, output, err)
186+
}
187+
return output, nil
188+
}
189+
173190
func GetFSSizeInGb(instance *remote.InstanceInfo, mountPath string) (int64, error) {
174191
output, err := instance.SSHNoSudo("df", "--output=size", "-BG", mountPath, "|", "awk", "'NR==2'")
175192
if err != nil {

0 commit comments

Comments
 (0)