@@ -35,6 +35,7 @@ import (
35
35
. "github.com/onsi/ginkgo"
36
36
. "github.com/onsi/gomega"
37
37
38
+ compute "google.golang.org/api/compute/v1"
38
39
"google.golang.org/api/iterator"
39
40
kmspb "google.golang.org/genproto/googleapis/cloud/kms/v1"
40
41
fieldmask "google.golang.org/genproto/protobuf/field_mask"
@@ -257,7 +258,6 @@ var _ = Describe("GCE PD CSI Driver", func() {
257
258
_ , err = computeService .Disks .Get (p , zone , volName ).Do ()
258
259
Expect (err ).To (BeNil (), "Could not find disk in correct zone" )
259
260
}
260
-
261
261
})
262
262
263
263
It ("Should complete entire disk lifecycle with underspecified volume ID" , func () {
@@ -284,7 +284,40 @@ var _ = Describe("GCE PD CSI Driver", func() {
284
284
// Attach Disk
285
285
err := testAttachWriteReadDetach (underSpecifiedID , volName , instance , client , false /* readOnly */ )
286
286
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" )
287
304
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" )
288
321
})
289
322
290
323
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 {
1122
1155
return b - a < epsiolon
1123
1156
}
1124
1157
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 ) {
1126
1159
// 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 ,
1130
1163
& csi.TopologyRequirement {
1131
1164
Requisite : []* csi.Topology {
1132
1165
{
@@ -1139,11 +1172,12 @@ func createAndValidateUniqueZonalDisk(client *remote.CsiClient, project, zone st
1139
1172
// Validate Disk Created
1140
1173
cloudDisk , err := computeService .Disks .Get (project , zone , volName ).Do ()
1141
1174
Expect (err ).To (BeNil (), "Could not get disk from cloud directly" )
1142
- Expect (cloudDisk .Type ).To (ContainSubstring (diskType ))
1143
1175
Expect (cloudDisk .Status ).To (Equal (readyState ))
1144
1176
Expect (cloudDisk .SizeGb ).To (Equal (defaultSizeGb ))
1145
1177
Expect (cloudDisk .Name ).To (Equal (volName ))
1146
- return
1178
+ disk .validate (cloudDisk )
1179
+
1180
+ return volName , volID
1147
1181
}
1148
1182
1149
1183
func deleteVolumeOrError (client * remote.CsiClient , volID string ) {
@@ -1160,8 +1194,9 @@ func deleteVolumeOrError(client *remote.CsiClient, volID string) {
1160
1194
1161
1195
func createAndValidateUniqueZonalMultiWriterDisk (client * remote.CsiClient , project , zone string , diskType string ) (string , string ) {
1162
1196
// Create Disk
1197
+ disk := typeToDisk [diskType ]
1163
1198
volName := testNamePrefix + string (uuid .NewUUID ())
1164
- volID , err := client .CreateVolumeWithCaps (volName , nil , defaultMwSizeGb ,
1199
+ volID , err := client .CreateVolumeWithCaps (volName , disk . params , defaultMwSizeGb ,
1165
1200
& csi.TopologyRequirement {
1166
1201
Requisite : []* csi.Topology {
1167
1202
{
@@ -1182,13 +1217,16 @@ func createAndValidateUniqueZonalMultiWriterDisk(client *remote.CsiClient, proje
1182
1217
Expect (err ).To (BeNil (), "CreateVolume failed with error: %v" , err )
1183
1218
1184
1219
// 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" )
1188
1222
Expect (cloudDisk .Status ).To (Equal (readyState ))
1189
1223
Expect (cloudDisk .SizeGb ).To (Equal (defaultMwSizeGb ))
1190
1224
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 ))
1192
1230
1193
1231
return volName , volID
1194
1232
}
@@ -1247,3 +1285,29 @@ func setupKeyRing(ctx context.Context, parentName string, keyRingId string) (*km
1247
1285
}
1248
1286
return key , keyVersions
1249
1287
}
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