podman-generate-systemd --new

Add a --new flag to podman-generate-systemd to create a new container
via podman-run instead of starting an existing container.

Creating a new container presents the challenge to find a reverse
mapping from a container to the CLI flags it can be created with.  We
are doing this via `(Container).Config.CreateCommand` field, which
includes a copy of the process' command from procFS at creating time.
This field may not be useful when the container was not created via the
Podman CLI (e.g., via a Python script).  Hence, we do not guarantee the
correctness of the generated files.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2020-01-09 12:27:24 +01:00
parent f3fc10feb4
commit 816e50ba02
7 changed files with 153 additions and 11 deletions

View File

@ -177,4 +177,32 @@ var _ = Describe("Podman generate systemd", func() {
found, _ = session.GrepString("/container-foo-1.service")
Expect(found).To(BeTrue())
})
It("podman generate systemd --new", func() {
n := podmanTest.Podman([]string{"create", "--name", "foo", "alpine", "top"})
n.WaitWithDefaultTimeout()
Expect(n.ExitCode()).To(Equal(0))
session := podmanTest.Podman([]string{"generate", "systemd", "--timeout", "42", "--name", "--new", "foo"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
// Grepping the output (in addition to unit tests)
found, _ := session.GrepString("# container-foo.service")
Expect(found).To(BeTrue())
found, _ = session.GrepString("stop --cidfile /%t/%n-cid -t 42")
Expect(found).To(BeTrue())
})
It("podman generate systemd --new pod", func() {
n := podmanTest.Podman([]string{"pod", "create", "--name", "foo"})
n.WaitWithDefaultTimeout()
Expect(n.ExitCode()).To(Equal(0))
session := podmanTest.Podman([]string{"generate", "systemd", "--timeout", "42", "--name", "--new", "foo"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(125))
})
})