From e2e6a73b6234af5932a619bf7115bd7de5e60e91 Mon Sep 17 00:00:00 2001 From: Andrew Vagin Date: Thu, 30 Jul 2015 08:24:27 +0300 Subject: [PATCH 1/2] tests: dump/restore a container with cgroups Signed-off-by: Andrey Vagin --- libcontainer/integration/checkpoint_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libcontainer/integration/checkpoint_test.go b/libcontainer/integration/checkpoint_test.go index db31fe21..76d86c09 100644 --- a/libcontainer/integration/checkpoint_test.go +++ b/libcontainer/integration/checkpoint_test.go @@ -5,9 +5,11 @@ import ( "io/ioutil" "os" "strings" + "syscall" "testing" "github.com/opencontainers/runc/libcontainer" + "github.com/opencontainers/runc/libcontainer/configs" ) func TestCheckpoint(t *testing.T) { @@ -28,6 +30,12 @@ func TestCheckpoint(t *testing.T) { config := newTemplateConfig(rootfs) + config.Mounts = append(config.Mounts, &configs.Mount{ + Destination: "/sys/fs/cgroup", + Device: "cgroup", + Flags: defaultMountFlags | syscall.MS_RDONLY, + }) + factory, err := libcontainer.New(root, libcontainer.Cgroupfs) if err != nil { From aa3c2dc6218d975f10b11f9e30c575166a48fcd4 Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Thu, 30 Jul 2015 09:43:40 +0300 Subject: [PATCH 2/2] integration: show criu logs in a error case Signed-off-by: Andrew Vagin --- libcontainer/integration/checkpoint_test.go | 37 +++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/libcontainer/integration/checkpoint_test.go b/libcontainer/integration/checkpoint_test.go index 76d86c09..fc027fa8 100644 --- a/libcontainer/integration/checkpoint_test.go +++ b/libcontainer/integration/checkpoint_test.go @@ -1,9 +1,11 @@ package integration import ( + "bufio" "bytes" "io/ioutil" "os" + "path/filepath" "strings" "syscall" "testing" @@ -12,6 +14,30 @@ import ( "github.com/opencontainers/runc/libcontainer/configs" ) +func showFile(t *testing.T, fname string) error { + t.Logf("=== %s ===\n", fname) + + f, err := os.Open(fname) + if err != nil { + t.Log(err) + return err + } + defer f.Close() + + scanner := bufio.NewScanner(f) + for scanner.Scan() { + t.Log(scanner.Text()) + } + + if err := scanner.Err(); err != nil { + return err + } + + t.Logf("=== END ===\n") + + return nil +} + func TestCheckpoint(t *testing.T) { if testing.Short() { return @@ -89,8 +115,11 @@ func TestCheckpoint(t *testing.T) { ImagesDirectory: imagesDir, WorkDirectory: imagesDir, } + dumpLog := filepath.Join(checkpointOpts.WorkDirectory, "dump.log") + restoreLog := filepath.Join(checkpointOpts.WorkDirectory, "restore.log") if err := container.Checkpoint(checkpointOpts); err != nil { + showFile(t, dumpLog) t.Fatal(err) } @@ -125,11 +154,13 @@ func TestCheckpoint(t *testing.T) { Stdout: &stdout, } - err = container.Restore(restoreProcessConfig, &libcontainer.CriuOpts{ - ImagesDirectory: imagesDir, - }) + err = container.Restore(restoreProcessConfig, checkpointOpts) restoreStdinR.Close() defer restoreStdinW.Close() + if err != nil { + showFile(t, restoreLog) + t.Fatal(err) + } state, err = container.Status() if err != nil {