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 verifyPDContentsViaContainer
pull/6/head
Jing Xu 2016-10-11 13:22:06 -07:00
parent ead65fc25f
commit 837fde7cd9
1 changed files with 19 additions and 10 deletions

View File

@ -49,6 +49,7 @@ const (
nodeStatusPollTime = 1 * time.Second nodeStatusPollTime = 1 * time.Second
gcePDRetryTimeout = 5 * time.Minute gcePDRetryTimeout = 5 * time.Minute
gcePDRetryPollTime = 5 * time.Second gcePDRetryPollTime = 5 * time.Second
maxReadRetry = 3
) )
var _ = framework.KubeDescribe("Pod Disks", func() { 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) { func verifyPDContentsViaContainer(f *framework.Framework, podName, containerName string, fileAndContentToVerify map[string]string) {
for filePath, expectedContents := range fileAndContentToVerify { for filePath, expectedContents := range fileAndContentToVerify {
v, err := f.ReadFileViaContainer(podName, containerName, filePath) var value string
if err != nil { // Add a retry to avoid temporal failure in reading the content
framework.Logf("Error reading file: %v", err) for i := 0; i < maxReadRetry; i++ {
} v, err := f.ReadFileViaContainer(podName, containerName, filePath)
framework.ExpectNoError(err) value = v
framework.Logf("Read file %q with content: %v", filePath, v)
if strings.TrimSpace(v) != strings.TrimSpace(expectedContents) {
size, err := f.CheckFileSizeViaContainer(podName, containerName, filePath)
if err != nil { if err != nil {
framework.Logf("Error reading file: %v", err) framework.Logf("Error reading file: %v", err)
} }
framework.Logf("Check file %q size: %q", filePath, size) framework.ExpectNoError(err)
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 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)))
} }
} }