@@ -876,6 +876,65 @@ var _ = Describe("GCE PD CSI Driver", func() {
876
876
Expect (gce .IsGCEError (err , "notFound" )).To (BeTrue (), "Expected snapshot to not be found" )
877
877
}()
878
878
})
879
+
880
+ // Use the region of the test location.
881
+ It ("Should successfully create snapshot backed by disk image" , func () {
882
+ testContext := getRandomTestContext ()
883
+
884
+ p , z , _ := testContext .Instance .GetIdentity ()
885
+ client := testContext .Client
886
+
887
+ // Create Disk
888
+ volName , volID := createAndValidateUniqueZonalDisk (client , p , z )
889
+
890
+ // Create Snapshot
891
+ snapshotName := testNamePrefix + string (uuid .NewUUID ())
892
+ testImageFamily := "test-family"
893
+
894
+ snapshotParams := map [string ]string {common .ParameterKeySnapshotType : common .DiskImageType , common .ParameterKeyImageFamily : testImageFamily }
895
+ snapshotID , err := client .CreateSnapshot (snapshotName , volID , snapshotParams )
896
+ Expect (err ).To (BeNil (), "CreateSnapshot failed with error: %v" , err )
897
+
898
+ // Validate Snapshot Created
899
+ snapshot , err := computeService .Snapshots .Get (p , snapshotName ).Do ()
900
+ Expect (err ).To (BeNil (), "Could not get snapshot from cloud directly" )
901
+ Expect (snapshot .Name ).To (Equal (snapshotName ))
902
+
903
+ err = wait .Poll (10 * time .Second , 3 * time .Minute , func () (bool , error ) {
904
+ snapshot , err := computeService .Snapshots .Get (p , snapshotName ).Do ()
905
+ Expect (err ).To (BeNil (), "Could not get snapshot from cloud directly" )
906
+ if snapshot .Status == "READY" {
907
+ return true , nil
908
+ }
909
+ return false , nil
910
+ })
911
+ Expect (err ).To (BeNil (), "Could not wait for snapshot be ready" )
912
+
913
+ // Check Snapshot Type
914
+ snapshot , err = computeService .Snapshots .Get (p , snapshotName ).Do ()
915
+ Expect (err ).To (BeNil (), "Could not get snapshot from cloud directly" )
916
+ _ , snapshotType , _ , err := common .SnapshotIDToProjectKey (cleanSelfLink (snapshot .SelfLink ))
917
+ Expect (err ).To (BeNil (), "Failed to parse snapshot ID" )
918
+ Expect (snapshotType ).To (Equal (common .DiskImageType ), "Expected images type in snapshot ID" )
919
+
920
+ defer func () {
921
+ // Delete Disk
922
+ err := client .DeleteVolume (volID )
923
+ Expect (err ).To (BeNil (), "DeleteVolume failed" )
924
+
925
+ // Validate Disk Deleted
926
+ _ , err = computeService .Disks .Get (p , z , volName ).Do ()
927
+ Expect (gce .IsGCEError (err , "notFound" )).To (BeTrue (), "Expected disk to not be found" )
928
+
929
+ // Delete Snapshot
930
+ err = client .DeleteSnapshot (snapshotID )
931
+ Expect (err ).To (BeNil (), "DeleteSnapshot failed" )
932
+
933
+ // Validate Snapshot Deleted
934
+ _ , err = computeService .Snapshots .Get (p , snapshotName ).Do ()
935
+ Expect (gce .IsGCEError (err , "notFound" )).To (BeTrue (), "Expected snapshot to not be found" )
936
+ }()
937
+ })
879
938
})
880
939
881
940
func equalWithinEpsilon (a , b , epsiolon int64 ) bool {
@@ -955,3 +1014,9 @@ func createAndValidateUniqueZonalMultiWriterDisk(client *remote.CsiClient, proje
955
1014
956
1015
return volName , volID
957
1016
}
1017
+
1018
+ func cleanSelfLink (selfLink string ) string {
1019
+ temp := strings .TrimPrefix (selfLink , gce .GCEComputeAPIEndpoint )
1020
+ temp = strings .TrimPrefix (temp , gce .GCEComputeBetaAPIEndpoint )
1021
+ return strings .TrimPrefix (temp , gce .GCEComputeAlphaAPIEndpoint )
1022
+ }
0 commit comments