summaryrefslogtreecommitdiff
path: root/test/e2e
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2018-03-16 10:34:32 -0400
committerGitHub <noreply@github.com>2018-03-16 10:34:32 -0400
commitd7acfb478e5e5e6ac344d18c1a65ab81996fd8b2 (patch)
treec1a335e5a2291e8447e8f9f4c4ef02e7cde2fd0c /test/e2e
parent2f533888a5adcbfb57ec22a8086aa5e76acb9071 (diff)
parentcd73a6904d3dc91f305c7415ab7bada8a976d815 (diff)
downloadpodman-d7acfb478e5e5e6ac344d18c1a65ab81996fd8b2.tar.gz
podman-d7acfb478e5e5e6ac344d18c1a65ab81996fd8b2.tar.bz2
podman-d7acfb478e5e5e6ac344d18c1a65ab81996fd8b2.zip
Merge pull request #447 from mheon/sig_proxy
Add signal proxying to podman run and attach
Diffstat (limited to 'test/e2e')
-rw-r--r--test/e2e/libpod_suite_test.go2
-rw-r--r--test/e2e/run_signal_test.go101
2 files changed, 102 insertions, 1 deletions
diff --git a/test/e2e/libpod_suite_test.go b/test/e2e/libpod_suite_test.go
index dc6292ace..634c38b29 100644
--- a/test/e2e/libpod_suite_test.go
+++ b/test/e2e/libpod_suite_test.go
@@ -162,7 +162,7 @@ func (p *PodmanTest) Podman(args []string) *PodmanSession {
command := exec.Command(p.PodmanBinary, podmanOptions...)
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
if err != nil {
- Fail(fmt.Sprintf("unable to run podman command: %s", strings.Join(podmanOptions, " ")))
+ Fail(fmt.Sprintf("unable to run podman command: %s\n%v", strings.Join(podmanOptions, " "), err))
}
return &PodmanSession{session}
}
diff --git a/test/e2e/run_signal_test.go b/test/e2e/run_signal_test.go
new file mode 100644
index 000000000..095288277
--- /dev/null
+++ b/test/e2e/run_signal_test.go
@@ -0,0 +1,101 @@
+package integration
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+ "strings"
+ "syscall"
+
+ "github.com/onsi/gomega/gexec"
+ "golang.org/x/sys/unix"
+
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+)
+
+// PodmanPID execs podman and returns its PID
+func (p *PodmanTest) PodmanPID(args []string) (*PodmanSession, int) {
+ podmanOptions := p.MakeOptions()
+ podmanOptions = append(podmanOptions, strings.Split(p.StorageOptions, " ")...)
+ podmanOptions = append(podmanOptions, args...)
+ fmt.Printf("Running: %s %s\n", p.PodmanBinary, strings.Join(podmanOptions, " "))
+ command := exec.Command(p.PodmanBinary, podmanOptions...)
+ session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
+ if err != nil {
+ Fail(fmt.Sprintf("unable to run podman command: %s", strings.Join(podmanOptions, " ")))
+ }
+ return &PodmanSession{session}, command.Process.Pid
+}
+
+const sigCatch = "for NUM in `seq 1 64`; do trap \"echo Received $NUM\" $NUM; done; echo READY; while :; do sleep 0.1; done"
+
+var _ = Describe("Podman run with --sig-proxy", func() {
+ var (
+ tmpdir string
+ err error
+ podmanTest PodmanTest
+ )
+
+ BeforeEach(func() {
+ tmpdir, err = CreateTempDirInTempDir()
+ if err != nil {
+ os.Exit(1)
+ }
+ podmanTest = PodmanCreate(tmpdir)
+ podmanTest.RestoreAllArtifacts()
+ podmanTest.RestoreArtifact(fedoraMinimal)
+ })
+
+ AfterEach(func() {
+ podmanTest.Cleanup()
+
+ })
+
+ Specify("signals are forwarded to container using sig-proxy", func() {
+ signal := syscall.SIGPOLL
+ session, pid := podmanTest.PodmanPID([]string{"run", "--name", "test1", fedoraMinimal, "bash", "-c", sigCatch})
+
+ ok := WaitForContainer(&podmanTest)
+ Expect(ok).To(BeTrue())
+
+ // Kill with given signal
+ if err := unix.Kill(pid, signal); err != nil {
+ Fail(fmt.Sprintf("error killing podman process %d: %v", pid, err))
+ }
+
+ // Kill with -9 to guarantee the container dies
+ killSession := podmanTest.Podman([]string{"kill", "-s", "9", "test1"})
+ killSession.WaitWithDefaultTimeout()
+ Expect(killSession.ExitCode()).To(Equal(0))
+
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ ok, _ = session.GrepString(fmt.Sprintf("Received %d", signal))
+ Expect(ok).To(BeTrue())
+ })
+
+ Specify("signals are not forwarded to container with sig-proxy false", func() {
+ signal := syscall.SIGPOLL
+ session, pid := podmanTest.PodmanPID([]string{"run", "--name", "test2", "--sig-proxy=false", fedoraMinimal, "bash", "-c", sigCatch})
+
+ ok := WaitForContainer(&podmanTest)
+ Expect(ok).To(BeTrue())
+
+ // Kill with given signal
+ // Should be no output, SIGPOLL is usually ignored
+ if err := unix.Kill(pid, signal); err != nil {
+ Fail(fmt.Sprintf("error killing podman process %d: %v", pid, err))
+ }
+
+ // Kill with -9 to guarantee the container dies
+ killSession := podmanTest.Podman([]string{"kill", "-s", "9", "test2"})
+ killSession.WaitWithDefaultTimeout()
+ Expect(killSession.ExitCode()).To(Equal(0))
+
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ ok, _ = session.GrepString(fmt.Sprintf("Received %d", signal))
+ Expect(ok).To(BeFalse())
+ })
+})