@@ -24,6 +24,7 @@ import (
24
24
"k8s.io/apimachinery/pkg/util/wait"
25
25
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
26
26
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
27
+ "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/remote"
27
28
28
29
csi "github.com/container-storage-interface/spec/lib/go/csi"
29
30
. "github.com/onsi/ginkgo"
@@ -466,6 +467,36 @@ var _ = Describe("GCE PD CSI Driver", func() {
466
467
Expect (err ).To (BeNil (), "Failed to go through volume lifecycle after restoring CMEK key" )
467
468
})
468
469
470
+ It ("Should create disks, attach them places, and verify List returns correct results" , func () {
471
+ Expect (testContexts ).ToNot (BeEmpty ())
472
+ testContext := getRandomTestContext ()
473
+
474
+ p , z , _ := testContext .Instance .GetIdentity ()
475
+ client := testContext .Client
476
+
477
+ nodeID := testContext .Instance .GetNodeID ()
478
+
479
+ volID := createUniqueVolumeOrError (client , p , z )
480
+ defer deleteVolumeOrError (client , volID , p )
481
+
482
+ secondVolID := createUniqueVolumeOrError (client , p , z )
483
+ defer deleteVolumeOrError (client , secondVolID , p )
484
+
485
+ // Attach volID to current instance
486
+ err := client .ControllerPublishVolume (volID , nodeID )
487
+ Expect (err ).To (BeNil (), "Failed ControllerPublishVolume" )
488
+ defer client .ControllerUnpublishVolume (volID , nodeID )
489
+
490
+ // List Volumes
491
+ volsToNodes , err := client .ListVolumes ()
492
+ Expect (err ).To (BeNil (), "Failed ListVolumes" )
493
+
494
+ // Verify
495
+ Expect (volsToNodes [volID ]).ToNot (BeNil (), "Couldn't find attached nodes for vol" )
496
+ Expect (volsToNodes [volID ]).To (ContainElement (nodeID ), "Couldn't find node in attached nodes for vol" )
497
+ Expect (volsToNodes [secondVolID ]).To (BeNil (), "Second vol ID attached nodes not nil" )
498
+ })
499
+
469
500
It ("Should create and delete snapshot for RePD in two zones " , func () {
470
501
Expect (testContexts ).ToNot (BeEmpty ())
471
502
testContext := getRandomTestContext ()
@@ -540,3 +571,32 @@ var _ = Describe("GCE PD CSI Driver", func() {
540
571
}()
541
572
})
542
573
})
574
+
575
+ func createUniqueVolumeOrError (client * remote.CsiClient , project , zone string ) string {
576
+ // Create Disk
577
+ volName := testNamePrefix + string (uuid .NewUUID ())
578
+ volID , err := client .CreateVolume (volName , nil , defaultSizeGb , nil )
579
+ Expect (err ).To (BeNil (), "CreateVolume failed with error: %v" , err )
580
+
581
+ // Validate Disk Created
582
+ cloudDisk , err := computeService .Disks .Get (project , zone , volName ).Do ()
583
+ Expect (err ).To (BeNil (), "Could not get disk from cloud directly" )
584
+ Expect (cloudDisk .Type ).To (ContainSubstring (standardDiskType ))
585
+ Expect (cloudDisk .Status ).To (Equal (readyState ))
586
+ Expect (cloudDisk .SizeGb ).To (Equal (defaultSizeGb ))
587
+ Expect (cloudDisk .Name ).To (Equal (volName ))
588
+
589
+ return volID
590
+ }
591
+
592
+ func deleteVolumeOrError (client * remote.CsiClient , volID , project string ) {
593
+ // Delete Disk
594
+ err := client .DeleteVolume (volID )
595
+ Expect (err ).To (BeNil (), "DeleteVolume failed" )
596
+
597
+ // Validate Disk Deleted
598
+ key , err := common .VolumeIDToKey (volID )
599
+ Expect (err ).To (BeNil (), "Failed to conver volume ID To key" )
600
+ _ , err = computeService .Disks .Get (project , key .Zone , key .Name ).Do ()
601
+ Expect (gce .IsGCEError (err , "notFound" )).To (BeTrue (), "Expected disk to not be found" )
602
+ }
0 commit comments