@@ -821,6 +821,61 @@ var _ = Describe("GCE PD CSI Driver", func() {
821
821
Expect (gce .IsGCEError (err , "notFound" )).To (BeTrue (), "Expected disk to not be found" )
822
822
}()
823
823
})
824
+
825
+ // Use the region of the test location.
826
+ It ("Should successfully create snapshot with storage locations" , func () {
827
+ testContext := getRandomTestContext ()
828
+
829
+ p , z , _ := testContext .Instance .GetIdentity ()
830
+ client := testContext .Client
831
+
832
+ // Create Disk
833
+ volName , volID := createAndValidateUniqueZonalDisk (client , p , z )
834
+
835
+ // Create Snapshot
836
+ snapshotName := testNamePrefix + string (uuid .NewUUID ())
837
+
838
+ // Convert GCP zone to region, e.g. us-central1-a => us-central1
839
+ // This is safe because we hardcode the zones.
840
+ snapshotLocation := z [:len (z )- 2 ]
841
+
842
+ snapshotParams := map [string ]string {common .ParameterKeyStorageLocations : snapshotLocation }
843
+ snapshotID , err := client .CreateSnapshot (snapshotName , volID , snapshotParams )
844
+ Expect (err ).To (BeNil (), "CreateSnapshot failed with error: %v" , err )
845
+
846
+ // Validate Snapshot Created
847
+ snapshot , err := computeService .Snapshots .Get (p , snapshotName ).Do ()
848
+ Expect (err ).To (BeNil (), "Could not get snapshot from cloud directly" )
849
+ Expect (snapshot .Name ).To (Equal (snapshotName ))
850
+
851
+ err = wait .Poll (10 * time .Second , 3 * time .Minute , func () (bool , error ) {
852
+ snapshot , err := computeService .Snapshots .Get (p , snapshotName ).Do ()
853
+ Expect (err ).To (BeNil (), "Could not get snapshot from cloud directly" )
854
+ if snapshot .Status == "READY" {
855
+ return true , nil
856
+ }
857
+ return false , nil
858
+ })
859
+ Expect (err ).To (BeNil (), "Could not wait for snapshot be ready" )
860
+
861
+ defer func () {
862
+ // Delete Disk
863
+ err := client .DeleteVolume (volID )
864
+ Expect (err ).To (BeNil (), "DeleteVolume failed" )
865
+
866
+ // Validate Disk Deleted
867
+ _ , err = computeService .Disks .Get (p , z , volName ).Do ()
868
+ Expect (gce .IsGCEError (err , "notFound" )).To (BeTrue (), "Expected disk to not be found" )
869
+
870
+ // Delete Snapshot
871
+ err = client .DeleteSnapshot (snapshotID )
872
+ Expect (err ).To (BeNil (), "DeleteSnapshot failed" )
873
+
874
+ // Validate Snapshot Deleted
875
+ _ , err = computeService .Snapshots .Get (p , snapshotName ).Do ()
876
+ Expect (gce .IsGCEError (err , "notFound" )).To (BeTrue (), "Expected snapshot to not be found" )
877
+ }()
878
+ })
824
879
})
825
880
826
881
func equalWithinEpsilon (a , b , epsiolon int64 ) bool {
0 commit comments