Merge pull request #105217 from dbgoytia/refactor/102787-enable-block-tests

Refactoring TestConcurrentAccessToRelatedVolumes for enabling Block Volume tests
This commit is contained in:
Kubernetes Prow Robot 2021-10-05 14:18:57 -07:00 committed by GitHub
commit 4af19756bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 22 deletions

View File

@ -454,7 +454,7 @@ func testVolumeContent(f *framework.Framework, pod *v1.Pod, fsGroup *int64, fsTy
if test.Mode == v1.PersistentVolumeBlock {
// Block: check content
deviceName := fmt.Sprintf("/opt/%d", i)
commands := generateReadBlockCmd(deviceName, len(test.ExpectedContent))
commands := GenerateReadBlockCmd(deviceName, len(test.ExpectedContent))
_, err := framework.LookForStringInPodExec(pod.Namespace, pod.Name, commands, test.ExpectedContent, time.Minute)
framework.ExpectNoError(err, "failed: finding the contents of the block device %s.", deviceName)
@ -573,7 +573,7 @@ func generateWriteCmd(content, path string) []string {
}
// generateReadBlockCmd generates the corresponding command lines to read from a block device with the given file path.
func generateReadBlockCmd(fullPath string, numberOfCharacters int) []string {
func GenerateReadBlockCmd(fullPath string, numberOfCharacters int) []string {
var commands []string
commands = []string{"head", "-c", strconv.Itoa(numberOfCharacters), fullPath}
return commands

View File

@ -328,12 +328,6 @@ func (t *multiVolumeTestSuite) DefineTests(driver storageframework.TestDriver, p
if pattern.SnapshotType == "" {
e2eskipper.Skipf("Driver %q does not support snapshots - skipping", dInfo.Name)
}
if pattern.VolMode == v1.PersistentVolumeBlock {
// TODO: refactor prepareSnapshotDataSourceForProvisioning() below to use
// utils.CheckWriteToPath / utils.CheckReadFromPath and remove
// redundant InjectContent(). This will enable block volume tests.
e2eskipper.Skipf("This test does not support block volumes -- skipping")
}
// Create a volume
testVolumeSizeRange := t.GetTestSuiteInfo().SupportedSizeRange
@ -386,12 +380,6 @@ func (t *multiVolumeTestSuite) DefineTests(driver storageframework.TestDriver, p
if !l.driver.GetDriverInfo().Capabilities[storageframework.CapPVCDataSource] {
e2eskipper.Skipf("Driver %q does not support volume clone - skipping", dInfo.Name)
}
if pattern.VolMode == v1.PersistentVolumeBlock {
// TODO: refactor preparePVCDataSourceForProvisioning() below to use
// utils.CheckWriteToPath / utils.CheckReadFromPath and remove
// redundant InjectContent(). This will enable block volume tests.
e2eskipper.Skipf("This test does not support block volumes -- skipping")
}
// Create a volume
expectedContent := fmt.Sprintf("volume content %d", time.Now().UTC().UnixNano())
@ -711,17 +699,28 @@ func TestConcurrentAccessToRelatedVolumes(f *framework.Framework, cs clientset.I
e2epod.SetAffinity(&node, actualNodeName)
}
// Check that all pods the same content
for i, pod := range pods {
fileName := "/mnt/volume1/index.html"
index := i + 1
for i, pvc := range pvcs {
var commands []string
if *pvc.Spec.VolumeMode == v1.PersistentVolumeBlock {
fileName := "/mnt/volume1"
commands = e2evolume.GenerateReadBlockCmd(fileName, len(expectedContent))
// Check that all pods have the same content
index := i + 1
ginkgo.By(fmt.Sprintf("Checking if the volume in pod%d has expected initial content", index))
commands := e2evolume.GenerateReadFileCmd(fileName)
_, err := framework.LookForStringInPodExec(pod.Namespace, pod.Name, commands, expectedContent, time.Minute)
_, err := framework.LookForStringInPodExec(pods[i].Namespace, pods[i].Name, commands, expectedContent, time.Minute)
framework.ExpectNoError(err, "failed: finding the contents of the block volume %s.", fileName)
} else {
fileName := "/mnt/volume1/index.html"
commands = e2evolume.GenerateReadFileCmd(fileName)
// Check that all pods have the same content
index := i + 1
ginkgo.By(fmt.Sprintf("Checking if the volume in pod%d has expected initial content", index))
_, err := framework.LookForStringInPodExec(pods[i].Namespace, pods[i].Name, commands, expectedContent, time.Minute)
framework.ExpectNoError(err, "failed: finding the contents of the mounted file %s.", fileName)
}
}
}
// getCurrentTopologies() goes through all Nodes and returns unique driver topologies and count of Nodes per topology
func getCurrentTopologiesNumber(cs clientset.Interface, nodes *v1.NodeList, keys []string) ([]topology, []int, error) {