@@ -35,6 +35,7 @@ import (
3535 . "github.com/onsi/ginkgo"
3636 . "github.com/onsi/gomega"
3737
38+ compute "google.golang.org/api/compute/v1"
3839 "google.golang.org/api/iterator"
3940 kmspb "google.golang.org/genproto/googleapis/cloud/kms/v1"
4041 fieldmask "google.golang.org/genproto/protobuf/field_mask"
@@ -257,7 +258,6 @@ var _ = Describe("GCE PD CSI Driver", func() {
257258 _ , err = computeService .Disks .Get (p , zone , volName ).Do ()
258259 Expect (err ).To (BeNil (), "Could not find disk in correct zone" )
259260 }
260-
261261 })
262262
263263 It ("Should complete entire disk lifecycle with underspecified volume ID" , func () {
@@ -284,7 +284,40 @@ var _ = Describe("GCE PD CSI Driver", func() {
284284 // Attach Disk
285285 err := testAttachWriteReadDetach (underSpecifiedID , volName , instance , client , false /* readOnly */ )
286286 Expect (err ).To (BeNil (), "Failed to go through volume lifecycle" )
287+ })
288+
289+ It ("Should complete publish/unpublish lifecycle with underspecified volume ID and missing volume" , func () {
290+ testContext := getRandomTestContext ()
291+
292+ p , z , _ := testContext .Instance .GetIdentity ()
293+ client := testContext .Client
294+ instance := testContext .Instance
295+
296+ // Create Disk
297+ volName , _ := createAndValidateUniqueZonalDisk (client , p , z , standardDiskType )
298+ underSpecifiedID := common .GenerateUnderspecifiedVolumeID (volName , true /* isZonal */ )
299+
300+ defer func () {
301+ // Detach Disk
302+ err := instance .DetachDisk (volName )
303+ Expect (err ).To (BeNil (), "DetachDisk failed" )
287304
305+ // Delete Disk
306+ err = client .DeleteVolume (underSpecifiedID )
307+ Expect (err ).To (BeNil (), "DeleteVolume failed" )
308+
309+ // Validate Disk Deleted
310+ _ , err = computeService .Disks .Get (p , z , volName ).Do ()
311+ Expect (gce .IsGCEError (err , "notFound" )).To (BeTrue (), "Expected disk to not be found" )
312+
313+ // Unpublish Disk
314+ err = client .ControllerUnpublishVolume (underSpecifiedID , instance .GetNodeID ())
315+ Expect (err ).To (BeNil (), "ControllerUnpublishVolume failed" )
316+ }()
317+
318+ // Attach Disk
319+ err := client .ControllerPublishVolume (underSpecifiedID , instance .GetNodeID ())
320+ Expect (err ).To (BeNil (), "ControllerPublishVolume failed" )
288321 })
289322
290323 It ("Should successfully create RePD in two zones in the drivers region when none are specified" , func () {
@@ -1122,11 +1155,11 @@ func equalWithinEpsilon(a, b, epsiolon int64) bool {
11221155 return b - a < epsiolon
11231156}
11241157
1125- func createAndValidateUniqueZonalDisk (client * remote.CsiClient , project , zone string , diskType string ) (volName , volID string ) {
1158+ func createAndValidateUniqueZonalDisk (client * remote.CsiClient , project , zone string , diskType string ) (string , string ) {
11261159 // Create Disk
1127- var err error
1128- volName = testNamePrefix + string (uuid .NewUUID ())
1129- volID , err = client .CreateVolume (volName , nil , defaultSizeGb ,
1160+ disk := typeToDisk [ diskType ]
1161+ volName : = testNamePrefix + string (uuid .NewUUID ())
1162+ volID , err : = client .CreateVolume (volName , disk . params , defaultSizeGb ,
11301163 & csi.TopologyRequirement {
11311164 Requisite : []* csi.Topology {
11321165 {
@@ -1139,11 +1172,12 @@ func createAndValidateUniqueZonalDisk(client *remote.CsiClient, project, zone st
11391172 // Validate Disk Created
11401173 cloudDisk , err := computeService .Disks .Get (project , zone , volName ).Do ()
11411174 Expect (err ).To (BeNil (), "Could not get disk from cloud directly" )
1142- Expect (cloudDisk .Type ).To (ContainSubstring (diskType ))
11431175 Expect (cloudDisk .Status ).To (Equal (readyState ))
11441176 Expect (cloudDisk .SizeGb ).To (Equal (defaultSizeGb ))
11451177 Expect (cloudDisk .Name ).To (Equal (volName ))
1146- return
1178+ disk .validate (cloudDisk )
1179+
1180+ return volName , volID
11471181}
11481182
11491183func deleteVolumeOrError (client * remote.CsiClient , volID string ) {
@@ -1160,8 +1194,9 @@ func deleteVolumeOrError(client *remote.CsiClient, volID string) {
11601194
11611195func createAndValidateUniqueZonalMultiWriterDisk (client * remote.CsiClient , project , zone string , diskType string ) (string , string ) {
11621196 // Create Disk
1197+ disk := typeToDisk [diskType ]
11631198 volName := testNamePrefix + string (uuid .NewUUID ())
1164- volID , err := client .CreateVolumeWithCaps (volName , nil , defaultMwSizeGb ,
1199+ volID , err := client .CreateVolumeWithCaps (volName , disk . params , defaultMwSizeGb ,
11651200 & csi.TopologyRequirement {
11661201 Requisite : []* csi.Topology {
11671202 {
@@ -1182,13 +1217,16 @@ func createAndValidateUniqueZonalMultiWriterDisk(client *remote.CsiClient, proje
11821217 Expect (err ).To (BeNil (), "CreateVolume failed with error: %v" , err )
11831218
11841219 // Validate Disk Created
1185- cloudDisk , err := computeAlphaService .Disks .Get (project , zone , volName ).Do ()
1186- Expect (err ).To (BeNil (), "Could not get disk from cloud directly" )
1187- Expect (cloudDisk .Type ).To (ContainSubstring (diskType ))
1220+ cloudDisk , err := computeService .Disks .Get (project , zone , volName ).Do ()
1221+ Expect (err ).To (BeNil (), "Failed to get cloud disk" )
11881222 Expect (cloudDisk .Status ).To (Equal (readyState ))
11891223 Expect (cloudDisk .SizeGb ).To (Equal (defaultMwSizeGb ))
11901224 Expect (cloudDisk .Name ).To (Equal (volName ))
1191- Expect (cloudDisk .MultiWriter ).To (Equal (true ))
1225+ disk .validate (cloudDisk )
1226+
1227+ alphaDisk , err := computeAlphaService .Disks .Get (project , zone , volName ).Do ()
1228+ Expect (err ).To (BeNil (), "Failed to get cloud disk using alpha API" )
1229+ Expect (alphaDisk .MultiWriter ).To (Equal (true ))
11921230
11931231 return volName , volID
11941232}
@@ -1247,3 +1285,29 @@ func setupKeyRing(ctx context.Context, parentName string, keyRingId string) (*km
12471285 }
12481286 return key , keyVersions
12491287}
1288+
1289+ type disk struct {
1290+ params map [string ]string
1291+ validate func (disk * compute.Disk )
1292+ }
1293+
1294+ var typeToDisk = map [string ]* disk {
1295+ standardDiskType : {
1296+ params : map [string ]string {
1297+ common .ParameterKeyType : standardDiskType ,
1298+ },
1299+ validate : func (disk * compute.Disk ) {
1300+ Expect (disk .Type ).To (ContainSubstring (standardDiskType ))
1301+ },
1302+ },
1303+ extremeDiskType : {
1304+ params : map [string ]string {
1305+ common .ParameterKeyType : extremeDiskType ,
1306+ common .ParameterKeyProvisionedIOPSOnCreate : provisionedIOPSOnCreate ,
1307+ },
1308+ validate : func (disk * compute.Disk ) {
1309+ Expect (disk .Type ).To (ContainSubstring (extremeDiskType ))
1310+ Expect (disk .ProvisionedIops ).To (Equal (provisionedIOPSOnCreateInt ))
1311+ },
1312+ },
1313+ }
0 commit comments