mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Fix block snapshot tests
Use InjectContent / TestVolumeClient to test a snapshot volume, since these functions support raw block volumes.
This commit is contained in:
parent
39ed64ec4c
commit
104db4f01b
@ -213,14 +213,23 @@ func (p *provisioningTestSuite) DefineTests(driver TestDriver, pattern testpatte
|
|||||||
|
|
||||||
dc := l.config.Framework.DynamicClient
|
dc := l.config.Framework.DynamicClient
|
||||||
vsc := sDriver.GetSnapshotClass(l.config)
|
vsc := sDriver.GetSnapshotClass(l.config)
|
||||||
dataSource, cleanupFunc := prepareSnapshotDataSourceForProvisioning(l.config.ClientNodeSelection, l.cs, dc, l.pvc, l.sc, vsc)
|
testConfig := convertTestConfig(l.config)
|
||||||
|
expectedContent := fmt.Sprintf("Hello from namespace %s", f.Namespace.Name)
|
||||||
|
dataSource, cleanupFunc := prepareSnapshotDataSourceForProvisioning(f, testConfig, l.cs, dc, l.pvc, l.sc, vsc, pattern.VolMode, expectedContent)
|
||||||
defer cleanupFunc()
|
defer cleanupFunc()
|
||||||
|
|
||||||
l.pvc.Spec.DataSource = dataSource
|
l.pvc.Spec.DataSource = dataSource
|
||||||
l.testCase.PvCheck = func(claim *v1.PersistentVolumeClaim) {
|
l.testCase.PvCheck = func(claim *v1.PersistentVolumeClaim) {
|
||||||
ginkgo.By("checking whether the created volume has the pre-populated data")
|
ginkgo.By("checking whether the created volume has the pre-populated data")
|
||||||
command := fmt.Sprintf("grep '%s' /mnt/test/initialData", claim.Namespace)
|
tests := []volume.Test{
|
||||||
RunInPodWithVolume(l.cs, claim.Namespace, claim.Name, "pvc-snapshot-tester", command, l.config.ClientNodeSelection)
|
{
|
||||||
|
Volume: *createVolumeSource(claim.Name, false /* readOnly */),
|
||||||
|
Mode: pattern.VolMode,
|
||||||
|
File: "index.html",
|
||||||
|
ExpectedContent: expectedContent,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
volume.TestVolumeClient(f, testConfig, nil, "", tests)
|
||||||
}
|
}
|
||||||
l.testCase.TestDynamicProvisioning()
|
l.testCase.TestDynamicProvisioning()
|
||||||
})
|
})
|
||||||
@ -698,12 +707,15 @@ func verifyPVCsPending(client clientset.Interface, pvcs []*v1.PersistentVolumeCl
|
|||||||
}
|
}
|
||||||
|
|
||||||
func prepareSnapshotDataSourceForProvisioning(
|
func prepareSnapshotDataSourceForProvisioning(
|
||||||
node e2epod.NodeSelection,
|
f *framework.Framework,
|
||||||
|
config volume.TestConfig,
|
||||||
client clientset.Interface,
|
client clientset.Interface,
|
||||||
dynamicClient dynamic.Interface,
|
dynamicClient dynamic.Interface,
|
||||||
initClaim *v1.PersistentVolumeClaim,
|
initClaim *v1.PersistentVolumeClaim,
|
||||||
class *storagev1.StorageClass,
|
class *storagev1.StorageClass,
|
||||||
snapshotClass *unstructured.Unstructured,
|
snapshotClass *unstructured.Unstructured,
|
||||||
|
mode v1.PersistentVolumeMode,
|
||||||
|
injectContent string,
|
||||||
) (*v1.TypedLocalObjectReference, func()) {
|
) (*v1.TypedLocalObjectReference, func()) {
|
||||||
var err error
|
var err error
|
||||||
if class != nil {
|
if class != nil {
|
||||||
@ -717,20 +729,19 @@ func prepareSnapshotDataSourceForProvisioning(
|
|||||||
framework.ExpectNoError(err)
|
framework.ExpectNoError(err)
|
||||||
|
|
||||||
// write namespace to the /mnt/test (= the volume).
|
// write namespace to the /mnt/test (= the volume).
|
||||||
ginkgo.By("[Initialize dataSource]write data to volume")
|
tests := []volume.Test{
|
||||||
command := fmt.Sprintf("echo '%s' > /mnt/test/initialData", updatedClaim.GetNamespace())
|
{
|
||||||
RunInPodWithVolume(client, updatedClaim.Namespace, updatedClaim.Name, "pvc-snapshot-writer", command, node)
|
Volume: *createVolumeSource(updatedClaim.Name, false /* readOnly */),
|
||||||
|
Mode: mode,
|
||||||
err = e2epv.WaitForPersistentVolumeClaimPhase(v1.ClaimBound, client, updatedClaim.Namespace, updatedClaim.Name, framework.Poll, framework.ClaimProvisionTimeout)
|
File: "index.html",
|
||||||
framework.ExpectNoError(err)
|
ExpectedContent: injectContent,
|
||||||
|
},
|
||||||
ginkgo.By("[Initialize dataSource]checking the initClaim")
|
}
|
||||||
// Get new copy of the initClaim
|
volume.InjectContent(f, config, nil, "", tests)
|
||||||
_, err = client.CoreV1().PersistentVolumeClaims(updatedClaim.Namespace).Get(context.TODO(), updatedClaim.Name, metav1.GetOptions{})
|
|
||||||
framework.ExpectNoError(err)
|
|
||||||
|
|
||||||
ginkgo.By("[Initialize dataSource]creating a SnapshotClass")
|
ginkgo.By("[Initialize dataSource]creating a SnapshotClass")
|
||||||
snapshotClass, err = dynamicClient.Resource(snapshotClassGVR).Create(snapshotClass, metav1.CreateOptions{})
|
snapshotClass, err = dynamicClient.Resource(snapshotClassGVR).Create(snapshotClass, metav1.CreateOptions{})
|
||||||
|
framework.ExpectNoError(err)
|
||||||
|
|
||||||
ginkgo.By("[Initialize dataSource]creating a snapshot")
|
ginkgo.By("[Initialize dataSource]creating a snapshot")
|
||||||
snapshot := getSnapshot(updatedClaim.Name, updatedClaim.Namespace, snapshotClass.GetName())
|
snapshot := getSnapshot(updatedClaim.Name, updatedClaim.Namespace, snapshotClass.GetName())
|
||||||
|
Loading…
Reference in New Issue
Block a user