summaryrefslogtreecommitdiff
path: root/test/e2e/checkpoint_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'test/e2e/checkpoint_test.go')
-rw-r--r--test/e2e/checkpoint_test.go172
1 files changed, 171 insertions, 1 deletions
diff --git a/test/e2e/checkpoint_test.go b/test/e2e/checkpoint_test.go
index 75310b961..3270ce685 100644
--- a/test/e2e/checkpoint_test.go
+++ b/test/e2e/checkpoint_test.go
@@ -4,6 +4,7 @@ import (
"net"
"os"
"os/exec"
+ "strings"
"github.com/containers/podman/v2/pkg/criu"
. "github.com/containers/podman/v2/test/utils"
@@ -622,7 +623,7 @@ var _ = Describe("Podman checkpoint", func() {
result := podmanTest.Podman([]string{"container", "checkpoint", "-l"})
result.WaitWithDefaultTimeout()
Expect(result).To(ExitWithError())
- Expect(result.ErrorToString()).To(ContainSubstring("Cannot checkpoint containers that have been started with '--rm'"))
+ Expect(result.ErrorToString()).To(ContainSubstring("cannot checkpoint containers that have been started with '--rm'"))
// Checkpointing with --export should still work
fileName := "/tmp/checkpoint-" + cid + ".tar.gz"
@@ -652,4 +653,173 @@ var _ = Describe("Podman checkpoint", func() {
// Remove exported checkpoint
os.Remove(fileName)
})
+
+ It("podman checkpoint a container with volumes", func() {
+ session := podmanTest.Podman([]string{
+ "build", "-f", "build/basicalpine/Containerfile.volume", "-t", "test-cr-volume",
+ })
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ // Start the container
+ localRunString := getRunString([]string{
+ "--rm",
+ "-v", "/volume1",
+ "-v", "my-test-vol:/volume2",
+ "test-cr-volume",
+ "top",
+ })
+ session = podmanTest.Podman(localRunString)
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
+
+ cid := session.OutputToString()
+
+ // Add file in volume0
+ result := podmanTest.Podman([]string{
+ "exec", "-l", "/bin/sh", "-c", "echo " + cid + " > /volume0/test.output",
+ })
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+
+ // Add file in volume1
+ result = podmanTest.Podman([]string{
+ "exec", "-l", "/bin/sh", "-c", "echo " + cid + " > /volume1/test.output",
+ })
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+
+ // Add file in volume2
+ result = podmanTest.Podman([]string{
+ "exec", "-l", "/bin/sh", "-c", "echo " + cid + " > /volume2/test.output",
+ })
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+
+ checkpointFileName := "/tmp/checkpoint-" + cid + ".tar.gz"
+
+ // Checkpoint the container
+ result = podmanTest.Podman([]string{"container", "checkpoint", "-l", "-e", checkpointFileName})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
+ Expect(podmanTest.NumberOfContainers()).To(Equal(0))
+
+ // Restore container should fail because named volume still exists
+ result = podmanTest.Podman([]string{"container", "restore", "-i", checkpointFileName})
+ result.WaitWithDefaultTimeout()
+ Expect(result).To(ExitWithError())
+ Expect(result.ErrorToString()).To(ContainSubstring(
+ "volume with name my-test-vol already exists. Use --ignore-volumes to not restore content of volumes",
+ ))
+
+ // Remove named volume
+ session = podmanTest.Podman([]string{"volume", "rm", "my-test-vol"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ // Restoring container
+ result = podmanTest.Podman([]string{"container", "restore", "-i", checkpointFileName})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
+ Expect(podmanTest.NumberOfContainers()).To(Equal(1))
+ Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up"))
+
+ // Validate volume0 content
+ result = podmanTest.Podman([]string{"exec", "-l", "cat", "/volume0/test.output"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(result.OutputToString()).To(ContainSubstring(cid))
+
+ // Validate volume1 content
+ result = podmanTest.Podman([]string{"exec", "-l", "cat", "/volume1/test.output"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(result.OutputToString()).To(ContainSubstring(cid))
+
+ // Validate volume2 content
+ result = podmanTest.Podman([]string{"exec", "-l", "cat", "/volume2/test.output"})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(result.OutputToString()).To(ContainSubstring(cid))
+
+ // Remove exported checkpoint
+ os.Remove(checkpointFileName)
+ })
+
+ It("podman checkpoint container with --pre-checkpoint", func() {
+ if !strings.Contains(podmanTest.OCIRuntime, "runc") {
+ Skip("Test only works on runc 1.0-rc3 or higher.")
+ }
+ localRunString := getRunString([]string{ALPINE, "top"})
+ session := podmanTest.Podman(localRunString)
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ cid := session.OutputToString()
+
+ result := podmanTest.Podman([]string{"container", "checkpoint", "-P", cid})
+ result.WaitWithDefaultTimeout()
+
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
+ Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up"))
+
+ result = podmanTest.Podman([]string{"container", "checkpoint", "--with-previous", cid})
+ result.WaitWithDefaultTimeout()
+
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
+ Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited"))
+
+ result = podmanTest.Podman([]string{"container", "restore", cid})
+ result.WaitWithDefaultTimeout()
+
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
+ Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up"))
+ })
+
+ It("podman checkpoint container with --pre-checkpoint and export (migration)", func() {
+ if !strings.Contains(podmanTest.OCIRuntime, "runc") {
+ Skip("Test only works on runc 1.0-rc3 or higher.")
+ }
+ localRunString := getRunString([]string{ALPINE, "top"})
+ session := podmanTest.Podman(localRunString)
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ cid := session.OutputToString()
+ preCheckpointFileName := "/tmp/pre-checkpoint-" + cid + ".tar.gz"
+ checkpointFileName := "/tmp/checkpoint-" + cid + ".tar.gz"
+
+ result := podmanTest.Podman([]string{"container", "checkpoint", "-P", "-e", preCheckpointFileName, cid})
+ result.WaitWithDefaultTimeout()
+
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
+ Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up"))
+
+ result = podmanTest.Podman([]string{"container", "checkpoint", "--with-previous", "-e", checkpointFileName, cid})
+ result.WaitWithDefaultTimeout()
+
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
+ Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited"))
+
+ result = podmanTest.Podman([]string{"rm", "-f", cid})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
+
+ result = podmanTest.Podman([]string{"container", "restore", "-i", checkpointFileName, "--import-previous", preCheckpointFileName})
+ result.WaitWithDefaultTimeout()
+
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
+ Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up"))
+
+ os.Remove(checkpointFileName)
+ os.Remove(preCheckpointFileName)
+ })
})