Skip to content

Commit 104db4f

Browse files
committed
Fix block snapshot tests
Use InjectContent / TestVolumeClient to test a snapshot volume, since these functions support raw block volumes.
1 parent 39ed64e commit 104db4f

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

test/e2e/storage/testsuites/provisioning.go

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,23 @@ func (p *provisioningTestSuite) DefineTests(driver TestDriver, pattern testpatte
213213

214214
dc := l.config.Framework.DynamicClient
215215
vsc := sDriver.GetSnapshotClass(l.config)
216-
dataSource, cleanupFunc := prepareSnapshotDataSourceForProvisioning(l.config.ClientNodeSelection, l.cs, dc, l.pvc, l.sc, vsc)
216+
testConfig := convertTestConfig(l.config)
217+
expectedContent := fmt.Sprintf("Hello from namespace %s", f.Namespace.Name)
218+
dataSource, cleanupFunc := prepareSnapshotDataSourceForProvisioning(f, testConfig, l.cs, dc, l.pvc, l.sc, vsc, pattern.VolMode, expectedContent)
217219
defer cleanupFunc()
218220

219221
l.pvc.Spec.DataSource = dataSource
220222
l.testCase.PvCheck = func(claim *v1.PersistentVolumeClaim) {
221223
ginkgo.By("checking whether the created volume has the pre-populated data")
222-
command := fmt.Sprintf("grep '%s' /mnt/test/initialData", claim.Namespace)
223-
RunInPodWithVolume(l.cs, claim.Namespace, claim.Name, "pvc-snapshot-tester", command, l.config.ClientNodeSelection)
224+
tests := []volume.Test{
225+
{
226+
Volume: *createVolumeSource(claim.Name, false /* readOnly */),
227+
Mode: pattern.VolMode,
228+
File: "index.html",
229+
ExpectedContent: expectedContent,
230+
},
231+
}
232+
volume.TestVolumeClient(f, testConfig, nil, "", tests)
224233
}
225234
l.testCase.TestDynamicProvisioning()
226235
})
@@ -698,12 +707,15 @@ func verifyPVCsPending(client clientset.Interface, pvcs []*v1.PersistentVolumeCl
698707
}
699708

700709
func prepareSnapshotDataSourceForProvisioning(
701-
node e2epod.NodeSelection,
710+
f *framework.Framework,
711+
config volume.TestConfig,
702712
client clientset.Interface,
703713
dynamicClient dynamic.Interface,
704714
initClaim *v1.PersistentVolumeClaim,
705715
class *storagev1.StorageClass,
706716
snapshotClass *unstructured.Unstructured,
717+
mode v1.PersistentVolumeMode,
718+
injectContent string,
707719
) (*v1.TypedLocalObjectReference, func()) {
708720
var err error
709721
if class != nil {
@@ -717,20 +729,19 @@ func prepareSnapshotDataSourceForProvisioning(
717729
framework.ExpectNoError(err)
718730

719731
// write namespace to the /mnt/test (= the volume).
720-
ginkgo.By("[Initialize dataSource]write data to volume")
721-
command := fmt.Sprintf("echo '%s' > /mnt/test/initialData", updatedClaim.GetNamespace())
722-
RunInPodWithVolume(client, updatedClaim.Namespace, updatedClaim.Name, "pvc-snapshot-writer", command, node)
723-
724-
err = e2epv.WaitForPersistentVolumeClaimPhase(v1.ClaimBound, client, updatedClaim.Namespace, updatedClaim.Name, framework.Poll, framework.ClaimProvisionTimeout)
725-
framework.ExpectNoError(err)
726-
727-
ginkgo.By("[Initialize dataSource]checking the initClaim")
728-
// Get new copy of the initClaim
729-
_, err = client.CoreV1().PersistentVolumeClaims(updatedClaim.Namespace).Get(context.TODO(), updatedClaim.Name, metav1.GetOptions{})
730-
framework.ExpectNoError(err)
732+
tests := []volume.Test{
733+
{
734+
Volume: *createVolumeSource(updatedClaim.Name, false /* readOnly */),
735+
Mode: mode,
736+
File: "index.html",
737+
ExpectedContent: injectContent,
738+
},
739+
}
740+
volume.InjectContent(f, config, nil, "", tests)
731741

732742
ginkgo.By("[Initialize dataSource]creating a SnapshotClass")
733743
snapshotClass, err = dynamicClient.Resource(snapshotClassGVR).Create(snapshotClass, metav1.CreateOptions{})
744+
framework.ExpectNoError(err)
734745

735746
ginkgo.By("[Initialize dataSource]creating a snapshot")
736747
snapshot := getSnapshot(updatedClaim.Name, updatedClaim.Namespace, snapshotClass.GetName())

0 commit comments

Comments
 (0)