Implement options for runtime specific settings

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-06-23 14:55:10 -07:00
parent eedcbc64cc
commit 82d0208aaa
18 changed files with 1701 additions and 467 deletions

View File

@@ -1,8 +1,14 @@
package containerd
import (
"path/filepath"
"syscall"
"testing"
tasks "github.com/containerd/containerd/api/services/tasks/v1"
"github.com/containerd/containerd/linux/runcopts"
"github.com/gogo/protobuf/proto"
protobuf "github.com/gogo/protobuf/types"
)
func TestCheckpointRestore(t *testing.T) {
@@ -200,3 +206,105 @@ func TestCheckpointRestoreNewContainer(t *testing.T) {
}
<-statusC
}
func TestCheckpointLeaveRunning(t *testing.T) {
if testing.Short() {
t.Skip()
}
if !supportsCriu {
t.Skip("system does not have criu installed")
}
client, err := New(address)
if err != nil {
t.Fatal(err)
}
defer client.Close()
var (
ctx, cancel = testContext()
id = t.Name()
)
defer cancel()
image, err := client.GetImage(ctx, testImage)
if err != nil {
t.Error(err)
return
}
spec, err := GenerateSpec(WithImageConfig(ctx, image), WithProcessArgs("sleep", "100"))
if err != nil {
t.Error(err)
return
}
container, err := client.NewContainer(ctx, id, WithSpec(spec), WithNewRootFS(id, image))
if err != nil {
t.Error(err)
return
}
defer container.Delete(ctx, WithRootFSDeletion)
task, err := container.NewTask(ctx, empty())
if err != nil {
t.Error(err)
return
}
defer task.Delete(ctx)
statusC := make(chan uint32, 1)
go func() {
status, err := task.Wait(ctx)
if err != nil {
t.Error(err)
}
statusC <- status
}()
if err := task.Start(ctx); err != nil {
t.Error(err)
return
}
if _, err := task.Checkpoint(ctx); err != nil {
t.Error(err)
return
}
status, err := task.Status(ctx)
if err != nil {
t.Error(err)
return
}
if status != Running {
t.Errorf("expected status %q but received %q", Running, status)
return
}
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
t.Error(err)
return
}
<-statusC
}
func WithExit(r *tasks.CheckpointTaskRequest) error {
a, err := marshal(&runcopts.CheckpointOptions{
Exit: true,
}, "CheckpointOptions")
if err != nil {
return err
}
r.Options = a
return nil
}
func marshal(m proto.Message, name string) (*protobuf.Any, error) {
data, err := proto.Marshal(m)
if err != nil {
return nil, err
}
return &protobuf.Any{
TypeUrl: filepath.Join(runcopts.URIBase, name),
Value: data,
}, nil
}