@@ -24,7 +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
- remote "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/remote"
27
+ "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/remote"
28
28
29
29
csi "github.com/container-storage-interface/spec/lib/go/csi"
30
30
. "github.com/onsi/ginkgo"
@@ -423,6 +423,36 @@ var _ = Describe("GCE PD CSI Driver", func() {
423
423
Expect (err ).To (BeNil (), "Failed to go through volume lifecycle after restoring CMEK key" )
424
424
})
425
425
426
+ It ("Should create disks, attach them places, and verify List returns correct results" , func () {
427
+ Expect (testContexts ).ToNot (BeEmpty ())
428
+ testContext := getRandomTestContext ()
429
+
430
+ p , z , _ := testContext .Instance .GetIdentity ()
431
+ client := testContext .Client
432
+
433
+ nodeID := testContext .Instance .GetNodeID ()
434
+
435
+ _ , volID := createAndValidateUniqueZonalDisk (client , p , z )
436
+ defer deleteVolumeOrError (client , volID , p )
437
+
438
+ _ , secondVolID := createAndValidateUniqueZonalDisk (client , p , z )
439
+ defer deleteVolumeOrError (client , secondVolID , p )
440
+
441
+ // Attach volID to current instance
442
+ err := client .ControllerPublishVolume (volID , nodeID )
443
+ Expect (err ).To (BeNil (), "Failed ControllerPublishVolume" )
444
+ defer client .ControllerUnpublishVolume (volID , nodeID )
445
+
446
+ // List Volumes
447
+ volsToNodes , err := client .ListVolumes ()
448
+ Expect (err ).To (BeNil (), "Failed ListVolumes" )
449
+
450
+ // Verify
451
+ Expect (volsToNodes [volID ]).ToNot (BeNil (), "Couldn't find attached nodes for vol" )
452
+ Expect (volsToNodes [volID ]).To (ContainElement (nodeID ), "Couldn't find node in attached nodes for vol" )
453
+ Expect (volsToNodes [secondVolID ]).To (BeNil (), "Second vol ID attached nodes not nil" )
454
+ })
455
+
426
456
It ("Should create and delete snapshot for RePD in two zones " , func () {
427
457
Expect (testContexts ).ToNot (BeEmpty ())
428
458
testContext := getRandomTestContext ()
@@ -580,10 +610,11 @@ func equalWithinEpsilon(a, b, epsiolon int64) bool {
580
610
return b - a < epsiolon
581
611
}
582
612
583
- func createAndValidateUniqueZonalDisk (client * remote.CsiClient , project , zone string ) (string , string ) {
613
+ func createAndValidateUniqueZonalDisk (client * remote.CsiClient , project , zone string ) (volName , volID string ) {
584
614
// Create Disk
585
- volName := testNamePrefix + string (uuid .NewUUID ())
586
- volID , err := client .CreateVolume (volName , nil , defaultSizeGb ,
615
+ var err error
616
+ volName = testNamePrefix + string (uuid .NewUUID ())
617
+ volID , err = client .CreateVolume (volName , nil , defaultSizeGb ,
587
618
& csi.TopologyRequirement {
588
619
Requisite : []* csi.Topology {
589
620
{
@@ -600,6 +631,17 @@ func createAndValidateUniqueZonalDisk(client *remote.CsiClient, project, zone st
600
631
Expect (cloudDisk .Status ).To (Equal (readyState ))
601
632
Expect (cloudDisk .SizeGb ).To (Equal (defaultSizeGb ))
602
633
Expect (cloudDisk .Name ).To (Equal (volName ))
634
+ return
635
+ }
636
+
637
+ func deleteVolumeOrError (client * remote.CsiClient , volID , project string ) {
638
+ // Delete Disk
639
+ err := client .DeleteVolume (volID )
640
+ Expect (err ).To (BeNil (), "DeleteVolume failed" )
603
641
604
- return volName , volID
642
+ // Validate Disk Deleted
643
+ key , err := common .VolumeIDToKey (volID )
644
+ Expect (err ).To (BeNil (), "Failed to conver volume ID To key" )
645
+ _ , err = computeService .Disks .Get (project , key .Zone , key .Name ).Do ()
646
+ Expect (gce .IsGCEError (err , "notFound" )).To (BeTrue (), "Expected disk to not be found" )
605
647
}
0 commit comments