@@ -44,6 +44,7 @@ import (
44
44
type StorageClassTest struct {
45
45
Client clientset.Interface
46
46
Claim * v1.PersistentVolumeClaim
47
+ SourceClaim * v1.PersistentVolumeClaim
47
48
Class * storagev1.StorageClass
48
49
Name string
49
50
CloudProviders []string
@@ -86,10 +87,11 @@ func (p *provisioningTestSuite) defineTests(driver TestDriver, pattern testpatte
86
87
config * PerTestConfig
87
88
testCleanup func ()
88
89
89
- testCase * StorageClassTest
90
- cs clientset.Interface
91
- pvc * v1.PersistentVolumeClaim
92
- sc * storagev1.StorageClass
90
+ testCase * StorageClassTest
91
+ cs clientset.Interface
92
+ pvc * v1.PersistentVolumeClaim
93
+ sourcePVC * v1.PersistentVolumeClaim
94
+ sc * storagev1.StorageClass
93
95
94
96
intreeOps opCounts
95
97
migratedOps opCounts
@@ -134,10 +136,15 @@ func (p *provisioningTestSuite) defineTests(driver TestDriver, pattern testpatte
134
136
ClaimSize : claimSize ,
135
137
StorageClassName : & (l .sc .Name ),
136
138
}, l .config .Framework .Namespace .Name )
137
- e2elog .Logf ("In creating storage class object and pvc object for driver - sc: %v, pvc: %v" , l .sc , l .pvc )
139
+ l .sourcePVC = framework .MakePersistentVolumeClaim (framework.PersistentVolumeClaimConfig {
140
+ ClaimSize : claimSize ,
141
+ StorageClassName : & (l .sc .Name ),
142
+ }, l .config .Framework .Namespace .Name )
143
+ e2elog .Logf ("In creating storage class object and pvc objects for driver - sc: %v, pvc: %v, src-pvc: %v" , l .sc , l .pvc , l .sourcePVC )
138
144
l .testCase = & StorageClassTest {
139
145
Client : l .config .Framework .ClientSet ,
140
146
Claim : l .pvc ,
147
+ SourceClaim : l .sourcePVC ,
141
148
Class : l .sc ,
142
149
ClaimSize : claimSize ,
143
150
ExpectedSize : claimSize ,
@@ -169,21 +176,21 @@ func (p *provisioningTestSuite) defineTests(driver TestDriver, pattern testpatte
169
176
})
170
177
171
178
ginkgo .It ("should provision storage with snapshot data source [Feature:VolumeSnapshotDataSource]" , func () {
172
- if ! dInfo .Capabilities [CapDataSource ] {
179
+ if ! dInfo .Capabilities [CapSnapshotDataSource ] {
173
180
framework .Skipf ("Driver %q does not support populate data from snapshot - skipping" , dInfo .Name )
174
181
}
175
182
176
183
sDriver , ok := driver .(SnapshottableTestDriver )
177
184
if ! ok {
178
- e2elog .Failf ("Driver %q has CapDataSource but does not implement SnapshottableTestDriver" , dInfo .Name )
185
+ e2elog .Failf ("Driver %q has CapSnapshotDataSource but does not implement SnapshottableTestDriver" , dInfo .Name )
179
186
}
180
187
181
188
init ()
182
189
defer cleanup ()
183
190
184
191
dc := l .config .Framework .DynamicClient
185
192
vsc := sDriver .GetSnapshotClass (l .config )
186
- dataSource , cleanupFunc := prepareDataSourceForProvisioning (framework.NodeSelection {Name : l .config .ClientNodeName }, l .cs , dc , l .pvc , l .sc , vsc )
193
+ dataSource , cleanupFunc := prepareSnapshotDataSourceForProvisioning (framework.NodeSelection {Name : l .config .ClientNodeName }, l .cs , dc , l .pvc , l .sc , vsc )
187
194
defer cleanupFunc ()
188
195
189
196
l .pvc .Spec .DataSource = dataSource
@@ -194,6 +201,26 @@ func (p *provisioningTestSuite) defineTests(driver TestDriver, pattern testpatte
194
201
}
195
202
l .testCase .TestDynamicProvisioning ()
196
203
})
204
+ ginkgo .It ("should provision storage with pvc data source [Feature:VolumePVCDataSource]" , func () {
205
+ if ! dInfo .Capabilities [CapPVCDataSource ] {
206
+ framework .Skipf ("Driver %q does not support cloning - skipping" , dInfo .Name )
207
+ }
208
+
209
+ init ()
210
+ defer cleanup ()
211
+
212
+ dc := l .config .Framework .DynamicClient
213
+ dataSource , dataSourceCleanup := preparePVCDataSourceForProvisioning (framework.NodeSelection {Name : l .config .ClientNodeName }, l .cs , dc , l .sourcePVC , l .sc )
214
+ defer dataSourceCleanup ()
215
+
216
+ l .pvc .Spec .DataSource = dataSource
217
+ l .testCase .PvCheck = func (claim * v1.PersistentVolumeClaim ) {
218
+ ginkgo .By ("checking whether the created volume has the pre-populated data" )
219
+ command := fmt .Sprintf ("grep '%s' /mnt/test/initialData" , claim .Namespace )
220
+ RunInPodWithVolume (l .cs , claim .Namespace , claim .Name , "pvc-datasource-tester" , command , framework.NodeSelection {Name : l .config .ClientNodeName })
221
+ }
222
+ l .testCase .TestDynamicProvisioning ()
223
+ })
197
224
}
198
225
199
226
// TestDynamicProvisioning tests dynamic provisioning with specified StorageClassTest
@@ -581,7 +608,7 @@ func verifyPVCsPending(client clientset.Interface, pvcs []*v1.PersistentVolumeCl
581
608
}
582
609
}
583
610
584
- func prepareDataSourceForProvisioning (
611
+ func prepareSnapshotDataSourceForProvisioning (
585
612
node framework.NodeSelection ,
586
613
client clientset.Interface ,
587
614
dynamicClient dynamic.Interface ,
@@ -653,3 +680,42 @@ func prepareDataSourceForProvisioning(
653
680
654
681
return dataSourceRef , cleanupFunc
655
682
}
683
+
684
+ func preparePVCDataSourceForProvisioning (
685
+ node framework.NodeSelection ,
686
+ client clientset.Interface ,
687
+ dynamicClient dynamic.Interface ,
688
+ source * v1.PersistentVolumeClaim ,
689
+ class * storagev1.StorageClass ,
690
+ ) (* v1.TypedLocalObjectReference , func ()) {
691
+ var err error
692
+ if class != nil {
693
+ ginkgo .By ("[Initialize dataSource]creating a StorageClass " + class .Name )
694
+ _ , err = client .StorageV1 ().StorageClasses ().Create (class )
695
+ framework .ExpectNoError (err )
696
+ }
697
+
698
+ ginkgo .By ("[Initialize dataSource]creating a source PVC" )
699
+ sourcePVC , err := client .CoreV1 ().PersistentVolumeClaims (source .Namespace ).Create (source )
700
+ framework .ExpectNoError (err )
701
+
702
+ // write namespace to the /mnt/test (= the volume).
703
+ ginkgo .By ("[Initialize dataSource]write data to volume" )
704
+ command := fmt .Sprintf ("echo '%s' > /mnt/test/initialData" , sourcePVC .GetNamespace ())
705
+ RunInPodWithVolume (client , sourcePVC .Namespace , sourcePVC .Name , "pvc-datasource-writer" , command , node )
706
+
707
+ dataSourceRef := & v1.TypedLocalObjectReference {
708
+ Kind : "PersistentVolumeClaim" ,
709
+ Name : sourcePVC .GetName (),
710
+ }
711
+
712
+ cleanupFunc := func () {
713
+ e2elog .Logf ("deleting source PVC %q/%q" , sourcePVC .Namespace , sourcePVC .Name )
714
+ err = client .CoreV1 ().PersistentVolumeClaims (sourcePVC .Namespace ).Delete (sourcePVC .Name , nil )
715
+ if err != nil && ! apierrs .IsNotFound (err ) {
716
+ e2elog .Failf ("Error deleting source PVC %q. Error: %v" , sourcePVC .Name , err )
717
+ }
718
+ }
719
+
720
+ return dataSourceRef , cleanupFunc
721
+ }
0 commit comments