Add conformance tests for terminationMessage(Path|Policy)

Test root, non-root, success and message, failure and message.
This commit is contained in:
Clayton Coleman 2017-01-01 15:23:24 -05:00
parent e6d35b0362
commit 244734171e
No known key found for this signature in database
GPG Key ID: 3D16906B4F1C5CB3

View File

@ -28,6 +28,7 @@ import (
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
gomegatypes "github.com/onsi/gomega/types"
) )
const ( const (
@ -128,46 +129,112 @@ while true; do sleep 1; done
} }
}) })
It("should report termination message if TerminationMessagePath is set [Conformance]", func() { rootUser := int64(0)
name := "termination-message-container" nonRootUser := int64(10000)
terminationMessage := "DONE" for _, testCase := range []struct {
terminationMessagePath := "/dev/termination-log" name string
priv := true container v1.Container
c := ConformanceContainer{ phase v1.PodPhase
PodClient: f.PodClient(), message gomegatypes.GomegaMatcher
Container: v1.Container{ }{
{
name: "if TerminationMessagePath is set [Conformance]",
container: v1.Container{
Image: "gcr.io/google_containers/busybox:1.24", Image: "gcr.io/google_containers/busybox:1.24",
Name: name,
Command: []string{"/bin/sh", "-c"}, Command: []string{"/bin/sh", "-c"},
Args: []string{fmt.Sprintf("/bin/echo -n %s > %s", terminationMessage, terminationMessagePath)}, Args: []string{"/bin/echo -n DONE > /dev/termination-log"},
TerminationMessagePath: terminationMessagePath, TerminationMessagePath: "/dev/termination-log",
SecurityContext: &v1.SecurityContext{ SecurityContext: &v1.SecurityContext{
Privileged: &priv, RunAsUser: &rootUser,
}, },
}, },
RestartPolicy: v1.RestartPolicyNever, phase: v1.PodSucceeded,
} message: Equal("DONE"),
},
By("create the container") {
c.Create() name: "if TerminationMessagePath is set as non-root user and at a non-default path [Conformance]",
defer c.Delete() container: v1.Container{
Image: "gcr.io/google_containers/busybox:1.24",
Command: []string{"/bin/sh", "-c"},
Args: []string{"/bin/echo -n DONE > /dev/termination-custom-log"},
TerminationMessagePath: "/dev/termination-custom-log",
SecurityContext: &v1.SecurityContext{
RunAsUser: &nonRootUser,
},
},
phase: v1.PodSucceeded,
message: Equal("DONE"),
},
By("wait for the container to succeed") {
Eventually(c.GetPhase, retryTimeout, pollInterval).Should(Equal(v1.PodSucceeded)) name: "from log output if TerminationMessagePolicy FallbackToLogOnError is set [Conformance]",
container: v1.Container{
Image: "gcr.io/google_containers/busybox:1.24",
Command: []string{"/bin/sh", "-c"},
Args: []string{"/bin/echo -n DONE; /bin/false"},
TerminationMessagePath: "/dev/termination-log",
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
},
phase: v1.PodFailed,
message: Equal("DONE\n"),
},
By("get the container status") {
status, err := c.GetStatus() name: "as empty when pod succeeds and TerminationMessagePolicy FallbackToLogOnError is set",
Expect(err).NotTo(HaveOccurred()) container: v1.Container{
Image: "gcr.io/google_containers/busybox:1.24",
Command: []string{"/bin/sh", "-c"},
Args: []string{"/bin/echo DONE; /bin/true"},
TerminationMessagePath: "/dev/termination-log",
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
},
phase: v1.PodSucceeded,
message: Equal(""),
},
By("the container should be terminated") {
Expect(GetContainerState(status.State)).To(Equal(ContainerStateTerminated)) name: "from file when pod succeeds and TerminationMessagePolicy FallbackToLogOnError is set [Conformance]",
container: v1.Container{
Image: "gcr.io/google_containers/busybox:1.24",
Command: []string{"/bin/sh", "-c"},
Args: []string{"/bin/echo -n OK > /dev/termination-log; /bin/echo DONE; /bin/true"},
TerminationMessagePath: "/dev/termination-log",
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
},
phase: v1.PodSucceeded,
message: Equal("OK"),
},
} {
It(fmt.Sprintf("should report termination message %s", testCase.name), func() {
testCase.container.Name = "termination-message-container"
c := ConformanceContainer{
PodClient: f.PodClient(),
Container: testCase.container,
RestartPolicy: v1.RestartPolicyNever,
}
By("the termination message should be set") By("create the container")
Expect(status.State.Terminated.Message).Should(Equal(terminationMessage)) c.Create()
defer c.Delete()
By("delete the container") By(fmt.Sprintf("wait for the container to reach %s", testCase.phase))
Expect(c.Delete()).To(Succeed()) Eventually(c.GetPhase, retryTimeout, pollInterval).Should(Equal(testCase.phase))
})
By("get the container status")
status, err := c.GetStatus()
Expect(err).NotTo(HaveOccurred())
By("the container should be terminated")
Expect(GetContainerState(status.State)).To(Equal(ContainerStateTerminated))
By("the termination message should be set")
Expect(status.State.Terminated.Message).Should(testCase.message)
By("delete the container")
Expect(c.Delete()).To(Succeed())
})
}
}) })
Context("when running a container with a new image", func() { Context("when running a container with a new image", func() {