modify code to compile on updated containerd
Signed-off-by: Mike Brown <brownwm@us.ibm.com>
This commit is contained in:
@@ -17,7 +17,6 @@ limitations under the License.
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
@@ -25,8 +24,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/api/services/execution"
|
||||
"github.com/containerd/containerd/api/types/container"
|
||||
"github.com/containerd/containerd/api/types/mount"
|
||||
"github.com/containerd/containerd/api/types/task"
|
||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/opencontainers/runtime-tools/generate"
|
||||
@@ -444,7 +443,7 @@ func TestStartContainer(t *testing.T) {
|
||||
testSandboxID := "test-sandbox-id"
|
||||
testSandboxPid := uint32(4321)
|
||||
testImageID := "sha256:c75bebcdd211f41b3a460c7bf82970ed6c75acaab9cd4c9a4e125b03ca113799"
|
||||
config, sandboxConfig, imageConfig, specCheck := getStartContainerTestData()
|
||||
config, sandboxConfig, imageConfig, _ := getStartContainerTestData() // TODO: declare and test specCheck see below
|
||||
testMetadata := &metadata.ContainerMetadata{
|
||||
ID: testID,
|
||||
Name: "test-name",
|
||||
@@ -458,16 +457,16 @@ func TestStartContainer(t *testing.T) {
|
||||
Name: "test-sandbox-name",
|
||||
Config: sandboxConfig,
|
||||
}
|
||||
testSandboxContainer := &container.Container{
|
||||
testSandboxContainer := &task.Task{
|
||||
ID: testSandboxID,
|
||||
Pid: testSandboxPid,
|
||||
Status: container.Status_RUNNING,
|
||||
Status: task.StatusRunning,
|
||||
}
|
||||
testMounts := []*mount.Mount{{Type: "bind", Source: "test-source"}}
|
||||
for desc, test := range map[string]struct {
|
||||
containerMetadata *metadata.ContainerMetadata
|
||||
sandboxMetadata *metadata.SandboxMetadata
|
||||
sandboxContainerdContainer *container.Container
|
||||
sandboxContainerdContainer *task.Task
|
||||
imageMetadataErr bool
|
||||
snapshotMountsErr bool
|
||||
prepareFIFOErr error
|
||||
@@ -523,10 +522,10 @@ func TestStartContainer(t *testing.T) {
|
||||
"should return error when sandbox is not running": {
|
||||
containerMetadata: testMetadata,
|
||||
sandboxMetadata: testSandboxMetadata,
|
||||
sandboxContainerdContainer: &container.Container{
|
||||
sandboxContainerdContainer: &task.Task{
|
||||
ID: testSandboxID,
|
||||
Pid: testSandboxPid,
|
||||
Status: container.Status_STOPPED,
|
||||
Status: task.StatusStopped,
|
||||
},
|
||||
expectStateChange: true,
|
||||
expectCalls: []string{"info"},
|
||||
@@ -591,7 +590,7 @@ func TestStartContainer(t *testing.T) {
|
||||
c := newTestCRIContainerdService()
|
||||
fake := c.containerService.(*servertesting.FakeExecutionClient)
|
||||
fakeOS := c.os.(*ostesting.FakeOS)
|
||||
fakeRootfsClient := c.rootfsService.(*servertesting.FakeRootfsClient)
|
||||
fakeSnapshotClient := c.snapshotService.(*servertesting.FakeSnapshotClient)
|
||||
if test.containerMetadata != nil {
|
||||
assert.NoError(t, c.containerStore.Create(*test.containerMetadata))
|
||||
}
|
||||
@@ -599,7 +598,7 @@ func TestStartContainer(t *testing.T) {
|
||||
assert.NoError(t, c.sandboxStore.Create(*test.sandboxMetadata))
|
||||
}
|
||||
if test.sandboxContainerdContainer != nil {
|
||||
fake.SetFakeContainers([]container.Container{*test.sandboxContainerdContainer})
|
||||
fake.SetFakeContainers([]task.Task{*test.sandboxContainerdContainer})
|
||||
}
|
||||
if !test.imageMetadataErr {
|
||||
assert.NoError(t, c.imageMetadataStore.Create(metadata.ImageMetadata{
|
||||
@@ -608,7 +607,7 @@ func TestStartContainer(t *testing.T) {
|
||||
}))
|
||||
}
|
||||
if !test.snapshotMountsErr {
|
||||
fakeRootfsClient.SetFakeMounts(testID, testMounts)
|
||||
fakeSnapshotClient.SetFakeMounts(testID, testMounts)
|
||||
}
|
||||
// TODO(random-liu): Test behavior with different streaming config.
|
||||
fakeOS.OpenFifoFn = func(context.Context, string, int, os.FileMode) (io.ReadWriteCloser, error) {
|
||||
@@ -650,26 +649,27 @@ func TestStartContainer(t *testing.T) {
|
||||
assert.EqualValues(t, errorStartExitCode, meta.ExitCode)
|
||||
assert.Equal(t, errorStartReason, meta.Reason)
|
||||
assert.NotEmpty(t, meta.Message)
|
||||
_, err := fake.Info(context.Background(), &execution.InfoRequest{ID: testID})
|
||||
_, err := fake.Info(context.Background(), &execution.InfoRequest{ContainerID: testID})
|
||||
assert.True(t, isContainerdContainerNotExistError(err),
|
||||
"containerd container should be cleaned up after when fail to start")
|
||||
continue
|
||||
}
|
||||
t.Logf("container state should be running when start successfully")
|
||||
assert.Equal(t, runtime.ContainerState_CONTAINER_RUNNING, meta.State())
|
||||
info, err := fake.Info(context.Background(), &execution.InfoRequest{ID: testID})
|
||||
info, err := fake.Info(context.Background(), &execution.InfoRequest{ContainerID: testID})
|
||||
assert.NoError(t, err)
|
||||
pid := info.Pid
|
||||
pid := info.Task.Pid
|
||||
assert.Equal(t, pid, meta.Pid)
|
||||
assert.Equal(t, container.Status_RUNNING, info.Status)
|
||||
assert.Equal(t, task.StatusRunning, info.Task.Status)
|
||||
// Check runtime spec
|
||||
calls := fake.GetCalledDetails()
|
||||
createOpts, ok := calls[1].Argument.(*execution.CreateRequest)
|
||||
assert.True(t, ok, "2nd call should be create")
|
||||
assert.Equal(t, testMounts, createOpts.Rootfs, "rootfs mounts should be correct")
|
||||
// TODO(random-liu): Test other create options.
|
||||
spec := &runtimespec.Spec{}
|
||||
assert.NoError(t, json.Unmarshal(createOpts.Spec.Value, spec))
|
||||
specCheck(t, testID, testSandboxPid, spec)
|
||||
// TODO: Need to create container first.. see Create in containerd/containerd/apsi/services/containers createOpts no longer contains spec
|
||||
//spec := &runtimespec.Spec{}
|
||||
//assert.NoError(t, json.Unmarshal(createOpts.Spec.Value, spec))
|
||||
//specCheck(t, testID, testSandboxPid, spec)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user