mirror of
https://github.com/containers/podman.git
synced 2025-06-19 16:33:24 +08:00
Merge pull request #6415 from vrothberg/systemd-new-pod
podman-generate-systemd --new for pods
This commit is contained in:
@ -2,6 +2,7 @@ package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@ -221,6 +222,42 @@ var _ = Describe("Podman create", func() {
|
||||
Expect(match).To(BeTrue())
|
||||
})
|
||||
|
||||
It("podman create --pod-id-file", func() {
|
||||
// First, make sure that --pod and --pod-id-file yield an error
|
||||
// if used together.
|
||||
session := podmanTest.Podman([]string{"create", "--pod", "foo", "--pod-id-file", "bar", ALPINE, "ls"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(125))
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "")
|
||||
Expect(err).To(BeNil())
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
podName := "rudoplh"
|
||||
ctrName := "prancer"
|
||||
podIDFile := tmpDir + "pod-id-file"
|
||||
|
||||
// Now, let's create a pod with --pod-id-file.
|
||||
session = podmanTest.Podman([]string{"pod", "create", "--pod-id-file", podIDFile, "--name", podName})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"pod", "inspect", podName})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(session.IsJSONOutputValid()).To(BeTrue())
|
||||
podData := session.InspectPodToJSON()
|
||||
|
||||
// Finally we can create a container with --pod-id-file and do
|
||||
// some checks to make sure it's working as expected.
|
||||
session = podmanTest.Podman([]string{"create", "--pod-id-file", podIDFile, "--name", ctrName, ALPINE, "top"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
ctrJSON := podmanTest.InspectContainer(ctrName)
|
||||
Expect(podData.ID).To(Equal(ctrJSON[0].Pod)) // Make sure the container's pod matches the pod's ID
|
||||
})
|
||||
|
||||
It("podman run entrypoint and cmd test", func() {
|
||||
name := "test101"
|
||||
create := podmanTest.Podman([]string{"create", "--name", name, redis})
|
||||
|
@ -3,6 +3,7 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
. "github.com/containers/libpod/test/utils"
|
||||
@ -191,7 +192,7 @@ var _ = Describe("Podman generate systemd", func() {
|
||||
found, _ := session.GrepString("# container-foo.service")
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
found, _ = session.GrepString("stop --ignore --cidfile %t/%n-cid -t 42")
|
||||
found, _ = session.GrepString("stop --ignore --cidfile %t/container-foo.ctr-id -t 42")
|
||||
Expect(found).To(BeTrue())
|
||||
})
|
||||
|
||||
@ -230,7 +231,7 @@ var _ = Describe("Podman generate systemd", func() {
|
||||
|
||||
session := podmanTest.Podman([]string{"generate", "systemd", "--time", "42", "--name", "--new", "foo"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(125))
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
})
|
||||
|
||||
It("podman generate systemd --container-prefix con", func() {
|
||||
@ -325,4 +326,49 @@ var _ = Describe("Podman generate systemd", func() {
|
||||
found, _ = session.GrepString("BindsTo=p_foo.service")
|
||||
Expect(found).To(BeTrue())
|
||||
})
|
||||
|
||||
It("podman generate systemd pod with containers --new", func() {
|
||||
tmpDir, err := ioutil.TempDir("", "")
|
||||
Expect(err).To(BeNil())
|
||||
tmpFile := tmpDir + "podID"
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
n := podmanTest.Podman([]string{"pod", "create", "--pod-id-file", tmpFile, "--name", "foo"})
|
||||
n.WaitWithDefaultTimeout()
|
||||
Expect(n.ExitCode()).To(Equal(0))
|
||||
|
||||
n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-1", "alpine", "top"})
|
||||
n.WaitWithDefaultTimeout()
|
||||
Expect(n.ExitCode()).To(Equal(0))
|
||||
|
||||
n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-2", "alpine", "top"})
|
||||
n.WaitWithDefaultTimeout()
|
||||
Expect(n.ExitCode()).To(Equal(0))
|
||||
|
||||
session := podmanTest.Podman([]string{"generate", "systemd", "--new", "--name", "foo"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
// Grepping the output (in addition to unit tests)
|
||||
found, _ := session.GrepString("# pod-foo.service")
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
found, _ = session.GrepString("Requires=container-foo-1.service container-foo-2.service")
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
found, _ = session.GrepString("BindsTo=pod-foo.service")
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
found, _ = session.GrepString("pod create --infra-conmon-pidfile %t/pod-foo.pid --pod-id-file %t/pod-foo.pod-id --name foo")
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
found, _ = session.GrepString("ExecStartPre=/usr/bin/rm -f %t/pod-foo.pid %t/pod-foo.pod-id")
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
found, _ = session.GrepString("pod stop --ignore --pod-id-file %t/pod-foo.pod-id -t 10")
|
||||
Expect(found).To(BeTrue())
|
||||
|
||||
found, _ = session.GrepString("pod rm --ignore -f --pod-id-file %t/pod-foo.pod-id")
|
||||
Expect(found).To(BeTrue())
|
||||
})
|
||||
})
|
||||
|
@ -57,4 +57,26 @@ var _ = Describe("Podman pod inspect", func() {
|
||||
podData := inspect.InspectPodToJSON()
|
||||
Expect(podData.ID).To(Equal(podid))
|
||||
})
|
||||
|
||||
It("podman pod inspect (CreateCommand)", func() {
|
||||
podName := "myTestPod"
|
||||
createCommand := []string{"pod", "create", "--name", podName, "--hostname", "rudolph", "--share", "net"}
|
||||
|
||||
// Create the pod.
|
||||
session := podmanTest.Podman(createCommand)
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
// Inspect the pod and make sure that the create command is
|
||||
// exactly how we created the pod.
|
||||
inspect := podmanTest.Podman([]string{"pod", "inspect", podName})
|
||||
inspect.WaitWithDefaultTimeout()
|
||||
Expect(inspect.ExitCode()).To(Equal(0))
|
||||
Expect(inspect.IsJSONOutputValid()).To(BeTrue())
|
||||
podData := inspect.InspectPodToJSON()
|
||||
// Let's get the last len(createCommand) items in the command.
|
||||
inspectCreateCommand := podData.CreateCommand
|
||||
index := len(inspectCreateCommand) - len(createCommand)
|
||||
Expect(inspectCreateCommand[index:]).To(Equal(createCommand))
|
||||
})
|
||||
})
|
||||
|
@ -2,6 +2,7 @@ package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -229,4 +230,72 @@ var _ = Describe("Podman pod rm", func() {
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
})
|
||||
|
||||
It("podman pod start/remove single pod via --pod-id-file", func() {
|
||||
tmpDir, err := ioutil.TempDir("", "")
|
||||
Expect(err).To(BeNil())
|
||||
tmpFile := tmpDir + "podID"
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
podName := "rudolph"
|
||||
|
||||
// Create a pod with --pod-id-file.
|
||||
session := podmanTest.Podman([]string{"pod", "create", "--name", podName, "--pod-id-file", tmpFile})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
// Create container inside the pod.
|
||||
session = podmanTest.Podman([]string{"create", "--pod", podName, ALPINE, "top"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"pod", "start", "--pod-id-file", tmpFile})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2)) // infra+top
|
||||
|
||||
session = podmanTest.Podman([]string{"pod", "rm", "--pod-id-file", tmpFile, "--force"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
||||
})
|
||||
|
||||
It("podman pod start/remove multiple pods via --pod-id-file", func() {
|
||||
tmpDir, err := ioutil.TempDir("", "")
|
||||
Expect(err).To(BeNil())
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
podIDFiles := []string{}
|
||||
for _, i := range "0123456789" {
|
||||
tmpFile := tmpDir + "cid" + string(i)
|
||||
podName := "rudolph" + string(i)
|
||||
// Create a pod with --pod-id-file.
|
||||
session := podmanTest.Podman([]string{"pod", "create", "--name", podName, "--pod-id-file", tmpFile})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
// Create container inside the pod.
|
||||
session = podmanTest.Podman([]string{"create", "--pod", podName, ALPINE, "top"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
// Append the id files along with the command.
|
||||
podIDFiles = append(podIDFiles, "--pod-id-file")
|
||||
podIDFiles = append(podIDFiles, tmpFile)
|
||||
}
|
||||
|
||||
cmd := []string{"pod", "start"}
|
||||
cmd = append(cmd, podIDFiles...)
|
||||
session := podmanTest.Podman(cmd)
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(20)) // 10*(infra+top)
|
||||
|
||||
cmd = []string{"pod", "rm", "--force"}
|
||||
cmd = append(cmd, podIDFiles...)
|
||||
session = podmanTest.Podman(cmd)
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
||||
})
|
||||
})
|
||||
|
@ -1,7 +1,11 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
. "github.com/containers/libpod/test/utils"
|
||||
. "github.com/onsi/ginkgo"
|
||||
@ -136,4 +140,94 @@ var _ = Describe("Podman pod start", func() {
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(125))
|
||||
})
|
||||
|
||||
It("podman pod start single pod via --pod-id-file", func() {
|
||||
tmpDir, err := ioutil.TempDir("", "")
|
||||
Expect(err).To(BeNil())
|
||||
tmpFile := tmpDir + "podID"
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
podName := "rudolph"
|
||||
|
||||
// Create a pod with --pod-id-file.
|
||||
session := podmanTest.Podman([]string{"pod", "create", "--name", podName, "--pod-id-file", tmpFile})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
// Create container inside the pod.
|
||||
session = podmanTest.Podman([]string{"create", "--pod", podName, ALPINE, "top"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"pod", "start", "--pod-id-file", tmpFile})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2)) // infra+top
|
||||
})
|
||||
|
||||
It("podman pod start multiple pods via --pod-id-file", func() {
|
||||
tmpDir, err := ioutil.TempDir("", "")
|
||||
Expect(err).To(BeNil())
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
podIDFiles := []string{}
|
||||
for _, i := range "0123456789" {
|
||||
tmpFile := tmpDir + "cid" + string(i)
|
||||
podName := "rudolph" + string(i)
|
||||
// Create a pod with --pod-id-file.
|
||||
session := podmanTest.Podman([]string{"pod", "create", "--name", podName, "--pod-id-file", tmpFile})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
// Create container inside the pod.
|
||||
session = podmanTest.Podman([]string{"create", "--pod", podName, ALPINE, "top"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
// Append the id files along with the command.
|
||||
podIDFiles = append(podIDFiles, "--pod-id-file")
|
||||
podIDFiles = append(podIDFiles, tmpFile)
|
||||
}
|
||||
|
||||
cmd := []string{"pod", "start"}
|
||||
cmd = append(cmd, podIDFiles...)
|
||||
session := podmanTest.Podman(cmd)
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(20)) // 10*(infra+top)
|
||||
})
|
||||
|
||||
It("podman pod create --infra-conmon-pod create + start", func() {
|
||||
tmpDir, err := ioutil.TempDir("", "")
|
||||
Expect(err).To(BeNil())
|
||||
tmpFile := tmpDir + "podID"
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
podName := "rudolph"
|
||||
// Create a pod with --infra-conmon-pid.
|
||||
session := podmanTest.Podman([]string{"pod", "create", "--name", podName, "--infra-conmon-pidfile", tmpFile})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"pod", "start", podName})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) // infra
|
||||
|
||||
readFirstLine := func(path string) string {
|
||||
content, err := ioutil.ReadFile(path)
|
||||
Expect(err).To(BeNil())
|
||||
return strings.Split(string(content), "\n")[0]
|
||||
}
|
||||
|
||||
// Read the infra-conmon-pidfile and perform some sanity checks
|
||||
// on the pid.
|
||||
infraConmonPID := readFirstLine(tmpFile)
|
||||
_, err = strconv.Atoi(infraConmonPID) // Make sure it's a proper integer
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
cmdline := readFirstLine(fmt.Sprintf("/proc/%s/cmdline", infraConmonPID))
|
||||
Expect(cmdline).To(ContainSubstring("/conmon"))
|
||||
})
|
||||
|
||||
})
|
||||
|
@ -1,6 +1,7 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
. "github.com/containers/libpod/test/utils"
|
||||
@ -175,4 +176,72 @@ var _ = Describe("Podman pod stop", func() {
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(125))
|
||||
})
|
||||
|
||||
It("podman pod start/stop single pod via --pod-id-file", func() {
|
||||
tmpDir, err := ioutil.TempDir("", "")
|
||||
Expect(err).To(BeNil())
|
||||
tmpFile := tmpDir + "podID"
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
podName := "rudolph"
|
||||
|
||||
// Create a pod with --pod-id-file.
|
||||
session := podmanTest.Podman([]string{"pod", "create", "--name", podName, "--pod-id-file", tmpFile})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
// Create container inside the pod.
|
||||
session = podmanTest.Podman([]string{"create", "--pod", podName, ALPINE, "top"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"pod", "start", "--pod-id-file", tmpFile})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2)) // infra+top
|
||||
|
||||
session = podmanTest.Podman([]string{"pod", "stop", "--pod-id-file", tmpFile})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
||||
})
|
||||
|
||||
It("podman pod start/stop multiple pods via --pod-id-file", func() {
|
||||
tmpDir, err := ioutil.TempDir("", "")
|
||||
Expect(err).To(BeNil())
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
podIDFiles := []string{}
|
||||
for _, i := range "0123456789" {
|
||||
tmpFile := tmpDir + "cid" + string(i)
|
||||
podName := "rudolph" + string(i)
|
||||
// Create a pod with --pod-id-file.
|
||||
session := podmanTest.Podman([]string{"pod", "create", "--name", podName, "--pod-id-file", tmpFile})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
// Create container inside the pod.
|
||||
session = podmanTest.Podman([]string{"create", "--pod", podName, ALPINE, "top"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
|
||||
// Append the id files along with the command.
|
||||
podIDFiles = append(podIDFiles, "--pod-id-file")
|
||||
podIDFiles = append(podIDFiles, tmpFile)
|
||||
}
|
||||
|
||||
cmd := []string{"pod", "start"}
|
||||
cmd = append(cmd, podIDFiles...)
|
||||
session := podmanTest.Podman(cmd)
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(20)) // 10*(infra+top)
|
||||
|
||||
cmd = []string{"pod", "stop"}
|
||||
cmd = append(cmd, podIDFiles...)
|
||||
session = podmanTest.Podman(cmd)
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user