mirror of
https://github.com/containers/podman.git
synced 2025-06-26 12:56:45 +08:00

Currenly if a user specifies the name or ID of an external storage container, we report an error to them. buildah from scratch working-container-2 podman rm working-container-2 Error: no container with name or ID working-container-2 found: no such container Since the user specified the correct name and the container is in storage we force them to specify --storage to remove it. This is a bad experience for the user. This change will just remove the container from storage. If the container is known by libpod, it will remove the container from libpod as well. The podman rm --storage option has been deprecated, and removed from docs. Also cleaned documented options that are not available to podman-remote. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
252 lines
7.6 KiB
Go
252 lines
7.6 KiB
Go
package integration
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
. "github.com/containers/podman/v2/test/utils"
|
|
. "github.com/onsi/ginkgo"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("Podman rm", func() {
|
|
var (
|
|
tempdir string
|
|
err error
|
|
podmanTest *PodmanTestIntegration
|
|
)
|
|
|
|
BeforeEach(func() {
|
|
tempdir, err = CreateTempDirInTempDir()
|
|
if err != nil {
|
|
os.Exit(1)
|
|
}
|
|
podmanTest = PodmanTestCreate(tempdir)
|
|
podmanTest.Setup()
|
|
podmanTest.SeedImages()
|
|
})
|
|
|
|
AfterEach(func() {
|
|
podmanTest.Cleanup()
|
|
f := CurrentGinkgoTestDescription()
|
|
processTestResult(f)
|
|
|
|
})
|
|
|
|
It("podman rm stopped container", func() {
|
|
_, ec, cid := podmanTest.RunLsContainer("")
|
|
Expect(ec).To(Equal(0))
|
|
|
|
result := podmanTest.Podman([]string{"rm", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result.ExitCode()).To(Equal(0))
|
|
})
|
|
|
|
It("podman rm refuse to remove a running container", func() {
|
|
session := podmanTest.RunTopContainer("")
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
cid := session.OutputToString()
|
|
|
|
result := podmanTest.Podman([]string{"rm", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result.ExitCode()).To(Equal(2))
|
|
})
|
|
|
|
It("podman rm created container", func() {
|
|
session := podmanTest.Podman([]string{"create", ALPINE, "ls"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
cid := session.OutputToString()
|
|
|
|
result := podmanTest.Podman([]string{"rm", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result.ExitCode()).To(Equal(0))
|
|
})
|
|
|
|
It("podman container rm created container", func() {
|
|
session := podmanTest.Podman([]string{"container", "create", ALPINE, "ls"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
cid := session.OutputToString()
|
|
|
|
result := podmanTest.Podman([]string{"container", "rm", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result.ExitCode()).To(Equal(0))
|
|
})
|
|
|
|
It("podman rm running container with -f", func() {
|
|
session := podmanTest.RunTopContainer("")
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
cid := session.OutputToString()
|
|
|
|
result := podmanTest.Podman([]string{"rm", "-f", cid})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result.ExitCode()).To(Equal(0))
|
|
})
|
|
|
|
It("podman rm all containers", func() {
|
|
session := podmanTest.Podman([]string{"create", ALPINE, "ls"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
|
|
session = podmanTest.Podman([]string{"create", ALPINE, "ls"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
|
|
session = podmanTest.Podman([]string{"create", ALPINE, "ls"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
|
|
result := podmanTest.Podman([]string{"rm", "-a"})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result.ExitCode()).To(Equal(0))
|
|
})
|
|
|
|
It("podman rm all containers with one running and short options", func() {
|
|
session := podmanTest.Podman([]string{"create", ALPINE, "ls"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
|
|
session = podmanTest.Podman([]string{"create", ALPINE, "ls"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
|
|
session = podmanTest.RunTopContainer("")
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
|
|
result := podmanTest.Podman([]string{"rm", "-af"})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result.ExitCode()).To(Equal(0))
|
|
})
|
|
|
|
It("podman rm the latest container", func() {
|
|
session := podmanTest.Podman([]string{"create", ALPINE, "ls"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
|
|
_, ec, cid := podmanTest.RunLsContainer("test1")
|
|
Expect(ec).To(Equal(0))
|
|
|
|
latest := "-l"
|
|
if IsRemote() {
|
|
latest = "test1"
|
|
}
|
|
result := podmanTest.Podman([]string{"rm", latest})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result.ExitCode()).To(Equal(0))
|
|
output := result.OutputToString()
|
|
Expect(output).To(ContainSubstring(cid))
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
})
|
|
|
|
It("podman rm --cidfile", func() {
|
|
|
|
tmpDir, err := ioutil.TempDir("", "")
|
|
Expect(err).To(BeNil())
|
|
tmpFile := tmpDir + "cid"
|
|
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
session := podmanTest.Podman([]string{"create", "--cidfile", tmpFile, ALPINE, "ls"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
cid := session.OutputToStringArray()[0]
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
result := podmanTest.Podman([]string{"rm", "--cidfile", tmpFile})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result.ExitCode()).To(Equal(0))
|
|
output := result.OutputToString()
|
|
Expect(output).To(ContainSubstring(cid))
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(0))
|
|
})
|
|
|
|
It("podman rm multiple --cidfile", func() {
|
|
|
|
tmpDir, err := ioutil.TempDir("", "")
|
|
Expect(err).To(BeNil())
|
|
tmpFile1 := tmpDir + "cid-1"
|
|
tmpFile2 := tmpDir + "cid-2"
|
|
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
session := podmanTest.Podman([]string{"create", "--cidfile", tmpFile1, ALPINE, "ls"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
cid1 := session.OutputToStringArray()[0]
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
session = podmanTest.Podman([]string{"create", "--cidfile", tmpFile2, ALPINE, "ls"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
cid2 := session.OutputToStringArray()[0]
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(2))
|
|
|
|
result := podmanTest.Podman([]string{"rm", "--cidfile", tmpFile1, "--cidfile", tmpFile2})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result.ExitCode()).To(Equal(0))
|
|
output := result.OutputToString()
|
|
Expect(output).To(ContainSubstring(cid1))
|
|
Expect(output).To(ContainSubstring(cid2))
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(0))
|
|
})
|
|
|
|
It("podman rm invalid --latest and --cidfile and --all", func() {
|
|
SkipIfRemote("Verifying --latest flag")
|
|
|
|
result := podmanTest.Podman([]string{"rm", "--cidfile", "foobar", "--latest"})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result.ExitCode()).To(Equal(125))
|
|
|
|
result = podmanTest.Podman([]string{"rm", "--cidfile", "foobar", "--all"})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result.ExitCode()).To(Equal(125))
|
|
|
|
result = podmanTest.Podman([]string{"rm", "--cidfile", "foobar", "--all", "--latest"})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result.ExitCode()).To(Equal(125))
|
|
|
|
result = podmanTest.Podman([]string{"rm", "--latest", "--all"})
|
|
result.WaitWithDefaultTimeout()
|
|
Expect(result.ExitCode()).To(Equal(125))
|
|
})
|
|
|
|
It("podman rm bogus container", func() {
|
|
session := podmanTest.Podman([]string{"rm", "bogus"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(1))
|
|
})
|
|
|
|
It("podman rm bogus container and a running container", func() {
|
|
session := podmanTest.RunTopContainer("test1")
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
|
|
session = podmanTest.Podman([]string{"rm", "bogus", "test1"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(1))
|
|
|
|
session = podmanTest.Podman([]string{"rm", "test1", "bogus"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(1))
|
|
})
|
|
|
|
It("podman rm --ignore bogus container and a running container", func() {
|
|
session := podmanTest.RunTopContainer("test1")
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
|
|
session = podmanTest.Podman([]string{"rm", "--force", "--ignore", "bogus", "test1"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
|
|
session = podmanTest.Podman([]string{"rm", "--ignore", "test1", "bogus"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session.ExitCode()).To(Equal(0))
|
|
})
|
|
})
|