mirror of
https://github.com/containers/podman.git
synced 2025-05-20 08:36:23 +08:00

Before this, for some special Podman commands (system reset, system migrate, system renumber), Podman would create a first Libpod runtime to do initialization and flag parsing, then stop that runtime and create an entirely new runtime to perform the actual task. This is an artifact of the pre-Podman 2.0 days, when there was almost no indirection between Libpod and the CLI, and we only used one runtime because we didn't need a second runtime for flag parsing and basic init. This system was clunky, and apparently, very buggy. When we migrated to SQLite, some logic was introduced where we'd select a different database location based on whether or not Libpod's StaticDir was manually set - which differed between the first invocation of Libpod and the second. So we'd get a different database for some commands (like `system reset`) and they would not be able to see existing containers, meaning they would not function properly. The immediate cause is obviously the SQLite behavior, but I'm certain there's a lot more baggage hiding behind this multiple Libpod runtime logic, so let's just refactor it out. It doesn't make sense, and complicates the code. Instead, make Reset, Renumber, and Migrate methods of the libpod Runtime. For Reset and Renumber, we can shut the runtime down afterwards to achieve the desired effect (no valid runtime after). Then pipe all of them through the ContainerEngine so cmd/podman can access them. As part of this, remove the SystemEngine part of pkg/domain. This was supposed to encompass these "special" commands, but every command in SystemEngine is actually a ContainerEngine command. Reset, Renumber, Migrate - they all need a full Libpod and access to all containers. There's no point to a separate engine if it just wraps Libpod in the exact same way as ContainerEngine. This consolidation saves us a bit more code and complexity. Signed-off-by: Matt Heon <mheon@redhat.com> <MH: Fixed cherry-pick conflicts for v4.8 branch> Signed-off-by: Matt Heon <mheon@redhat.com>
108 lines
3.9 KiB
Go
108 lines
3.9 KiB
Go
package integration
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
. "github.com/containers/podman/v4/test/utils"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
// system reset must run serial: https://github.com/containers/podman/issues/17903
|
|
var _ = Describe("podman system reset", Serial, func() {
|
|
|
|
It("podman system reset", func() {
|
|
SkipIfRemote("system reset not supported on podman --remote")
|
|
// system reset will not remove additional store images, so need to grab length
|
|
useCustomNetworkDir(podmanTest, tempdir)
|
|
|
|
session := podmanTest.Podman([]string{"rmi", "--force", "--all"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(ExitCleanly())
|
|
|
|
session = podmanTest.Podman([]string{"images", "-n"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(ExitCleanly())
|
|
l := len(session.OutputToStringArray())
|
|
|
|
podmanTest.AddImageToRWStore(ALPINE)
|
|
session = podmanTest.Podman([]string{"volume", "create", "data"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(ExitCleanly())
|
|
|
|
session = podmanTest.Podman([]string{"create", "-v", "data:/data", ALPINE, "echo", "hello"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(ExitCleanly())
|
|
|
|
session = podmanTest.Podman([]string{"network", "create"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(ExitCleanly())
|
|
|
|
session = podmanTest.Podman([]string{"system", "reset", "-f"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(ExitCleanly())
|
|
|
|
Expect(session.ErrorToString()).To(Not(ContainSubstring("Failed to add pause process")))
|
|
Expect(session.ErrorToString()).To(Not(ContainSubstring("/usr/share/containers/storage.conf")))
|
|
|
|
session = podmanTest.Podman([]string{"images", "-n"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(ExitCleanly())
|
|
Expect(session.OutputToStringArray()).To(HaveLen(l))
|
|
|
|
session = podmanTest.Podman([]string{"volume", "ls"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(ExitCleanly())
|
|
Expect(session.OutputToStringArray()).To(BeEmpty())
|
|
|
|
session = podmanTest.Podman([]string{"container", "ls", "-q"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(ExitCleanly())
|
|
Expect(session.OutputToStringArray()).To(BeEmpty())
|
|
|
|
session = podmanTest.Podman([]string{"network", "ls", "-q"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(ExitCleanly())
|
|
// default network should exists
|
|
Expect(session.OutputToStringArray()).To(HaveLen(1))
|
|
|
|
// TODO: machine tests currently don't run outside of the machine test pkg
|
|
// no machines are created here to cleanup
|
|
// machine commands are rootless only
|
|
if isRootless() {
|
|
session = podmanTest.Podman([]string{"machine", "list", "-q"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(ExitCleanly())
|
|
Expect(session.OutputToStringArray()).To(BeEmpty())
|
|
}
|
|
})
|
|
|
|
It("system reset completely removes container", func() {
|
|
SkipIfRemote("system reset not supported on podman --remote")
|
|
useCustomNetworkDir(podmanTest, tempdir)
|
|
|
|
rmi := podmanTest.Podman([]string{"rmi", "--force", "--all"})
|
|
rmi.WaitWithDefaultTimeout()
|
|
Expect(rmi).Should(ExitCleanly())
|
|
podmanTest.AddImageToRWStore(ALPINE)
|
|
|
|
// The name ensures that we have a Libpod resource that we'll
|
|
// hit if we recreate the container after a reset and it still
|
|
// exists. The port does the same for a system-level resource.
|
|
ctrName := "testctr"
|
|
port1 := GetPort()
|
|
port2 := GetPort()
|
|
session := podmanTest.Podman([]string{"run", "--name", ctrName, "-p", fmt.Sprintf("%d:%d", port1, port2), "-d", ALPINE, "top"})
|
|
session.WaitWithDefaultTimeout()
|
|
Expect(session).Should(ExitCleanly())
|
|
|
|
reset := podmanTest.Podman([]string{"system", "reset", "--force"})
|
|
reset.WaitWithDefaultTimeout()
|
|
Expect(reset).Should(ExitCleanly())
|
|
|
|
session2 := podmanTest.Podman([]string{"run", "--name", ctrName, "-p", fmt.Sprintf("%d:%d", port1, port2), "-d", ALPINE, "top"})
|
|
session2.WaitWithDefaultTimeout()
|
|
Expect(session2).Should(ExitCleanly())
|
|
})
|
|
})
|