diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2020-06-10 16:26:24 +0200 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2020-06-15 15:53:51 +0200 |
commit | fa3b8a75c4ec571f8cbb2622ea624b42bc5c2472 (patch) | |
tree | 23b4ebcca03d20cedadfa094d51469d55e756b83 /test | |
parent | f4c3b718eb22a161a897a6ed55d10f3a07e31aa8 (diff) | |
download | podman-fa3b8a75c4ec571f8cbb2622ea624b42bc5c2472.tar.gz podman-fa3b8a75c4ec571f8cbb2622ea624b42bc5c2472.tar.bz2 podman-fa3b8a75c4ec571f8cbb2622ea624b42bc5c2472.zip |
{create,run} --replace
Add a `--replace` flag to the `container {create,run}` commands.
If another container with the same name already exists, it will
be replaced and removed.
Adding this flag is motivated by #5485 to make running Podman in systemd
units (or any other scripts/automation) more robust. In case of a
crash, a container may not be removed by a sytemd unit anymore. The
`--replace` flag allows for supporting crashes.
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/e2e/create_test.go | 15 | ||||
-rw-r--r-- | test/e2e/run_test.go | 15 |
2 files changed, 30 insertions, 0 deletions
diff --git a/test/e2e/create_test.go b/test/e2e/create_test.go index b9a1ff83d..822e470f2 100644 --- a/test/e2e/create_test.go +++ b/test/e2e/create_test.go @@ -429,4 +429,19 @@ var _ = Describe("Podman create", func() { Expect(len(data)).To(Equal(1)) Expect(data[0].HostConfig.NanoCpus).To(Equal(int64(nanoCPUs))) }) + + It("podman create --replace", func() { + // Make sure we error out with --name. + session := podmanTest.Podman([]string{"create", "--replace", ALPINE, "/bin/sh"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(125)) + + // Create and replace 5 times in a row the "same" container. + ctrName := "testCtr" + for i := 0; i < 5; i++ { + session = podmanTest.Podman([]string{"create", "--replace", "--name", ctrName, ALPINE, "/bin/sh"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + } + }) }) diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go index 59215c7e5..76944b3db 100644 --- a/test/e2e/run_test.go +++ b/test/e2e/run_test.go @@ -931,4 +931,19 @@ USER mail` session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) }) + + It("podman run --replace", func() { + // Make sure we error out with --name. + session := podmanTest.Podman([]string{"create", "--replace", ALPINE, "/bin/sh"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(125)) + + // Run and replace 5 times in a row the "same" container. + ctrName := "testCtr" + for i := 0; i < 5; i++ { + session := podmanTest.Podman([]string{"run", "--detach", "--replace", "--name", ctrName, ALPINE, "/bin/sh"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + } + }) }) |