@@ -33,13 +33,15 @@ import (
33
33
"google.golang.org/api/iterator"
34
34
kmspb "google.golang.org/genproto/googleapis/cloud/kms/v1"
35
35
fieldmask "google.golang.org/genproto/protobuf/field_mask"
36
+ testutils "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/e2e/utils"
36
37
)
37
38
38
39
const (
39
40
testNamePrefix = "gcepd-csi-e2e-"
40
41
41
42
defaultSizeGb int64 = 5
42
43
defaultRepdSizeGb int64 = 200
44
+ defaultMwSizeGb int64 = 200
43
45
readyState = "READY"
44
46
standardDiskType = "pd-standard"
45
47
ssdDiskType = "pd-ssd"
@@ -582,48 +584,63 @@ var _ = Describe("GCE PD CSI Driver", func() {
582
584
// Hardcode to us-east1-a while feature is in alpha
583
585
zone := "us-east1-a"
584
586
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 )
616
589
617
590
defer func () {
618
591
// Delete Disk
619
- client .DeleteVolume (volID )
592
+ err := client .DeleteVolume (volID )
620
593
Expect (err ).To (BeNil (), "DeleteVolume failed" )
621
594
622
595
// Validate Disk Deleted
623
596
_ , err = computeAlphaService .Disks .Get (p , zone , volName ).Do ()
624
597
Expect (gce .IsGCEError (err , "notFound" )).To (BeTrue (), "Expected disk to not be found" )
625
598
}()
626
599
})
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
+ })
627
644
})
628
645
629
646
func equalWithinEpsilon (a , b , epsiolon int64 ) bool {
@@ -656,3 +673,38 @@ func createAndValidateUniqueZonalDisk(client *remote.CsiClient, project, zone st
656
673
657
674
return volName , volID
658
675
}
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
+ }
0 commit comments