Merge pull request #33976 from jingxu97/head-10-3

Automatic merge from submit-queue

Add a check for file size if the reading content returns empty

In order to debug the flaky tests for writing/reading files via
contains, this PR adds a check for file size if reading returns empty
content.
pull/6/head
Kubernetes Submit Queue 2016-10-04 21:03:00 -07:00 committed by GitHub
commit a9003a36ba
2 changed files with 17 additions and 0 deletions

View File

@ -587,6 +587,16 @@ func (f *Framework) ReadFileViaContainer(podName, containerName string, path str
return string(stdout), err return string(stdout), err
} }
func (f *Framework) CheckFileSizeViaContainer(podName, containerName, path string) (string, error) {
By("checking a file size in the container")
stdout, stderr, err := kubectlExecWithRetry(f.Namespace.Name, podName, containerName, "--", "ls", "-l", path)
if err != nil {
Logf("error running kubectl exec to read file: %v\nstdout=%v\nstderr=%v)", err, string(stdout), string(stderr))
}
return string(stdout), err
}
// CreateServiceForSimpleAppWithPods is a convenience wrapper to create a service and its matching pods all at once. // CreateServiceForSimpleAppWithPods is a convenience wrapper to create a service and its matching pods all at once.
func (f *Framework) CreateServiceForSimpleAppWithPods(contPort int, svcPort int, appName string, podSpec func(n api.Node) api.PodSpec, count int, block bool) (error, *api.Service) { func (f *Framework) CreateServiceForSimpleAppWithPods(contPort int, svcPort int, appName string, podSpec func(n api.Node) api.PodSpec, count int, block bool) (error, *api.Service) {
var err error = nil var err error = nil

View File

@ -456,6 +456,13 @@ func verifyPDContentsViaContainer(f *framework.Framework, podName, containerName
} }
framework.ExpectNoError(err) framework.ExpectNoError(err)
framework.Logf("Read file %q with content: %v", filePath, 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 {
framework.Logf("Error reading file: %v", err)
}
framework.Logf("Check file %q size: %q", filePath, size)
}
Expect(strings.TrimSpace(v)).To(Equal(strings.TrimSpace(expectedContents))) Expect(strings.TrimSpace(v)).To(Equal(strings.TrimSpace(expectedContents)))
} }
} }