modify code to compile on updated containerd
Signed-off-by: Mike Brown <brownwm@us.ibm.com>
This commit is contained in:
@@ -17,15 +17,13 @@ limitations under the License.
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/containerd/containerd/api/services/execution"
|
||||
rootfsapi "github.com/containerd/containerd/api/services/rootfs"
|
||||
imagedigest "github.com/opencontainers/go-digest"
|
||||
snapshotapi "github.com/containerd/containerd/api/services/snapshot"
|
||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -268,9 +266,9 @@ options timeout:1
|
||||
}
|
||||
|
||||
func TestRunPodSandbox(t *testing.T) {
|
||||
config, imageConfig, specCheck := getRunPodSandboxTestData()
|
||||
config, imageConfig, _ := getRunPodSandboxTestData() // TODO: declare and test specCheck see below
|
||||
c := newTestCRIContainerdService()
|
||||
fakeRootfsClient := c.rootfsService.(*servertesting.FakeRootfsClient)
|
||||
fakeSnapshotClient := c.snapshotService.(*servertesting.FakeSnapshotClient)
|
||||
fakeExecutionClient := c.containerService.(*servertesting.FakeExecutionClient)
|
||||
fakeCNIPlugin := c.netPlugin.(*servertesting.FakeCNIPlugin)
|
||||
fakeOS := c.os.(*ostesting.FakeOS)
|
||||
@@ -286,17 +284,15 @@ func TestRunPodSandbox(t *testing.T) {
|
||||
assert.Equal(t, os.FileMode(0700), perm)
|
||||
return nopReadWriteCloser{}, nil
|
||||
}
|
||||
testChainID := imagedigest.Digest("test-sandbox-chain-id")
|
||||
testChainID := "test-sandbox-chain-id"
|
||||
imageMetadata := metadata.ImageMetadata{
|
||||
ID: testSandboxImage,
|
||||
ChainID: testChainID.String(),
|
||||
ChainID: testChainID,
|
||||
Config: imageConfig,
|
||||
}
|
||||
// Insert sandbox image metadata.
|
||||
assert.NoError(t, c.imageMetadataStore.Create(imageMetadata))
|
||||
// Insert fake chainID
|
||||
fakeRootfsClient.SetFakeChainIDs([]imagedigest.Digest{testChainID})
|
||||
expectRootfsClientCalls := []string{"prepare"}
|
||||
expectSnapshotClientCalls := []string{"prepare"}
|
||||
expectExecutionClientCalls := []string{"create", "start"}
|
||||
|
||||
res, err := c.RunPodSandbox(context.Background(), &runtime.RunPodSandboxRequest{Config: config})
|
||||
@@ -312,30 +308,31 @@ func TestRunPodSandbox(t *testing.T) {
|
||||
assert.Contains(t, pipes, stdout, "sandbox stdout pipe should be created")
|
||||
assert.Contains(t, pipes, stderr, "sandbox stderr pipe should be created")
|
||||
|
||||
assert.Equal(t, expectRootfsClientCalls, fakeRootfsClient.GetCalledNames(), "expect rootfs functions should be called")
|
||||
calls := fakeRootfsClient.GetCalledDetails()
|
||||
prepareOpts := calls[0].Argument.(*rootfsapi.PrepareRequest)
|
||||
assert.Equal(t, &rootfsapi.PrepareRequest{
|
||||
Name: id,
|
||||
ChainID: testChainID,
|
||||
Readonly: true,
|
||||
assert.Equal(t, expectSnapshotClientCalls, fakeSnapshotClient.GetCalledNames(), "expect snapshot functions should be called")
|
||||
calls := fakeSnapshotClient.GetCalledDetails()
|
||||
prepareOpts := calls[0].Argument.(*snapshotapi.PrepareRequest)
|
||||
assert.Equal(t, &snapshotapi.PrepareRequest{
|
||||
Key: id,
|
||||
Parent: testChainID,
|
||||
}, prepareOpts, "prepare request should be correct")
|
||||
|
||||
assert.Equal(t, expectExecutionClientCalls, fakeExecutionClient.GetCalledNames(), "expect containerd functions should be called")
|
||||
calls = fakeExecutionClient.GetCalledDetails()
|
||||
createOpts := calls[0].Argument.(*execution.CreateRequest)
|
||||
assert.Equal(t, id, createOpts.ID, "create id should be correct")
|
||||
assert.Equal(t, id, createOpts.ContainerID, "create id should be correct")
|
||||
assert.Equal(t, stdout, createOpts.Stdout, "stdout pipe should be passed to containerd")
|
||||
assert.Equal(t, stderr, createOpts.Stderr, "stderr pipe should be passed to containerd")
|
||||
mountsResp, err := fakeRootfsClient.Mounts(context.Background(), &rootfsapi.MountsRequest{Name: id})
|
||||
mountsResp, err := fakeSnapshotClient.Mounts(context.Background(), &snapshotapi.MountsRequest{Key: id})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, mountsResp.Mounts, createOpts.Rootfs, "rootfs mount should be correct")
|
||||
spec := &runtimespec.Spec{}
|
||||
assert.NoError(t, json.Unmarshal(createOpts.Spec.Value, spec))
|
||||
t.Logf("oci spec check")
|
||||
specCheck(t, id, spec)
|
||||
|
||||
startID := calls[1].Argument.(*execution.StartRequest).ID
|
||||
// TODO: Need to create container first.. see Create in containerd/containerd/apsi/services/containers spec is no longer in the create request
|
||||
//spec := &runtimespec.Spec{}
|
||||
//assert.NoError(t, json.Unmarshal(createOpts.Spec.Value, spec))
|
||||
//t.Logf("oci spec check")
|
||||
//specCheck(t, id, spec)
|
||||
|
||||
startID := calls[1].Argument.(*execution.StartRequest).ContainerID
|
||||
assert.Equal(t, id, startID, "start id should be correct")
|
||||
|
||||
meta, err := c.sandboxStore.Get(id)
|
||||
@@ -346,9 +343,9 @@ func TestRunPodSandbox(t *testing.T) {
|
||||
assert.Equal(t, config, meta.Config, "metadata config should be correct")
|
||||
// TODO(random-liu): [P2] Add clock interface and use fake clock.
|
||||
assert.NotZero(t, meta.CreatedAt, "metadata CreatedAt should be set")
|
||||
info, err := fakeExecutionClient.Info(context.Background(), &execution.InfoRequest{ID: id})
|
||||
info, err := fakeExecutionClient.Info(context.Background(), &execution.InfoRequest{ContainerID: id})
|
||||
assert.NoError(t, err)
|
||||
pid := info.Pid
|
||||
pid := info.Task.Pid
|
||||
assert.Equal(t, meta.NetNS, getNetworkNamespace(pid), "metadata network namespace should be correct")
|
||||
|
||||
gotID, err := c.sandboxIDIndex.Get(id)
|
||||
@@ -359,7 +356,12 @@ func TestRunPodSandbox(t *testing.T) {
|
||||
assert.Equal(t, expectedCNICalls, fakeCNIPlugin.GetCalledNames(), "expect SetUpPod should be called")
|
||||
calls = fakeCNIPlugin.GetCalledDetails()
|
||||
pluginArgument := calls[0].Argument.(servertesting.CNIPluginArgument)
|
||||
expectedPluginArgument := servertesting.CNIPluginArgument{meta.NetNS, config.GetMetadata().GetNamespace(), config.GetMetadata().GetName(), id}
|
||||
expectedPluginArgument := servertesting.CNIPluginArgument{
|
||||
NetnsPath: meta.NetNS,
|
||||
Namespace: config.GetMetadata().GetNamespace(),
|
||||
Name: config.GetMetadata().GetName(),
|
||||
ContainerID: id,
|
||||
}
|
||||
assert.Equal(t, expectedPluginArgument, pluginArgument, "SetUpPod should be called with correct arguments")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user