mirror of https://github.com/k3s-io/k3s
Merge pull request #35560 from jingxu97/Oct/pd-tests
Automatic merge from submit-queue Add a retry when reading a file content from a container To avoid temporal failure in reading the file content, add a retry process in function verifyPDContentsViaContainerpull/6/head
commit
2f4cdd3f7e
|
@ -49,6 +49,7 @@ const (
|
|||
nodeStatusPollTime = 1 * time.Second
|
||||
gcePDRetryTimeout = 5 * time.Minute
|
||||
gcePDRetryPollTime = 5 * time.Second
|
||||
maxReadRetry = 3
|
||||
)
|
||||
|
||||
var _ = framework.KubeDescribe("Pod Disks", func() {
|
||||
|
@ -450,20 +451,28 @@ func deletePDWithRetry(diskName string) {
|
|||
|
||||
func verifyPDContentsViaContainer(f *framework.Framework, podName, containerName string, fileAndContentToVerify map[string]string) {
|
||||
for filePath, expectedContents := range fileAndContentToVerify {
|
||||
var value string
|
||||
// Add a retry to avoid temporal failure in reading the content
|
||||
for i := 0; i < maxReadRetry; i++ {
|
||||
v, err := f.ReadFileViaContainer(podName, containerName, filePath)
|
||||
value = v
|
||||
if err != nil {
|
||||
framework.Logf("Error reading file: %v", err)
|
||||
}
|
||||
framework.ExpectNoError(err)
|
||||
framework.Logf("Read file %q with content: %v", filePath, v)
|
||||
framework.Logf("Read file %q with content: %v (iteration %d)", filePath, v, i)
|
||||
if strings.TrimSpace(v) != strings.TrimSpace(expectedContents) {
|
||||
framework.Logf("Warning: read content <%q> does not match execpted content <%q>.", v, expectedContents)
|
||||
size, err := f.CheckFileSizeViaContainer(podName, containerName, filePath)
|
||||
if err != nil {
|
||||
framework.Logf("Error reading file: %v", err)
|
||||
framework.Logf("Error checking file size: %v", err)
|
||||
}
|
||||
framework.Logf("Check file %q size: %q", filePath, size)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
Expect(strings.TrimSpace(v)).To(Equal(strings.TrimSpace(expectedContents)))
|
||||
}
|
||||
Expect(strings.TrimSpace(value)).To(Equal(strings.TrimSpace(expectedContents)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue