Skip to content

Commit 96e3bc1

Browse files
committed
Log PodExec stdout + stderr
e2e tests should log stdout / stderr of failed commands executed via PodExec. "command terminated with exit code 1" is not really useful.
1 parent 53b2973 commit 96e3bc1

File tree

5 files changed

+35
-31
lines changed

5 files changed

+35
-31
lines changed

test/e2e/storage/host_path_type.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"fmt"
2222
"path"
2323

24-
"k8s.io/api/core/v1"
24+
v1 "k8s.io/api/core/v1"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
"k8s.io/apimachinery/pkg/fields"
2727
"k8s.io/kubernetes/pkg/kubelet/events"
@@ -262,8 +262,9 @@ var _ = utils.SIGDescribe("HostPathType Character Device [Slow]", func() {
262262
ginkgo.By(fmt.Sprintf("running on node %s", basePod.Spec.NodeName))
263263
targetCharDev = path.Join(hostBaseDir, "achardev")
264264
ginkgo.By("Create a character device for further testing")
265-
_, err := utils.PodExec(f, basePod, fmt.Sprintf("mknod %s c 89 1", path.Join(mountBaseDir, "achardev")))
266-
framework.ExpectNoError(err)
265+
cmd := fmt.Sprintf("mknod %s c 89 1", path.Join(mountBaseDir, "achardev"))
266+
stdout, stderr, err := utils.PodExec(f, basePod, cmd)
267+
framework.ExpectNoError(err, "command: %q, stdout: %s\nstderr: %s", cmd, stdout, stderr)
267268
})
268269

269270
ginkgo.It("Should fail on mounting non-existent character device 'does-not-exist-char-dev' when HostPathType is HostPathCharDev", func() {
@@ -330,8 +331,9 @@ var _ = utils.SIGDescribe("HostPathType Block Device [Slow]", func() {
330331
ginkgo.By(fmt.Sprintf("running on node %s", basePod.Spec.NodeName))
331332
targetBlockDev = path.Join(hostBaseDir, "ablkdev")
332333
ginkgo.By("Create a block device for further testing")
333-
_, err := utils.PodExec(f, basePod, fmt.Sprintf("mknod %s b 89 1", path.Join(mountBaseDir, "ablkdev")))
334-
framework.ExpectNoError(err)
334+
cmd := fmt.Sprintf("mknod %s b 89 1", path.Join(mountBaseDir, "ablkdev"))
335+
stdout, stderr, err := utils.PodExec(f, basePod, cmd)
336+
framework.ExpectNoError(err, "command %q: stdout: %s\nstderr: %s", cmd, stdout, stderr)
335337
})
336338

337339
ginkgo.It("Should fail on mounting non-existent block device 'does-not-exist-blk-dev' when HostPathType is HostPathBlockDev", func() {

test/e2e/storage/persistent_volumes-local.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,10 +1074,10 @@ func testReadFileContent(f *framework.Framework, testFileDir string, testFile st
10741074
// Execute a read or write command in a pod.
10751075
// Fail on error
10761076
func podRWCmdExec(f *framework.Framework, pod *v1.Pod, cmd string) string {
1077-
out, err := utils.PodExec(f, pod, cmd)
1078-
framework.Logf("podRWCmdExec out: %q err: %v", out, err)
1077+
stdout, stderr, err := utils.PodExec(f, pod, cmd)
1078+
framework.Logf("podRWCmdExec cmd: %q, out: %q, stderr: %q, err: %v", cmd, stdout, stderr, err)
10791079
framework.ExpectNoError(err)
1080-
return out
1080+
return stdout
10811081
}
10821082

10831083
// Initialize test volume on node

test/e2e/storage/testsuites/snapshottable.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ func (s *snapshottableTestSuite) DefineTests(driver TestDriver, pattern testpatt
276276
framework.ExpectNoError(e2epod.WaitForPodRunningInNamespaceSlow(cs, restoredPod.Name, restoredPod.Namespace))
277277

278278
command = "cat /mnt/test/data"
279-
actualData, err := utils.PodExec(f, restoredPod, command)
280-
framework.ExpectNoError(err)
279+
actualData, stderr, err := utils.PodExec(f, restoredPod, command)
280+
framework.ExpectNoError(err, "command %q: stdout: %s\nstderr: %s", command, actualData, stderr)
281281
framework.ExpectEqual(actualData, originalMntTestData)
282282

283283
ginkgo.By("should delete the VolumeSnapshotContent according to its deletion policy")

test/e2e/storage/testsuites/volume_io.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,19 @@ func writeToFile(f *framework.Framework, pod *v1.Pod, fpath, ddInput string, fsi
249249
ginkgo.By(fmt.Sprintf("writing %d bytes to test file %s", fsize, fpath))
250250
loopCnt := fsize / testpatterns.MinFileSize
251251
writeCmd := fmt.Sprintf("i=0; while [ $i -lt %d ]; do dd if=%s bs=%d >>%s 2>/dev/null; let i+=1; done", loopCnt, ddInput, testpatterns.MinFileSize, fpath)
252-
_, err := utils.PodExec(f, pod, writeCmd)
253-
252+
stdout, stderr, err := utils.PodExec(f, pod, writeCmd)
253+
if err != nil {
254+
return fmt.Errorf("error writing to volume using %q: %s\nstdout: %s\nstderr: %s", writeCmd, err, stdout, stderr)
255+
}
254256
return err
255257
}
256258

257259
// Verify that the test file is the expected size and contains the expected content.
258260
func verifyFile(f *framework.Framework, pod *v1.Pod, fpath string, expectSize int64, ddInput string) error {
259261
ginkgo.By("verifying file size")
260-
rtnstr, err := utils.PodExec(f, pod, fmt.Sprintf("stat -c %%s %s", fpath))
262+
rtnstr, stderr, err := utils.PodExec(f, pod, fmt.Sprintf("stat -c %%s %s", fpath))
261263
if err != nil || rtnstr == "" {
262-
return fmt.Errorf("unable to get file size via `stat %s`: %v", fpath, err)
264+
return fmt.Errorf("unable to get file size via `stat %s`: %v\nstdout: %s\nstderr: %s", fpath, err, rtnstr, stderr)
263265
}
264266
size, err := strconv.Atoi(strings.TrimSuffix(rtnstr, "\n"))
265267
if err != nil {
@@ -270,9 +272,9 @@ func verifyFile(f *framework.Framework, pod *v1.Pod, fpath string, expectSize in
270272
}
271273

272274
ginkgo.By("verifying file hash")
273-
rtnstr, err = utils.PodExec(f, pod, fmt.Sprintf("md5sum %s | cut -d' ' -f1", fpath))
275+
rtnstr, stderr, err = utils.PodExec(f, pod, fmt.Sprintf("md5sum %s | cut -d' ' -f1", fpath))
274276
if err != nil {
275-
return fmt.Errorf("unable to test file hash via `md5sum %s`: %v", fpath, err)
277+
return fmt.Errorf("unable to test file hash via `md5sum %s`: %v\nstdout: %s\nstderr: %s", fpath, err, rtnstr, stderr)
276278
}
277279
actualHash := strings.TrimSuffix(rtnstr, "\n")
278280
expectedHash, ok := md5hashes[expectSize]
@@ -291,10 +293,10 @@ func verifyFile(f *framework.Framework, pod *v1.Pod, fpath string, expectSize in
291293
// Delete `fpath` to save some disk space on host. Delete errors are logged but ignored.
292294
func deleteFile(f *framework.Framework, pod *v1.Pod, fpath string) {
293295
ginkgo.By(fmt.Sprintf("deleting test file %s...", fpath))
294-
_, err := utils.PodExec(f, pod, fmt.Sprintf("rm -f %s", fpath))
296+
stdout, stderr, err := utils.PodExec(f, pod, fmt.Sprintf("rm -f %s", fpath))
295297
if err != nil {
296298
// keep going, the test dir will be deleted when the volume is unmounted
297-
framework.Logf("unable to delete test file %s: %v\nerror ignored, continuing test", fpath, err)
299+
framework.Logf("unable to delete test file %s: %v\nerror ignored, continuing test\nstdout: %s\nstderr: %s", fpath, err, stdout, stderr)
298300
}
299301
}
300302

test/e2e/storage/utils/utils.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,41 +67,41 @@ const (
6767
)
6868

6969
// PodExec runs f.ExecCommandInContainerWithFullOutput to execute a shell cmd in target pod
70-
func PodExec(f *framework.Framework, pod *v1.Pod, shExec string) (string, error) {
71-
stdout, _, err := f.ExecCommandInContainerWithFullOutput(pod.Name, pod.Spec.Containers[0].Name, "/bin/sh", "-c", shExec)
72-
return stdout, err
70+
func PodExec(f *framework.Framework, pod *v1.Pod, shExec string) (string, string, error) {
71+
stdout, stderr, err := f.ExecCommandInContainerWithFullOutput(pod.Name, pod.Spec.Containers[0].Name, "/bin/sh", "-c", shExec)
72+
return stdout, stderr, err
7373
}
7474

7575
// VerifyExecInPodSucceed verifies shell cmd in target pod succeed
7676
func VerifyExecInPodSucceed(f *framework.Framework, pod *v1.Pod, shExec string) {
77-
_, err := PodExec(f, pod, shExec)
77+
stdout, stderr, err := PodExec(f, pod, shExec)
7878
if err != nil {
7979
if exiterr, ok := err.(uexec.CodeExitError); ok {
8080
exitCode := exiterr.ExitStatus()
8181
framework.ExpectNoError(err,
82-
"%q should succeed, but failed with exit code %d and error message %q",
83-
shExec, exitCode, exiterr)
82+
"%q should succeed, but failed with exit code %d and error message %q\nstdout: %s\nstderr: %s",
83+
shExec, exitCode, exiterr, stdout, stderr)
8484
} else {
8585
framework.ExpectNoError(err,
86-
"%q should succeed, but failed with error message %q",
87-
shExec, err)
86+
"%q should succeed, but failed with error message %q\nstdout: %s\nstderr: %s",
87+
shExec, err, stdout, stderr)
8888
}
8989
}
9090
}
9191

9292
// VerifyExecInPodFail verifies shell cmd in target pod fail with certain exit code
9393
func VerifyExecInPodFail(f *framework.Framework, pod *v1.Pod, shExec string, exitCode int) {
94-
_, err := PodExec(f, pod, shExec)
94+
stdout, stderr, err := PodExec(f, pod, shExec)
9595
if err != nil {
9696
if exiterr, ok := err.(clientexec.ExitError); ok {
9797
actualExitCode := exiterr.ExitStatus()
9898
framework.ExpectEqual(actualExitCode, exitCode,
99-
"%q should fail with exit code %d, but failed with exit code %d and error message %q",
100-
shExec, exitCode, actualExitCode, exiterr)
99+
"%q should fail with exit code %d, but failed with exit code %d and error message %q\nstdout: %s\nstderr: %s",
100+
shExec, exitCode, actualExitCode, exiterr, stdout, stderr)
101101
} else {
102102
framework.ExpectNoError(err,
103-
"%q should fail with exit code %d, but failed with error message %q",
104-
shExec, exitCode, err)
103+
"%q should fail with exit code %d, but failed with error message %q\nstdout: %s\nstderr: %s",
104+
shExec, exitCode, err, stdout, stderr)
105105
}
106106
}
107107
framework.ExpectError(err, "%q should fail with exit code %d, but exit without error", shExec, exitCode)

0 commit comments

Comments
 (0)