Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func TestMain(m *testing.M) {
)
defer cancel()

fmt.Println("About to start daemon")

if !noDaemon {
os.RemoveAll(defaultRoot)

Expand All @@ -75,6 +77,8 @@ func TestMain(m *testing.M) {
}
}

fmt.Println("Waiting for dameon to start")

waitCtx, waitCancel := context.WithTimeout(ctx, 2*time.Second)
client, err := ctrd.waitForStart(waitCtx)
waitCancel()
Expand All @@ -85,6 +89,8 @@ func TestMain(m *testing.M) {
os.Exit(1)
}

fmt.Println("Daemon started")

// print out the version in information
version, err := client.Version(ctx)
if err != nil {
Expand All @@ -99,17 +105,10 @@ func TestMain(m *testing.M) {
}).Info("running tests against containerd")

// pull a seed image
if runtime.GOOS != "windows" { // TODO: remove once pull is supported on windows
if _, err = client.Pull(ctx, testImage, WithPullUnpack); err != nil {
ctrd.Stop()
ctrd.Wait()
fmt.Fprintf(os.Stderr, "%s: %s\n", err, buf.String())
os.Exit(1)
}
}

if err := platformTestSetup(client); err != nil {
fmt.Fprintln(os.Stderr, "platform test setup failed", err)
if _, err = client.Pull(ctx, testImage, WithPullUnpack); err != nil {
ctrd.Stop()
ctrd.Wait()
fmt.Fprintf(os.Stderr, "%s: %s\n", err, buf.String())
os.Exit(1)
}

Expand Down
4 changes: 0 additions & 4 deletions client_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ var (
testImage string
)

func platformTestSetup(client *Client) error {
return nil
}

func init() {
switch runtime.GOARCH {
case "386":
Expand Down
72 changes: 0 additions & 72 deletions client_windows_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package containerd

import (
"encoding/json"
"fmt"
"os"
"path/filepath"

"github.com/pkg/errors"
)

const (
Expand All @@ -15,74 +11,6 @@ const (
)

var (
dockerLayerFolders []string

defaultRoot = filepath.Join(os.Getenv("programfiles"), "containerd", "root-test")
defaultState = filepath.Join(os.Getenv("programfiles"), "containerd", "state-test")
)

func platformTestSetup(client *Client) error {
var (
roots []string
layerChains = make(map[string]string)
)
// Since we can't pull images yet, we'll piggyback on the default
// docker's images
wfPath := `C:\ProgramData\docker\windowsfilter`
wf, err := os.Open(wfPath)
if err != nil {
return errors.Wrapf(err, "failed to access docker layers @ %s", wfPath)
}
defer wf.Close()
entries, err := wf.Readdirnames(0)
if err != nil {
return errors.Wrapf(err, "failed to read %s entries", wfPath)
}

for _, fn := range entries {
layerChainPath := filepath.Join(wfPath, fn, "layerchain.json")
lfi, err := os.Stat(layerChainPath)
switch {
case err == nil && lfi.Mode().IsRegular():
f, err := os.OpenFile(layerChainPath, os.O_RDONLY, 0660)
if err != nil {
fmt.Fprintln(os.Stderr,
errors.Wrapf(err, "failed to open %s", layerChainPath))
continue
}
defer f.Close()
l := make([]string, 0)
if err := json.NewDecoder(f).Decode(&l); err != nil {
fmt.Fprintln(os.Stderr,
errors.Wrapf(err, "failed to decode %s", layerChainPath))
continue
}
switch {
case len(l) == 1:
layerChains[l[0]] = filepath.Join(wfPath, fn)
case len(l) > 1:
fmt.Fprintf(os.Stderr, "Too many entries in %s: %d", layerChainPath, len(l))
case len(l) == 0:
roots = append(roots, filepath.Join(wfPath, fn))
}
case os.IsNotExist(err):
// keep on going
default:
return errors.Wrapf(err, "error trying to access %s", layerChainPath)
}
}

// They'll be 2 roots, just take the first one
l := roots[0]
dockerLayerFolders = append(dockerLayerFolders, l)
for {
l = layerChains[l]
if l == "" {
break
}

dockerLayerFolders = append([]string{l}, dockerLayerFolders...)
}

return nil
}
1 change: 1 addition & 0 deletions cmd/containerd/builtins_windows.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
_ "github.com/containerd/containerd/differ/windowsdiffer"
_ "github.com/containerd/containerd/snapshot/windows"
_ "github.com/containerd/containerd/windows"
)
34 changes: 9 additions & 25 deletions cmd/ctr/run_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,15 @@ import (
"github.com/containerd/console"
"github.com/containerd/containerd"
"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/log"
digest "github.com/opencontainers/go-digest"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

const pipeRoot = `\\.\pipe`

func init() {
runCommand.Flags = append(runCommand.Flags, cli.StringSliceFlag{
Name: "layer",
Usage: "HCSSHIM Layers to be used",
})
}

func withLayers(context *cli.Context) containerd.SpecOpts {
return func(ctx gocontext.Context, client *containerd.Client, c *containers.Container, s *specs.Spec) error {
l := context.StringSlice("layer")
if l == nil {
return errors.Wrap(errdefs.ErrInvalidArgument, "base layers must be specified with `--layer`")
}
s.Windows.LayerFolders = l
return nil
}
}

func handleConsoleResize(ctx gocontext.Context, task resizer, con console.Console) error {
// do an initial resize of the console
size, err := con.Size()
Expand Down Expand Up @@ -86,7 +66,7 @@ func setHostNetworking() containerd.SpecOpts {

func newContainer(ctx gocontext.Context, client *containerd.Client, context *cli.Context) (containerd.Container, error) {
var (
// ref = context.Args().First()
ref = context.Args().First()
id = context.Args().Get(1)
args = context.Args()[2:]
tty = context.Bool("tty")
Expand All @@ -95,11 +75,13 @@ func newContainer(ctx gocontext.Context, client *containerd.Client, context *cli

labels := labelArgs(labelStrings)

// TODO(mlaventure): get base image once we have a snapshotter
image, err := client.GetImage(ctx, ref)
if err != nil {
return nil, err
}

opts := []containerd.SpecOpts{
// TODO(mlaventure): use containerd.WithImageConfig once we have a snapshotter
withLayers(context),
containerd.WithImageConfig(image),
withEnv(context),
withMounts(context),
withTTY(tty),
Expand All @@ -114,7 +96,9 @@ func newContainer(ctx gocontext.Context, client *containerd.Client, context *cli
containerd.WithNewSpec(opts...),
containerd.WithContainerLabels(labels),
containerd.WithRuntime(context.String("runtime"), nil),
// TODO(mlaventure): containerd.WithImage(image),
containerd.WithImage(image),
containerd.WithSnapshotter(context.String("snapshotter")),
containerd.WithNewSnapshot(id, image),
)
}

Expand Down
32 changes: 16 additions & 16 deletions container_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func TestDaemonRestart(t *testing.T) {
return
}

container, err := client.NewContainer(ctx, id, WithNewSpec(withImageConfig(image), withProcessArgs("sleep", "30")), withNewSnapshot(id, image))
container, err := client.NewContainer(ctx, id, WithNewSpec(WithImageConfig(image), withProcessArgs("sleep", "30")), WithNewSnapshot(id, image))
if err != nil {
t.Error(err)
return
Expand Down Expand Up @@ -283,7 +283,7 @@ func TestContainerAttach(t *testing.T) {
return
}

container, err := client.NewContainer(ctx, id, WithNewSpec(withImageConfig(image), withCat()), withNewSnapshot(id, image))
container, err := client.NewContainer(ctx, id, WithNewSpec(WithImageConfig(image), withCat()), WithNewSnapshot(id, image))
if err != nil {
t.Error(err)
return
Expand Down Expand Up @@ -405,8 +405,8 @@ func TestContainerUsername(t *testing.T) {

// squid user in the alpine image has a uid of 31
container, err := client.NewContainer(ctx, id,
withNewSnapshot(id, image),
WithNewSpec(withImageConfig(image), WithUsername("squid"), WithProcessArgs("id", "-u")),
WithNewSnapshot(id, image),
WithNewSpec(WithImageConfig(image), WithUsername("squid"), WithProcessArgs("id", "-u")),
)
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -470,7 +470,7 @@ func TestContainerAttachProcess(t *testing.T) {
return
}

container, err := client.NewContainer(ctx, id, WithNewSpec(withImageConfig(image), withProcessArgs("sleep", "100")), withNewSnapshot(id, image))
container, err := client.NewContainer(ctx, id, WithNewSpec(WithImageConfig(image), withProcessArgs("sleep", "100")), WithNewSnapshot(id, image))
if err != nil {
t.Error(err)
return
Expand Down Expand Up @@ -614,8 +614,8 @@ func TestContainerUserID(t *testing.T) {

// adm user in the alpine image has a uid of 3 and gid of 4.
container, err := client.NewContainer(ctx, id,
withNewSnapshot(id, image),
WithNewSpec(withImageConfig(image), WithUserID(3), WithProcessArgs("sh", "-c", "echo $(id -u):$(id -g)")),
WithNewSnapshot(id, image),
WithNewSpec(WithImageConfig(image), WithUserID(3), WithProcessArgs("sh", "-c", "echo $(id -u):$(id -g)")),
)
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -673,8 +673,8 @@ func TestContainerKillAll(t *testing.T) {
}

container, err := client.NewContainer(ctx, id,
withNewSnapshot(id, image),
WithNewSpec(withImageConfig(image),
WithNewSnapshot(id, image),
WithNewSpec(WithImageConfig(image),
withProcessArgs("sh", "-c", "top"),
WithHostNamespace(specs.PIDNamespace),
),
Expand Down Expand Up @@ -734,7 +734,7 @@ func TestShimSigkilled(t *testing.T) {
if err != nil {
t.Fatal(err)
}
container, err := client.NewContainer(ctx, id, WithNewSpec(WithImageConfig(image)), withNewSnapshot(id, image))
container, err := client.NewContainer(ctx, id, WithNewSpec(WithImageConfig(image)), WithNewSnapshot(id, image))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -798,7 +798,7 @@ func TestDaemonRestartWithRunningShim(t *testing.T) {
t.Error(err)
return
}
container, err := client.NewContainer(ctx, id, WithNewSpec(WithImageConfig(image), WithProcessArgs("sleep", "100")), withNewSnapshot(id, image))
container, err := client.NewContainer(ctx, id, WithNewSpec(WithImageConfig(image), WithProcessArgs("sleep", "100")), WithNewSnapshot(id, image))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -883,8 +883,8 @@ func TestContainerRuntimeOptions(t *testing.T) {

container, err := client.NewContainer(
ctx, id,
WithNewSpec(withImageConfig(image), withExitStatus(7)),
withNewSnapshot(id, image),
WithNewSpec(WithImageConfig(image), withExitStatus(7)),
WithNewSnapshot(id, image),
WithRuntime("io.containerd.runtime.v1.linux", &runcopts.RuncOptions{Runtime: "no-runc"}),
)
if err != nil {
Expand Down Expand Up @@ -925,8 +925,8 @@ func TestContainerKillInitPidHost(t *testing.T) {
}

container, err := client.NewContainer(ctx, id,
withNewSnapshot(id, image),
WithNewSpec(withImageConfig(image),
WithNewSnapshot(id, image),
WithNewSpec(WithImageConfig(image),
withProcessArgs("sh", "-c", "sleep 42; echo hi"),
WithHostNamespace(specs.PIDNamespace),
),
Expand Down Expand Up @@ -1007,7 +1007,7 @@ func testUserNamespaces(t *testing.T, readonlyRootFS bool) {
return
}

opts := []NewContainerOpts{WithNewSpec(withImageConfig(image),
opts := []NewContainerOpts{WithNewSpec(WithImageConfig(image),
withExitStatus(7),
WithUserNamespace(0, 1000, 10000),
)}
Expand Down
Loading