summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/containers/checkpoint.go1
-rw-r--r--cmd/podman/containers/restore.go1
-rw-r--r--docs/source/markdown/podman-container-checkpoint.1.md8
-rw-r--r--docs/source/markdown/podman-container-restore.1.md8
-rw-r--r--docs/source/markdown/podman-create.1.md10
-rw-r--r--docs/source/markdown/podman-run.1.md10
-rw-r--r--libpod/container_api.go3
-rw-r--r--libpod/networking_linux.go20
-rw-r--r--libpod/oci_conmon_linux.go6
-rw-r--r--pkg/bindings/containers/types.go2
-rw-r--r--pkg/bindings/containers/types_checkpoint_options.go15
-rw-r--r--pkg/bindings/containers/types_restore_options.go15
-rw-r--r--pkg/domain/entities/containers.go2
-rw-r--r--pkg/domain/infra/abi/containers.go1
-rw-r--r--pkg/domain/infra/tunnel/containers.go2
-rw-r--r--pkg/machine/ignition.go2
-rw-r--r--pkg/specgenutil/volumes.go2
-rw-r--r--pkg/util/filters.go25
-rw-r--r--pkg/util/mountOpts.go1
-rw-r--r--test/e2e/checkpoint_test.go37
-rw-r--r--test/e2e/volume_ls_test.go11
-rw-r--r--test/system/520-checkpoint.bats175
22 files changed, 342 insertions, 15 deletions
diff --git a/cmd/podman/containers/checkpoint.go b/cmd/podman/containers/checkpoint.go
index d92bc3e5e..e8dd25978 100644
--- a/cmd/podman/containers/checkpoint.go
+++ b/cmd/podman/containers/checkpoint.go
@@ -55,6 +55,7 @@ func init() {
flags.BoolVarP(&checkpointOptions.Keep, "keep", "k", false, "Keep all temporary checkpoint files")
flags.BoolVarP(&checkpointOptions.LeaveRunning, "leave-running", "R", false, "Leave the container running after writing checkpoint to disk")
flags.BoolVar(&checkpointOptions.TCPEstablished, "tcp-established", false, "Checkpoint a container with established TCP connections")
+ flags.BoolVar(&checkpointOptions.FileLocks, "file-locks", false, "Checkpoint a container with file locks")
flags.BoolVarP(&checkpointOptions.All, "all", "a", false, "Checkpoint all running containers")
exportFlagName := "export"
diff --git a/cmd/podman/containers/restore.go b/cmd/podman/containers/restore.go
index 4ac14001a..cf0ad5f80 100644
--- a/cmd/podman/containers/restore.go
+++ b/cmd/podman/containers/restore.go
@@ -53,6 +53,7 @@ func init() {
flags.BoolVarP(&restoreOptions.All, "all", "a", false, "Restore all checkpointed containers")
flags.BoolVarP(&restoreOptions.Keep, "keep", "k", false, "Keep all temporary checkpoint files")
flags.BoolVar(&restoreOptions.TCPEstablished, "tcp-established", false, "Restore a container with established TCP connections")
+ flags.BoolVar(&restoreOptions.FileLocks, "file-locks", false, "Restore a container with file locks")
importFlagName := "import"
flags.StringVarP(&restoreOptions.Import, importFlagName, "i", "", "Restore from exported checkpoint archive (tar.gz)")
diff --git a/docs/source/markdown/podman-container-checkpoint.1.md b/docs/source/markdown/podman-container-checkpoint.1.md
index 1faa40a94..200920ca9 100644
--- a/docs/source/markdown/podman-container-checkpoint.1.md
+++ b/docs/source/markdown/podman-container-checkpoint.1.md
@@ -110,6 +110,14 @@ restore. Defaults to not checkpointing *containers* with established TCP
connections.\
The default is **false**.
+#### **--file-locks**
+
+Checkpoint a *container* with file locks. If an application running in the container
+is using file locks, this OPTION is required during checkpoint and restore. Otherwise
+checkpointing *containers* with file locks is expected to fail. If file locks are not
+used, this option is ignored.\
+The default is **false**.
+
#### **--with-previous**
Check out the *container* with previous criu image files in pre-dump. It only works on `runc 1.0-rc3` or `higher`.\
diff --git a/docs/source/markdown/podman-container-restore.1.md b/docs/source/markdown/podman-container-restore.1.md
index be67792fc..10477fc77 100644
--- a/docs/source/markdown/podman-container-restore.1.md
+++ b/docs/source/markdown/podman-container-restore.1.md
@@ -143,6 +143,14 @@ option is ignored. Defaults to not restoring *containers* with established TCP
connections.\
The default is **false**.
+#### **--file-locks**
+
+Restore a *container* with file locks. This option is required to
+restore file locks from a checkpoint image. If the checkpoint image
+does not contain file locks, this option is ignored. Defaults to not
+restoring file locks.\
+The default is **false**.
+
## EXAMPLE
Restores the container "mywebserver".
```
diff --git a/docs/source/markdown/podman-create.1.md b/docs/source/markdown/podman-create.1.md
index 811d16880..b58fd1e18 100644
--- a/docs/source/markdown/podman-create.1.md
+++ b/docs/source/markdown/podman-create.1.md
@@ -606,7 +606,9 @@ Current supported mount TYPEs are **bind**, **volume**, **image**, **tmpfs** and
· ro, readonly: true or false (default).
- . U, chown: true or false (default). Change recursively the owner and group of the source volume based on the UID and GID of the container.
+ . U, chown: true or false (default). Change recursively the owner and group of the source volume based on the UID and GID of the container.
+
+ · idmap: true or false (default). If specified, create an idmapped mount to the target user namespace in the container.
Options specific to image:
@@ -622,7 +624,9 @@ Current supported mount TYPEs are **bind**, **volume**, **image**, **tmpfs** and
. relabel: shared, private.
- . U, chown: true or false (default). Change recursively the owner and group of the source volume based on the UID and GID of the container.
+ · idmap: true or false (default). If specified, create an idmapped mount to the target user namespace in the container.
+
+ . U, chown: true or false (default). Change recursively the owner and group of the source volume based on the UID and GID of the container.
Options specific to tmpfs:
@@ -636,7 +640,7 @@ Current supported mount TYPEs are **bind**, **volume**, **image**, **tmpfs** and
· notmpcopyup: Disable copying files from the image to the tmpfs.
- . U, chown: true or false (default). Change recursively the owner and group of the source volume based on the UID and GID of the container.
+ . U, chown: true or false (default). Change recursively the owner and group of the source volume based on the UID and GID of the container.
Options specific to devpts:
diff --git a/docs/source/markdown/podman-run.1.md b/docs/source/markdown/podman-run.1.md
index 3d908444b..90c456544 100644
--- a/docs/source/markdown/podman-run.1.md
+++ b/docs/source/markdown/podman-run.1.md
@@ -633,7 +633,9 @@ Current supported mount TYPEs are **bind**, **volume**, **image**, **tmpfs** and
· ro, readonly: true or false (default).
- . U, chown: true or false (default). Change recursively the owner and group of the source volume based on the UID and GID of the container.
+ . U, chown: true or false (default). Change recursively the owner and group of the source volume based on the UID and GID of the container.
+
+ · idmap: true or false (default). If specified, create an idmapped mount to the target user namespace in the container.
Options specific to image:
@@ -649,7 +651,9 @@ Current supported mount TYPEs are **bind**, **volume**, **image**, **tmpfs** and
. relabel: shared, private.
- . U, chown: true or false (default). Change recursively the owner and group of the source volume based on the UID and GID of the container.
+ · idmap: true or false (default). If specified, create an idmapped mount to the target user namespace in the container.
+
+ . U, chown: true or false (default). Change recursively the owner and group of the source volume based on the UID and GID of the container.
Options specific to tmpfs:
@@ -663,7 +667,7 @@ Current supported mount TYPEs are **bind**, **volume**, **image**, **tmpfs** and
· notmpcopyup: Disable copying files from the image to the tmpfs.
- . U, chown: true or false (default). Change recursively the owner and group of the source volume based on the UID and GID of the container.
+ . U, chown: true or false (default). Change recursively the owner and group of the source volume based on the UID and GID of the container.
Options specific to devpts:
diff --git a/libpod/container_api.go b/libpod/container_api.go
index a41bb03df..7ae9f497c 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -798,6 +798,9 @@ type ContainerCheckpointOptions struct {
// how much time each component in the stack requires to
// checkpoint a container.
PrintStats bool
+ // FileLocks tells the API to checkpoint/restore a container
+ // with file-locks
+ FileLocks bool
}
// Checkpoint checkpoints a container
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go
index 9be600bb4..314a74427 100644
--- a/libpod/networking_linux.go
+++ b/libpod/networking_linux.go
@@ -4,6 +4,7 @@ package libpod
import (
"crypto/rand"
+ "crypto/sha1"
"fmt"
"io/ioutil"
"net"
@@ -400,10 +401,7 @@ func (r *Runtime) GetRootlessNetNs(new bool) (*RootlessNetNS, error) {
return nil, nil
}
var rootlessNetNS *RootlessNetNS
- runDir, err := util.GetRuntimeDir()
- if err != nil {
- return nil, err
- }
+ runDir := r.config.Engine.TmpDir
lfile := filepath.Join(runDir, "rootless-netns.lock")
lock, err := lockfile.GetLockfile(lfile)
@@ -429,7 +427,15 @@ func (r *Runtime) GetRootlessNetNs(new bool) (*RootlessNetNS, error) {
if err != nil {
return nil, err
}
- path := filepath.Join(nsDir, rootlessNetNsName)
+
+ // create a hash from the static dir
+ // the cleanup will check if there are running containers
+ // if you run a several libpod instances with different root/runroot directories this check will fail
+ // we want one netns for each libpod static dir so we use the hash to prevent name collisions
+ hash := sha1.Sum([]byte(r.config.Engine.StaticDir))
+ netnsName := fmt.Sprintf("%s-%x", rootlessNetNsName, hash[:10])
+
+ path := filepath.Join(nsDir, netnsName)
ns, err := ns.GetNS(path)
if err != nil {
if !new {
@@ -437,8 +443,8 @@ func (r *Runtime) GetRootlessNetNs(new bool) (*RootlessNetNS, error) {
return nil, errors.Wrap(err, "error getting rootless network namespace")
}
// create a new namespace
- logrus.Debug("creating rootless network namespace")
- ns, err = netns.NewNSWithName(rootlessNetNsName)
+ logrus.Debugf("creating rootless network namespace with name %q", netnsName)
+ ns, err = netns.NewNSWithName(netnsName)
if err != nil {
return nil, errors.Wrap(err, "error creating rootless network namespace")
}
diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go
index c31ac840f..bcf45ec8d 100644
--- a/libpod/oci_conmon_linux.go
+++ b/libpod/oci_conmon_linux.go
@@ -795,6 +795,9 @@ func (r *ConmonOCIRuntime) CheckpointContainer(ctr *Container, options Container
if options.TCPEstablished {
args = append(args, "--tcp-established")
}
+ if options.FileLocks {
+ args = append(args, "--file-locks")
+ }
if !options.PreCheckPoint && options.KeepRunning {
args = append(args, "--leave-running")
}
@@ -1106,6 +1109,9 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
if restoreOptions.TCPEstablished {
args = append(args, "--runtime-opt", "--tcp-established")
}
+ if restoreOptions.FileLocks {
+ args = append(args, "--runtime-opt", "--file-locks")
+ }
if restoreOptions.Pod != "" {
mountLabel := ctr.config.MountLabel
processLabel := ctr.config.ProcessLabel
diff --git a/pkg/bindings/containers/types.go b/pkg/bindings/containers/types.go
index 9f7986cbd..81a53a549 100644
--- a/pkg/bindings/containers/types.go
+++ b/pkg/bindings/containers/types.go
@@ -53,6 +53,7 @@ type CheckpointOptions struct {
PrintStats *bool
PreCheckpoint *bool
WithPrevious *bool
+ FileLocks *bool
}
//go:generate go run ../generator/generator.go RestoreOptions
@@ -69,6 +70,7 @@ type RestoreOptions struct {
Pod *string
PrintStats *bool
PublishPorts []string
+ FileLocks *bool
}
//go:generate go run ../generator/generator.go CreateOptions
diff --git a/pkg/bindings/containers/types_checkpoint_options.go b/pkg/bindings/containers/types_checkpoint_options.go
index 6301564e2..391748d76 100644
--- a/pkg/bindings/containers/types_checkpoint_options.go
+++ b/pkg/bindings/containers/types_checkpoint_options.go
@@ -136,3 +136,18 @@ func (o *CheckpointOptions) GetWithPrevious() bool {
}
return *o.WithPrevious
}
+
+// WithFileLocks set field FileLocks to given value
+func (o *CheckpointOptions) WithFileLocks(value bool) *CheckpointOptions {
+ o.FileLocks = &value
+ return o
+}
+
+// GetFileLocks returns value of field FileLocks
+func (o *CheckpointOptions) GetFileLocks() bool {
+ if o.FileLocks == nil {
+ var z bool
+ return z
+ }
+ return *o.FileLocks
+}
diff --git a/pkg/bindings/containers/types_restore_options.go b/pkg/bindings/containers/types_restore_options.go
index 8817b834b..7af2bba32 100644
--- a/pkg/bindings/containers/types_restore_options.go
+++ b/pkg/bindings/containers/types_restore_options.go
@@ -181,3 +181,18 @@ func (o *RestoreOptions) GetPublishPorts() []string {
}
return o.PublishPorts
}
+
+// WithFileLocks set field FileLocks to given value
+func (o *RestoreOptions) WithFileLocks(value bool) *RestoreOptions {
+ o.FileLocks = &value
+ return o
+}
+
+// GetFileLocks returns value of field FileLocks
+func (o *RestoreOptions) GetFileLocks() bool {
+ if o.FileLocks == nil {
+ var z bool
+ return z
+ }
+ return *o.FileLocks
+}
diff --git a/pkg/domain/entities/containers.go b/pkg/domain/entities/containers.go
index 1a4019bb1..1677c067f 100644
--- a/pkg/domain/entities/containers.go
+++ b/pkg/domain/entities/containers.go
@@ -191,6 +191,7 @@ type CheckpointOptions struct {
WithPrevious bool
Compression archive.Compression
PrintStats bool
+ FileLocks bool
}
type CheckpointReport struct {
@@ -215,6 +216,7 @@ type RestoreOptions struct {
PublishPorts []string
Pod string
PrintStats bool
+ FileLocks bool
}
type RestoreReport struct {
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index 2559c11f2..631eb3a43 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -517,6 +517,7 @@ func (ic *ContainerEngine) ContainerCheckpoint(ctx context.Context, namesOrIds [
WithPrevious: options.WithPrevious,
Compression: options.Compression,
PrintStats: options.PrintStats,
+ FileLocks: options.FileLocks,
}
if options.All {
diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go
index a7dcc923b..2127f8749 100644
--- a/pkg/domain/infra/tunnel/containers.go
+++ b/pkg/domain/infra/tunnel/containers.go
@@ -303,6 +303,7 @@ func (ic *ContainerEngine) ContainerExport(ctx context.Context, nameOrID string,
func (ic *ContainerEngine) ContainerCheckpoint(ctx context.Context, namesOrIds []string, opts entities.CheckpointOptions) ([]*entities.CheckpointReport, error) {
options := new(containers.CheckpointOptions)
+ options.WithFileLocks(opts.FileLocks)
options.WithIgnoreRootfs(opts.IgnoreRootFS)
options.WithKeep(opts.Keep)
options.WithExport(opts.Export)
@@ -352,6 +353,7 @@ func (ic *ContainerEngine) ContainerRestore(ctx context.Context, namesOrIds []st
}
options := new(containers.RestoreOptions)
+ options.WithFileLocks(opts.FileLocks)
options.WithIgnoreRootfs(opts.IgnoreRootFS)
options.WithIgnoreVolumes(opts.IgnoreVolumes)
options.WithIgnoreStaticIP(opts.IgnoreStaticIP)
diff --git a/pkg/machine/ignition.go b/pkg/machine/ignition.go
index 42d729458..e19940b22 100644
--- a/pkg/machine/ignition.go
+++ b/pkg/machine/ignition.go
@@ -81,7 +81,7 @@ func NewIgnitionFile(ign DynamicIgnition) error {
// so a listening host knows it can being interacting with it
ready := `[Unit]
Requires=dev-virtio\\x2dports-%s.device
-After=remove-moby.service
+After=remove-moby.service sshd.socket sshd.service
OnFailure=emergency.target
OnFailureJobMode=isolate
[Service]
diff --git a/pkg/specgenutil/volumes.go b/pkg/specgenutil/volumes.go
index 184bfadf8..8ff770f9c 100644
--- a/pkg/specgenutil/volumes.go
+++ b/pkg/specgenutil/volumes.go
@@ -355,6 +355,8 @@ func getBindMount(args []string) (spec.Mount, error) {
newMount.Options = append(newMount.Options, "U")
}
setOwnership = true
+ case "idmap":
+ newMount.Options = append(newMount.Options, "idmap")
case "consistency":
// Often used on MACs and mistakenly on Linux platforms.
// Since Docker ignores this option so shall we.
diff --git a/pkg/util/filters.go b/pkg/util/filters.go
index e252c1ddf..5af868873 100644
--- a/pkg/util/filters.go
+++ b/pkg/util/filters.go
@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
+ "regexp"
"strings"
"time"
@@ -94,6 +95,28 @@ func PrepareFilters(r *http.Request) (*map[string][]string, error) {
return &filterMap, nil
}
+func wildCardToRegexp(pattern string) string {
+ var result strings.Builder
+ for i, literal := range strings.Split(pattern, "*") {
+ // Replace * with .*
+ if i > 0 {
+ result.WriteString(".*")
+ }
+ // Quote any regular expression meta characters in the
+ // literal text.
+ result.WriteString(regexp.QuoteMeta(literal))
+ }
+ return result.String()
+}
+
+func matchPattern(pattern string, value string) bool {
+ if strings.Contains(pattern, "*") {
+ result, _ := regexp.MatchString(wildCardToRegexp(pattern), value)
+ return result
+ }
+ return false
+}
+
// MatchLabelFilters matches labels and returns true if they are valid
func MatchLabelFilters(filterValues []string, labels map[string]string) bool {
outer:
@@ -106,7 +129,7 @@ outer:
filterValue = ""
}
for labelKey, labelValue := range labels {
- if labelKey == filterKey && (filterValue == "" || labelValue == filterValue) {
+ if ((labelKey == filterKey) || matchPattern(filterKey, labelKey)) && (filterValue == "" || labelValue == filterValue) {
continue outer
}
}
diff --git a/pkg/util/mountOpts.go b/pkg/util/mountOpts.go
index f13dc94ec..959763dba 100644
--- a/pkg/util/mountOpts.go
+++ b/pkg/util/mountOpts.go
@@ -33,6 +33,7 @@ func ProcessOptions(options []string, isTmpfs bool, sourcePath string) ([]string
// Some options have parameters - size, mode
splitOpt := strings.SplitN(opt, "=", 2)
switch splitOpt[0] {
+ case "idmap":
case "O":
if len(options) > 1 {
return nil, errors.Wrapf(ErrDupeMntOption, "'O' option can not be used with other options")
diff --git a/test/e2e/checkpoint_test.go b/test/e2e/checkpoint_test.go
index 14545c4f9..4963b04fc 100644
--- a/test/e2e/checkpoint_test.go
+++ b/test/e2e/checkpoint_test.go
@@ -1340,4 +1340,41 @@ var _ = Describe("Podman checkpoint", func() {
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
})
+ It("podman checkpoint and restore container with --file-locks", func() {
+ if !strings.Contains(podmanTest.OCIRuntime, "runc") {
+ // TODO: Enable test for crun when this feature has been released
+ // https://github.com/containers/crun/pull/783
+ Skip("FIXME: requires crun >= 1.4")
+ }
+ localRunString := getRunString([]string{"--name", "test_name", ALPINE, "flock", "test.lock", "sleep", "100"})
+ session := podmanTest.Podman(localRunString)
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+
+ // Checkpoint is expected to fail without --file-locks
+ result := podmanTest.Podman([]string{"container", "checkpoint", "test_name"})
+ result.WaitWithDefaultTimeout()
+ Expect(result).Should(Exit(125))
+ Expect(result.ErrorToString()).To(ContainSubstring("criu failed"))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
+
+ // Checkpoint is expected to succeed with --file-locks
+ result = podmanTest.Podman([]string{"container", "checkpoint", "--file-locks", "test_name"})
+ result.WaitWithDefaultTimeout()
+ Expect(result).Should(Exit(0))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
+ Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Exited"))
+
+ result = podmanTest.Podman([]string{"container", "restore", "--file-locks", "test_name"})
+ result.WaitWithDefaultTimeout()
+
+ Expect(result).Should(Exit(0))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
+ Expect(podmanTest.GetContainerStatus()).To(ContainSubstring("Up"))
+
+ result = podmanTest.Podman([]string{"rm", "-t", "0", "-f", "test_name"})
+ result.WaitWithDefaultTimeout()
+ Expect(result).Should(Exit(0))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
+ })
})
diff --git a/test/e2e/volume_ls_test.go b/test/e2e/volume_ls_test.go
index 0dd1a2b7c..6c4b22fa5 100644
--- a/test/e2e/volume_ls_test.go
+++ b/test/e2e/volume_ls_test.go
@@ -45,6 +45,17 @@ var _ = Describe("Podman volume ls", func() {
Expect(len(session.OutputToStringArray())).To(Equal(2))
})
+ It("podman ls volume filter with a key pattern", func() {
+ session := podmanTest.Podman([]string{"volume", "create", "--label", "helloworld=world", "myvol2"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+
+ session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=hello*"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(len(session.OutputToStringArray())).To(Equal(2))
+ })
+
It("podman ls volume with JSON format", func() {
session := podmanTest.Podman([]string{"volume", "create", "myvol"})
session.WaitWithDefaultTimeout()
diff --git a/test/system/520-checkpoint.bats b/test/system/520-checkpoint.bats
new file mode 100644
index 000000000..723a20cc4
--- /dev/null
+++ b/test/system/520-checkpoint.bats
@@ -0,0 +1,175 @@
+#!/usr/bin/env bats -*- bats -*-
+#
+# test podman checkpoint. Similar in many ways to our pause tests.
+#
+
+load helpers
+
+CHECKED_ROOTLESS=
+function setup() {
+ # FIXME: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1857257
+ # TL;DR they keep fixing it then breaking it again. There's a test we
+ # could run to see if it's fixed, but it's way too complicated. Since
+ # integration tests also skip checkpoint tests on Ubuntu, do the same here.
+ if grep -qiw ubuntu /etc/os-release; then
+ skip "FIXME: checkpointing broken in Ubuntu 2004, 2104, 2110, ..."
+ fi
+
+ # None of these tests work rootless....
+ if is_rootless; then
+ # ...however, is that a genuine cast-in-stone limitation, or one
+ # that can some day be fixed? If one day some PR removes that
+ # restriction, fail loudly here, so the developer can enable tests.
+ if [[ -n "$CHECKED_ROOTLESS" ]]; then
+ run_podman '?' container checkpoint -l
+ is "$output" "Error: checkpointing a container requires root" \
+ "Confirming that rootless checkpoint doesn't work. If that changed, please reexamine this test file!"
+ CHECKED_ROOTLESS=y
+ fi
+ skip "checkpoint does not work rootless"
+ fi
+
+ basic_setup
+}
+
+function teardown() {
+ run_podman '?' volume rm myvol
+
+ basic_teardown
+}
+
+@test "podman checkpoint - basic test" {
+ run_podman run -d $IMAGE sh -c 'while :;do cat /proc/uptime; sleep 0.1;done'
+ local cid="$output"
+
+ # Wait for container to start emitting output
+ wait_for_output '[1-9]\+' $cid
+
+ # Checkpoint, and confirm via inspect
+ run_podman container checkpoint $cid
+ is "$output" "$cid" "podman container checkpoint"
+
+ run_podman container inspect \
+ --format '{{.State.Status}}:{{.State.Running}}:{{.State.Paused}}:{{.State.Checkpointed}}' $cid
+ is "$output" "exited:false:false:true" "State. Status:Running:Pause:Checkpointed"
+
+ # Plan A was to do something similar to 080-pause.bats: sleep for long
+ # enough to cause a gap in the timestamps in the log. But checkpoint
+ # doesn't seem to work like that: upon restore, even if we sleep a long
+ # time, the newly-started container seems to pick back up close to
+ # where it left off. (Maybe it's something about /proc/uptime?)
+ # Anyway, scratch Plan A. Plan B is simply to make sure that the
+ # restarted container spits something out.
+ run_podman logs $cid
+ local nlines_before="${#lines[*]}"
+
+ # Restart immediately and confirm state
+ run_podman container restore $cid
+ is "$output" "$cid" "podman container restore"
+
+ # Note that upon restore, .Checkpointed reverts to false (#12117)
+ run_podman container inspect \
+ --format '{{.State.Status}}:{{.State.Running}}:{{.State.Paused}}:{{.State.Checkpointed}}' $cid
+ is "$output" "running:true:false:false" \
+ "State. Status:Running:Pause:Checkpointed"
+
+ # Pause briefly to let restarted container emit some output
+ sleep 0.3
+
+ # Get full logs, and make sure something changed
+ run_podman logs $cid
+ local nlines_after="${#lines[*]}"
+ if [[ $nlines_after -eq $nlines_before ]]; then
+ die "Container failed to output new lines after first restore"
+ fi
+
+ # Same thing again: test for https://github.com/containers/crun/issues/756
+ # in which, after second checkpoint/restore, we lose logs
+ run_podman container checkpoint $cid
+ run_podman container logs $cid
+ nlines_before="${#lines[*]}"
+ run_podman container restore $cid
+
+ # Give container time to write new output; then confirm that something
+ # was emitted
+ sleep 0.3
+ run_podman container logs $cid
+ nlines_after="${#lines[*]}"
+ if [[ $nlines_after -eq $nlines_before ]]; then
+ die "stdout went away after second restore (crun issue 756)"
+ fi
+
+ run_podman rm -t 0 -f $cid
+}
+
+
+@test "podman checkpoint --export, with volumes" {
+ skip_if_remote "Test uses --root/--runroot, which are N/A over remote"
+
+ # Create a root in tempdir. We will run a container here.
+ local p_root=${PODMAN_TMPDIR}/testroot/root
+ local p_runroot=${PODMAN_TMPDIR}/testroot/runroot
+ mkdir -p $p_root $p_runroot
+
+ # To avoid network pull, copy $IMAGE straight to temp root
+ local p_opts="--root $p_root --runroot $p_runroot --events-backend file"
+ run_podman save -o $PODMAN_TMPDIR/image.tar $IMAGE
+ run_podman $p_opts load -i $PODMAN_TMPDIR/image.tar
+
+ # Create a volume, find unused network port, and create a webserv container
+ run_podman $p_opts volume create myvol
+ local cname=c_$(random_string 10)
+ local host_port=$(random_free_port)
+ local server=http://127.0.0.1:$host_port
+
+ run_podman $p_opts run -d --name $cname --volume myvol:/myvol \
+ -p $host_port:80 \
+ -w /myvol \
+ $IMAGE sh -c "/bin/busybox-extras httpd -p 80;echo $cname >cname;echo READY;while :;do cat /proc/uptime >mydate.tmp;mv -f mydate.tmp mydate;sleep 0.1;done"
+ local cid="$output"
+ _PODMAN_TEST_OPTS="$p_opts" wait_for_ready $cid
+
+ # Confirm that container responds
+ run curl --max-time 3 -s $server/cname
+ is "$output" "$cname" "curl $server/cname"
+ run curl --max-time 3 -s $server/mydate
+ local date_oldroot="$output"
+
+ # Checkpoint...
+ run_podman $p_opts container checkpoint \
+ --ignore-rootfs \
+ --export=$PODMAN_TMPDIR/$cname.tar.gz \
+ $cname
+
+ # ...confirm that port is now closed
+ run curl --max-time 1 -s $server/mydate
+ is "$status" "7" "cannot connect to port $host_port while container is down"
+
+ # ...now restore it to our regular root
+ run_podman container restore --import=$PODMAN_TMPDIR/$cname.tar.gz
+ is "$output" "$cid"
+
+ # Inspect (on regular root). Note that, unlike the basic test above,
+ # .State.Checkpointed here is *false*.
+ run_podman container inspect \
+ --format '{{.State.Status}}:{{.State.Running}}:{{.State.Paused}}:{{.State.Checkpointed}}' $cname
+ is "$output" "running:true:false:false" "State. Status:Running:Pause:Checkpointed"
+
+ # Pause a moment to let the restarted container update the timestamp file
+ sleep .3
+ run curl --max-time 3 -s $server/mydate
+ local date_newroot="$output"
+ if [[ $date_newroot = $date_oldroot ]]; then
+ die "Restored container did not update the timestamp file"
+ fi
+
+ run_podman exec $cid cat /myvol/cname
+ is "$output" "$cname" "volume transferred fine"
+
+ run_podman rm -t 0 -f $cid
+ run_podman volume rm -f myvol
+}
+
+# FIXME: test --leave-running
+
+# vim: filetype=sh