summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2022-03-15 14:44:18 -0700
committerJhon Honce <jhonce@redhat.com>2022-03-16 11:27:07 -0700
commit1387b5bd8a639fcc0c9f9e78cda2aee7bac61b7d (patch)
treef43473e581e6917e5d21eca989e8252aec878702
parentca7376bb115e2d3506a3efe242bde25118f57c39 (diff)
downloadpodman-1387b5bd8a639fcc0c9f9e78cda2aee7bac61b7d.tar.gz
podman-1387b5bd8a639fcc0c9f9e78cda2aee7bac61b7d.tar.bz2
podman-1387b5bd8a639fcc0c9f9e78cda2aee7bac61b7d.zip
Add test for BZ #2052697
Signed-off-by: Jhon Honce <jhonce@redhat.com>
-rw-r--r--test/e2e/systemd_activate_test.go107
-rw-r--r--test/utils/utils.go2
2 files changed, 109 insertions, 0 deletions
diff --git a/test/e2e/systemd_activate_test.go b/test/e2e/systemd_activate_test.go
new file mode 100644
index 000000000..d5434868d
--- /dev/null
+++ b/test/e2e/systemd_activate_test.go
@@ -0,0 +1,107 @@
+package integration
+
+import (
+ "errors"
+ "fmt"
+ "io/fs"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "syscall"
+ "time"
+
+ testUtils "github.com/containers/podman/v4/test/utils"
+ podmanUtils "github.com/containers/podman/v4/utils"
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+ . "github.com/onsi/gomega/gexec"
+)
+
+var _ = Describe("Systemd activate", func() {
+ var tempDir string
+ var err error
+ var podmanTest *PodmanTestIntegration
+
+ BeforeEach(func() {
+ tempDir, err = testUtils.CreateTempDirInTempDir()
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "%v\n", err)
+ os.Exit(1)
+ }
+
+ podmanTest = PodmanTestCreate(tempDir)
+ podmanTest.Setup()
+ podmanTest.SeedImages()
+ })
+
+ AfterEach(func() {
+ podmanTest.Cleanup()
+ processTestResult(CurrentGinkgoTestDescription())
+ })
+
+ It("stop podman.service", func() {
+ SkipIfRemote("Testing stopped service requires both podman and podman-remote binaries")
+
+ activate, err := exec.LookPath("systemd-socket-activate")
+ if err != nil {
+ activate = "/usr/bin/systemd-socket-activate"
+ }
+ stat, err := os.Stat(activate)
+ switch {
+ case errors.Is(err, fs.ErrNotExist):
+ Skip(activate + " required for systemd activation tests")
+ case stat.Mode()&0111 == 0:
+ Skip("Unable to execute " + activate)
+ case err != nil:
+ Skip(err.Error())
+ }
+
+ // systemd-socket-activate does not support DNS lookups
+ host := "127.0.0.1"
+ port, err := podmanUtils.GetRandomPort()
+ Expect(err).ToNot(HaveOccurred())
+
+ activateSession := testUtils.StartSystemExec(activate, []string{
+ fmt.Sprintf("--listen=%s:%d", host, port),
+ podmanTest.PodmanBinary,
+ "--root=" + filepath.Join(tempDir, "server_root"),
+ "system", "service",
+ "--time=0",
+ })
+ Expect(activateSession.Exited).ShouldNot(Receive(), "Failed to start podman service")
+
+ // Curried functions for specialized podman calls
+ podmanRemote := func(args ...string) *testUtils.PodmanSession {
+ args = append([]string{"--url", fmt.Sprintf("tcp://%s:%d", host, port)}, args...)
+ return testUtils.SystemExec(podmanTest.RemotePodmanBinary, args)
+ }
+
+ podman := func(args ...string) *testUtils.PodmanSession {
+ args = append([]string{"--root", filepath.Join(tempDir, "server_root")}, args...)
+ return testUtils.SystemExec(podmanTest.PodmanBinary, args)
+ }
+
+ containerName := "top_" + testUtils.RandomString(8)
+ apiSession := podmanRemote(
+ "create", "--tty", "--name", containerName, "--entrypoint", "top",
+ "quay.io/libpod/alpine_labels:latest",
+ )
+ Expect(apiSession).Should(Exit(0))
+
+ apiSession = podmanRemote("start", containerName)
+ Expect(apiSession).Should(Exit(0))
+
+ apiSession = podmanRemote("inspect", "--format={{.State.Running}}", containerName)
+ Expect(apiSession).Should(Exit(0))
+ Expect(apiSession.OutputToString()).To(Equal("true"))
+
+ // Emulate 'systemd stop podman.service'
+ activateSession.Signal(syscall.SIGTERM)
+ time.Sleep(2)
+ Eventually(activateSession).Should(Exit(0))
+
+ abiSession := podman("inspect", "--format={{.State.Running}}", containerName)
+ Expect(abiSession).To(Exit(0))
+ Expect(abiSession.OutputToString()).To(Equal("true"))
+ })
+})
diff --git a/test/utils/utils.go b/test/utils/utils.go
index 14092a2a5..8fe45dca0 100644
--- a/test/utils/utils.go
+++ b/test/utils/utils.go
@@ -368,6 +368,7 @@ func CreateTempDirInTempDir() (string, error) {
// SystemExec is used to exec a system command to check its exit code or output
func SystemExec(command string, args []string) *PodmanSession {
c := exec.Command(command, args...)
+ fmt.Println("Execing " + c.String() + "\n")
session, err := Start(c, GinkgoWriter, GinkgoWriter)
if err != nil {
Fail(fmt.Sprintf("unable to run command: %s %s", command, strings.Join(args, " ")))
@@ -379,6 +380,7 @@ func SystemExec(command string, args []string) *PodmanSession {
// StartSystemExec is used to start exec a system command
func StartSystemExec(command string, args []string) *PodmanSession {
c := exec.Command(command, args...)
+ fmt.Println("Execing " + c.String() + "\n")
session, err := Start(c, GinkgoWriter, GinkgoWriter)
if err != nil {
Fail(fmt.Sprintf("unable to run command: %s %s", command, strings.Join(args, " ")))