@@ -620,6 +620,8 @@ func provisionMockServerSetupExpectations(identityServer *driver.MockIdentitySer
620
620
}, nil ).Times (1 )
621
621
}
622
622
623
+ // provisionFromSnapshotMockServerSetupExpectations mocks plugin and controller capabilities reported
624
+ // by a CSI plugin that supports the snapshot feature
623
625
func provisionFromSnapshotMockServerSetupExpectations (identityServer * driver.MockIdentityServer , controllerServer * driver.MockControllerServer ) {
624
626
identityServer .EXPECT ().GetPluginCapabilities (gomock .Any (), gomock .Any ()).Return (& csi.GetPluginCapabilitiesResponse {
625
627
Capabilities : []* csi.PluginCapability {
@@ -1166,7 +1168,7 @@ func TestProvisionFromSnapshot(t *testing.T) {
1166
1168
volOpts controller.VolumeOptions
1167
1169
restoredVolSizeSmall bool
1168
1170
wrongDataSource bool
1169
- validSnapshotStatus bool
1171
+ snapshotStatusReady bool
1170
1172
expectedPVSpec * pvSpec
1171
1173
expectErr bool
1172
1174
}{
@@ -1195,7 +1197,7 @@ func TestProvisionFromSnapshot(t *testing.T) {
1195
1197
},
1196
1198
Parameters : map [string ]string {},
1197
1199
},
1198
- validSnapshotStatus : true ,
1200
+ snapshotStatusReady : true ,
1199
1201
expectedPVSpec : & pvSpec {
1200
1202
Name : "test-testi" ,
1201
1203
ReclaimPolicy : v1 .PersistentVolumeReclaimDelete ,
@@ -1238,7 +1240,7 @@ func TestProvisionFromSnapshot(t *testing.T) {
1238
1240
Parameters : map [string ]string {},
1239
1241
},
1240
1242
restoredVolSizeSmall : true ,
1241
- validSnapshotStatus : true ,
1243
+ snapshotStatusReady : true ,
1242
1244
expectErr : true ,
1243
1245
},
1244
1246
"fail empty snapshot name" : {
@@ -1346,7 +1348,7 @@ func TestProvisionFromSnapshot(t *testing.T) {
1346
1348
},
1347
1349
Parameters : map [string ]string {},
1348
1350
},
1349
- validSnapshotStatus : false ,
1351
+ snapshotStatusReady : false ,
1350
1352
expectErr : true ,
1351
1353
},
1352
1354
}
@@ -1364,7 +1366,7 @@ func TestProvisionFromSnapshot(t *testing.T) {
1364
1366
client := & fake.Clientset {}
1365
1367
1366
1368
client .AddReactor ("get" , "volumesnapshots" , func (action k8stesting.Action ) (handled bool , ret runtime.Object , err error ) {
1367
- snap := newSnapshot (snapName , snapClassName , "snapcontent-snapuid" , "snapuid" , "claim" , tc .validSnapshotStatus , nil , metaTimeNowUnix , resource .NewQuantity (requestedBytes , resource .BinarySI ))
1369
+ snap := newSnapshot (snapName , snapClassName , "snapcontent-snapuid" , "snapuid" , "claim" , tc .snapshotStatusReady , nil , metaTimeNowUnix , resource .NewQuantity (requestedBytes , resource .BinarySI ))
1368
1370
return true , snap , nil
1369
1371
})
1370
1372
@@ -1382,11 +1384,19 @@ func TestProvisionFromSnapshot(t *testing.T) {
1382
1384
},
1383
1385
}
1384
1386
1385
- // Setup mock call expectations.
1387
+ // Setup mock call expectations. If tc.wrongDataSource is false, DataSource is valid
1388
+ // and the controller will proceed to check whether the plugin supports snapshot.
1389
+ // So in this case, we need the plugin to report snapshot support capabilities;
1390
+ // Otherwise, the controller will fail the operation so it won't check the capabilities.
1386
1391
if tc .wrongDataSource == false {
1387
1392
provisionFromSnapshotMockServerSetupExpectations (identityServer , controllerServer )
1388
1393
}
1389
- if tc .restoredVolSizeSmall == false && tc .wrongDataSource == false && tc .validSnapshotStatus {
1394
+ // If tc.restoredVolSizeSmall is true, or tc.wrongDataSource is true, or
1395
+ // tc.snapshotStatusReady is false, create volume from snapshot operation will fail
1396
+ // early and therefore CreateVolume is not expected to be called.
1397
+ // When the following if condition is met, it is a valid create volume from snapshot
1398
+ // operation and CreateVolume is expected to be called.
1399
+ if tc .restoredVolSizeSmall == false && tc .wrongDataSource == false && tc .snapshotStatusReady {
1390
1400
controllerServer .EXPECT ().CreateVolume (gomock .Any (), gomock .Any ()).Return (out , nil ).Times (1 )
1391
1401
}
1392
1402
0 commit comments