@@ -946,6 +946,65 @@ var _ = Describe("GCE PD CSI Driver", func() {
946
946
Expect (gce .IsGCEError (err , "notFound" )).To (BeTrue (), "Expected snapshot to not be found" )
947
947
}()
948
948
})
949
+
950
+ // Use the region of the test location.
951
+ It ("Should successfully create snapshot backed by disk image" , func () {
952
+ testContext := getRandomTestContext ()
953
+
954
+ p , z , _ := testContext .Instance .GetIdentity ()
955
+ client := testContext .Client
956
+
957
+ // Create Disk
958
+ volName , volID := createAndValidateUniqueZonalDisk (client , p , z )
959
+
960
+ // Create Snapshot
961
+ snapshotName := testNamePrefix + string (uuid .NewUUID ())
962
+ testImageFamily := "test-family"
963
+
964
+ snapshotParams := map [string ]string {common .ParameterKeySnapshotType : common .DiskImageType , common .ParameterKeyImageFamily : testImageFamily }
965
+ snapshotID , err := client .CreateSnapshot (snapshotName , volID , snapshotParams )
966
+ Expect (err ).To (BeNil (), "CreateSnapshot failed with error: %v" , err )
967
+
968
+ // Validate Snapshot Created
969
+ snapshot , err := computeService .Images .Get (p , snapshotName ).Do ()
970
+ Expect (err ).To (BeNil (), "Could not get snapshot from cloud directly" )
971
+ Expect (snapshot .Name ).To (Equal (snapshotName ))
972
+
973
+ err = wait .Poll (10 * time .Second , 5 * time .Minute , func () (bool , error ) {
974
+ snapshot , err := computeService .Images .Get (p , snapshotName ).Do ()
975
+ Expect (err ).To (BeNil (), "Could not get snapshot from cloud directly" )
976
+ if snapshot .Status == "READY" {
977
+ return true , nil
978
+ }
979
+ return false , nil
980
+ })
981
+ Expect (err ).To (BeNil (), "Could not wait for snapshot be ready" )
982
+
983
+ // Check Snapshot Type
984
+ snapshot , err = computeService .Images .Get (p , snapshotName ).Do ()
985
+ Expect (err ).To (BeNil (), "Could not get snapshot from cloud directly" )
986
+ _ , snapshotType , _ , err := common .SnapshotIDToProjectKey (cleanSelfLink (snapshot .SelfLink ))
987
+ Expect (err ).To (BeNil (), "Failed to parse snapshot ID" )
988
+ Expect (snapshotType ).To (Equal (common .DiskImageType ), "Expected images type in snapshot ID" )
989
+
990
+ defer func () {
991
+ // Delete Disk
992
+ err := client .DeleteVolume (volID )
993
+ Expect (err ).To (BeNil (), "DeleteVolume failed" )
994
+
995
+ // Validate Disk Deleted
996
+ _ , err = computeService .Disks .Get (p , z , volName ).Do ()
997
+ Expect (gce .IsGCEError (err , "notFound" )).To (BeTrue (), "Expected disk to not be found" )
998
+
999
+ // Delete Snapshot
1000
+ err = client .DeleteSnapshot (snapshotID )
1001
+ Expect (err ).To (BeNil (), "DeleteSnapshot failed" )
1002
+
1003
+ // Validate Snapshot Deleted
1004
+ _ , err = computeService .Images .Get (p , snapshotName ).Do ()
1005
+ Expect (gce .IsGCEError (err , "notFound" )).To (BeTrue (), "Expected snapshot to not be found" )
1006
+ }()
1007
+ })
949
1008
})
950
1009
951
1010
func equalWithinEpsilon (a , b , epsiolon int64 ) bool {
@@ -1025,3 +1084,9 @@ func createAndValidateUniqueZonalMultiWriterDisk(client *remote.CsiClient, proje
1025
1084
1026
1085
return volName , volID
1027
1086
}
1087
+
1088
+ func cleanSelfLink (selfLink string ) string {
1089
+ temp := strings .TrimPrefix (selfLink , gce .GCEComputeAPIEndpoint )
1090
+ temp = strings .TrimPrefix (temp , gce .GCEComputeBetaAPIEndpoint )
1091
+ return strings .TrimPrefix (temp , gce .GCEComputeAlphaAPIEndpoint )
1092
+ }
0 commit comments