mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-07 00:14:21 +01:00
Config: Remove ConfigJSONKey from annotations
Fixes: #2023 We can get OCI spec config from bundle instead of annotations, so this field isn't necessary. Signed-off-by: Wei Zhang <weizhang555.zw@gmail.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"github.com/kata-containers/runtime/pkg/katautils"
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/compatoci"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@@ -113,7 +114,7 @@ func create(ctx context.Context, containerID, bundlePath, console, pidFilePath s
|
||||
return err
|
||||
}
|
||||
|
||||
ociSpec, err := oci.ParseConfigJSON(bundlePath)
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
|
||||
"github.com/kata-containers/runtime/pkg/katautils"
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/compatoci"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
@@ -322,7 +323,7 @@ func TestCreateInvalidContainerType(t *testing.T) {
|
||||
ociConfigFile := filepath.Join(bundlePath, "config.json")
|
||||
assert.True(katautils.FileExists(ociConfigFile))
|
||||
|
||||
spec, err := oci.ParseConfigJSON(bundlePath)
|
||||
spec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
// Force an invalid container type
|
||||
@@ -367,7 +368,7 @@ func TestCreateContainerInvalid(t *testing.T) {
|
||||
ociConfigFile := filepath.Join(bundlePath, "config.json")
|
||||
assert.True(katautils.FileExists(ociConfigFile))
|
||||
|
||||
spec, err := oci.ParseConfigJSON(bundlePath)
|
||||
spec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
|
||||
assert.NoError(err)
|
||||
|
||||
@@ -432,7 +433,7 @@ func TestCreateProcessCgroupsPathSuccessful(t *testing.T) {
|
||||
ociConfigFile := filepath.Join(bundlePath, "config.json")
|
||||
assert.True(katautils.FileExists(ociConfigFile))
|
||||
|
||||
spec, err := oci.ParseConfigJSON(bundlePath)
|
||||
spec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
// Force sandbox-type container
|
||||
@@ -535,7 +536,7 @@ func TestCreateCreateCgroupsFilesFail(t *testing.T) {
|
||||
ociConfigFile := filepath.Join(bundlePath, "config.json")
|
||||
assert.True(katautils.FileExists(ociConfigFile))
|
||||
|
||||
spec, err := oci.ParseConfigJSON(bundlePath)
|
||||
spec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
// Force sandbox-type container
|
||||
@@ -622,7 +623,7 @@ func TestCreateCreateCreatePidFileFail(t *testing.T) {
|
||||
ociConfigFile := filepath.Join(bundlePath, "config.json")
|
||||
assert.True(katautils.FileExists(ociConfigFile))
|
||||
|
||||
spec, err := oci.ParseConfigJSON(bundlePath)
|
||||
spec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
// Force sandbox-type container
|
||||
@@ -697,7 +698,7 @@ func TestCreate(t *testing.T) {
|
||||
ociConfigFile := filepath.Join(bundlePath, "config.json")
|
||||
assert.True(katautils.FileExists(ociConfigFile))
|
||||
|
||||
spec, err := oci.ParseConfigJSON(bundlePath)
|
||||
spec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
// Force sandbox-type container
|
||||
|
||||
@@ -13,13 +13,15 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/urfave/cli"
|
||||
|
||||
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/compatoci"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
|
||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func testRemoveCgroupsPathSuccessful(t *testing.T, cgroupsPathList []string) {
|
||||
@@ -153,7 +155,8 @@ func TestDeleteSandbox(t *testing.T) {
|
||||
|
||||
rootPath, bundlePath := testConfigSetup(t)
|
||||
defer os.RemoveAll(rootPath)
|
||||
configJSON, err := readOCIConfigJSON(bundlePath)
|
||||
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
path, err := createTempContainerIDMapping(sandbox.ID(), sandbox.ID())
|
||||
@@ -165,11 +168,11 @@ func TestDeleteSandbox(t *testing.T) {
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||
vcAnnotations.ConfigJSONKey: configJSON,
|
||||
},
|
||||
State: types.ContainerState{
|
||||
State: "ready",
|
||||
},
|
||||
Spec: &ociSpec,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -231,7 +234,7 @@ func TestDeleteInvalidContainerType(t *testing.T) {
|
||||
|
||||
rootPath, bundlePath := testConfigSetup(t)
|
||||
defer os.RemoveAll(rootPath)
|
||||
configJSON, err := readOCIConfigJSON(bundlePath)
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
path, err := createTempContainerIDMapping(sandbox.ID(), sandbox.ID())
|
||||
@@ -243,11 +246,11 @@ func TestDeleteInvalidContainerType(t *testing.T) {
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: "InvalidType",
|
||||
vcAnnotations.ConfigJSONKey: configJSON,
|
||||
},
|
||||
State: types.ContainerState{
|
||||
State: "created",
|
||||
},
|
||||
Spec: &ociSpec,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -270,7 +273,7 @@ func TestDeleteSandboxRunning(t *testing.T) {
|
||||
|
||||
rootPath, bundlePath := testConfigSetup(t)
|
||||
defer os.RemoveAll(rootPath)
|
||||
configJSON, err := readOCIConfigJSON(bundlePath)
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
path, err := createTempContainerIDMapping(sandbox.ID(), sandbox.ID())
|
||||
@@ -282,11 +285,11 @@ func TestDeleteSandboxRunning(t *testing.T) {
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||
vcAnnotations.ConfigJSONKey: configJSON,
|
||||
},
|
||||
State: types.ContainerState{
|
||||
State: "running",
|
||||
},
|
||||
Spec: &ociSpec,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -350,7 +353,7 @@ func TestDeleteRunningContainer(t *testing.T) {
|
||||
|
||||
rootPath, bundlePath := testConfigSetup(t)
|
||||
defer os.RemoveAll(rootPath)
|
||||
configJSON, err := readOCIConfigJSON(bundlePath)
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
path, err := createTempContainerIDMapping(sandbox.MockContainers[0].ID(), sandbox.MockContainers[0].ID())
|
||||
@@ -362,11 +365,11 @@ func TestDeleteRunningContainer(t *testing.T) {
|
||||
ID: sandbox.MockContainers[0].ID(),
|
||||
Annotations: map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||
vcAnnotations.ConfigJSONKey: configJSON,
|
||||
},
|
||||
State: types.ContainerState{
|
||||
State: "running",
|
||||
},
|
||||
Spec: &ociSpec,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -433,7 +436,7 @@ func TestDeleteContainer(t *testing.T) {
|
||||
|
||||
rootPath, bundlePath := testConfigSetup(t)
|
||||
defer os.RemoveAll(rootPath)
|
||||
configJSON, err := readOCIConfigJSON(bundlePath)
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
path, err := createTempContainerIDMapping(sandbox.MockContainers[0].ID(), sandbox.MockContainers[0].ID())
|
||||
@@ -445,11 +448,11 @@ func TestDeleteContainer(t *testing.T) {
|
||||
ID: sandbox.MockContainers[0].ID(),
|
||||
Annotations: map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||
vcAnnotations.ConfigJSONKey: configJSON,
|
||||
},
|
||||
State: types.ContainerState{
|
||||
State: "ready",
|
||||
},
|
||||
Spec: &ociSpec,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -533,7 +536,7 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
|
||||
|
||||
rootPath, bundlePath := testConfigSetup(t)
|
||||
defer os.RemoveAll(rootPath)
|
||||
configJSON, err := readOCIConfigJSON(bundlePath)
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
path, err := createTempContainerIDMapping(sandbox.ID(), sandbox.ID())
|
||||
@@ -545,11 +548,11 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||
vcAnnotations.ConfigJSONKey: configJSON,
|
||||
},
|
||||
State: types.ContainerState{
|
||||
State: "ready",
|
||||
},
|
||||
Spec: &ociSpec,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/compatoci"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
|
||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||
)
|
||||
@@ -79,7 +80,7 @@ func TestExecuteErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, types.ContainerState{}, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, types.ContainerState{}, annotations, &specs.Spec{Process: &specs.Process{}}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -93,17 +94,16 @@ func TestExecuteErrors(t *testing.T) {
|
||||
// Container state undefined
|
||||
rootPath, bundlePath := testConfigSetup(t)
|
||||
defer os.RemoveAll(rootPath)
|
||||
configJSON, err := readOCIConfigJSON(bundlePath)
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
annotations = map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||
vcAnnotations.ConfigJSONKey: configJSON,
|
||||
}
|
||||
|
||||
containerState := types.ContainerState{}
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, containerState, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, containerState, annotations, &ociSpec), nil
|
||||
}
|
||||
|
||||
err = execute(context.Background(), ctx)
|
||||
@@ -115,7 +115,7 @@ func TestExecuteErrors(t *testing.T) {
|
||||
State: types.StatePaused,
|
||||
}
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, containerState, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, containerState, annotations, &ociSpec), nil
|
||||
}
|
||||
|
||||
err = execute(context.Background(), ctx)
|
||||
@@ -127,7 +127,7 @@ func TestExecuteErrors(t *testing.T) {
|
||||
State: types.StateStopped,
|
||||
}
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, containerState, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, containerState, annotations, &ociSpec), nil
|
||||
}
|
||||
|
||||
err = execute(context.Background(), ctx)
|
||||
@@ -152,12 +152,11 @@ func TestExecuteErrorReadingProcessJson(t *testing.T) {
|
||||
|
||||
rootPath, bundlePath := testConfigSetup(t)
|
||||
defer os.RemoveAll(rootPath)
|
||||
configJSON, err := readOCIConfigJSON(bundlePath)
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
annotations := map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||
vcAnnotations.ConfigJSONKey: configJSON,
|
||||
}
|
||||
|
||||
state := types.ContainerState{
|
||||
@@ -169,7 +168,7 @@ func TestExecuteErrorReadingProcessJson(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, state, annotations, &ociSpec), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -201,12 +200,11 @@ func TestExecuteErrorOpeningConsole(t *testing.T) {
|
||||
|
||||
rootPath, bundlePath := testConfigSetup(t)
|
||||
defer os.RemoveAll(rootPath)
|
||||
configJSON, err := readOCIConfigJSON(bundlePath)
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
annotations := map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||
vcAnnotations.ConfigJSONKey: configJSON,
|
||||
}
|
||||
|
||||
state := types.ContainerState{
|
||||
@@ -218,7 +216,7 @@ func TestExecuteErrorOpeningConsole(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, state, annotations, &ociSpec), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -268,12 +266,11 @@ func TestExecuteWithFlags(t *testing.T) {
|
||||
|
||||
rootPath, bundlePath := testConfigSetup(t)
|
||||
defer os.RemoveAll(rootPath)
|
||||
configJSON, err := readOCIConfigJSON(bundlePath)
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
annotations := map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||
vcAnnotations.ConfigJSONKey: configJSON,
|
||||
}
|
||||
|
||||
state := types.ContainerState{
|
||||
@@ -285,7 +282,7 @@ func TestExecuteWithFlags(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, state, annotations, &ociSpec), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -358,12 +355,11 @@ func TestExecuteWithFlagsDetached(t *testing.T) {
|
||||
|
||||
rootPath, bundlePath := testConfigSetup(t)
|
||||
defer os.RemoveAll(rootPath)
|
||||
configJSON, err := readOCIConfigJSON(bundlePath)
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
annotations := map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||
vcAnnotations.ConfigJSONKey: configJSON,
|
||||
}
|
||||
|
||||
state := types.ContainerState{
|
||||
@@ -375,7 +371,7 @@ func TestExecuteWithFlagsDetached(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, state, annotations, &ociSpec), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -437,12 +433,11 @@ func TestExecuteWithInvalidProcessJson(t *testing.T) {
|
||||
|
||||
rootPath, bundlePath := testConfigSetup(t)
|
||||
defer os.RemoveAll(rootPath)
|
||||
configJSON, err := readOCIConfigJSON(bundlePath)
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
annotations := map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||
vcAnnotations.ConfigJSONKey: configJSON,
|
||||
}
|
||||
|
||||
state := types.ContainerState{
|
||||
@@ -454,7 +449,7 @@ func TestExecuteWithInvalidProcessJson(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, state, annotations, &ociSpec), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -489,12 +484,11 @@ func TestExecuteWithValidProcessJson(t *testing.T) {
|
||||
|
||||
rootPath, bundlePath := testConfigSetup(t)
|
||||
defer os.RemoveAll(rootPath)
|
||||
configJSON, err := readOCIConfigJSON(bundlePath)
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
annotations := map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||
vcAnnotations.ConfigJSONKey: configJSON,
|
||||
}
|
||||
|
||||
state := types.ContainerState{
|
||||
@@ -506,7 +500,7 @@ func TestExecuteWithValidProcessJson(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, state, annotations, &ociSpec), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -590,12 +584,11 @@ func TestExecuteWithEmptyEnvironmentValue(t *testing.T) {
|
||||
|
||||
rootPath, bundlePath := testConfigSetup(t)
|
||||
defer os.RemoveAll(rootPath)
|
||||
configJSON, err := readOCIConfigJSON(bundlePath)
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
annotations := map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||
vcAnnotations.ConfigJSONKey: configJSON,
|
||||
}
|
||||
|
||||
state := types.ContainerState{
|
||||
@@ -607,7 +600,7 @@ func TestExecuteWithEmptyEnvironmentValue(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, state, annotations, &ociSpec), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
||||
@@ -13,11 +13,13 @@ import (
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
|
||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -81,7 +83,7 @@ func testKillCLIFunctionTerminationSignalSuccessful(t *testing.T, sig string) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, state, annotations, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -100,7 +102,7 @@ func testKillCLIFunctionTerminationSignalSuccessful(t *testing.T, sig string) {
|
||||
}
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, state, annotations, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
testingImpl.StopContainerFunc = nil
|
||||
@@ -134,7 +136,7 @@ func TestKillCLIFunctionNotTerminationSignalSuccessful(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -167,7 +169,7 @@ func TestKillCLIFunctionNoSignalSuccessful(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, state, annotations, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -186,7 +188,7 @@ func TestKillCLIFunctionNoSignalSuccessful(t *testing.T) {
|
||||
}
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, state, annotations, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
testingImpl.StopContainerFunc = nil
|
||||
@@ -223,7 +225,7 @@ func TestKillCLIFunctionEnableAllSuccessful(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, state, annotations, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -243,7 +245,7 @@ func TestKillCLIFunctionEnableAllSuccessful(t *testing.T) {
|
||||
}
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
return newSingleContainerStatus(testContainerID, state, annotations, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
testingImpl.StopContainerFunc = nil
|
||||
@@ -300,7 +302,7 @@ func TestKillCLIFunctionInvalidSignalFailure(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -330,7 +332,7 @@ func TestKillCLIFunctionStatePausedSuccessful(t *testing.T) {
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state,
|
||||
map[string]string{string(vcAnnotations.ContainerTypeKey): string(vc.PodContainer)}), nil
|
||||
map[string]string{string(vcAnnotations.ContainerTypeKey): string(vc.PodContainer)}, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -359,7 +361,7 @@ func TestKillCLIFunctionInvalidStateStoppedFailure(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -385,7 +387,7 @@ func TestKillCLIFunctionKillContainerFailure(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -412,7 +414,7 @@ func TestKillCLIFunctionInvalidStateStoppedAllSuccess(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
|
||||
"github.com/kata-containers/runtime/pkg/katautils"
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/compatoci"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
|
||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||
@@ -150,20 +151,6 @@ func runUnitTests(m *testing.M) {
|
||||
os.Exit(ret)
|
||||
}
|
||||
|
||||
// Read fail that should contain a specs.Spec and
|
||||
// return its JSON representation on success
|
||||
func readOCIConfigJSON(bundlePath string) (string, error) {
|
||||
ociSpec, err := oci.ParseConfigJSON(bundlePath)
|
||||
if err != nil {
|
||||
return "", nil
|
||||
}
|
||||
ociSpecJSON, err := json.Marshal(ociSpec)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(ociSpecJSON), err
|
||||
}
|
||||
|
||||
// TestMain is the common main function used by ALL the test functions
|
||||
// for this package.
|
||||
func TestMain(m *testing.M) {
|
||||
@@ -347,7 +334,7 @@ func realMakeOCIBundle(bundleDir string) error {
|
||||
|
||||
// Note the unusual parameter (a directory, not the config
|
||||
// file to parse!)
|
||||
spec, err := oci.ParseConfigJSON(bundleDir)
|
||||
spec, err := compatoci.ParseConfigJSON(bundleDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -412,11 +399,12 @@ func writeOCIConfigFile(spec specs.Spec, configPath string) error {
|
||||
return ioutil.WriteFile(configPath, bytes, testFileMode)
|
||||
}
|
||||
|
||||
func newSingleContainerStatus(containerID string, containerState types.ContainerState, annotations map[string]string) vc.ContainerStatus {
|
||||
func newSingleContainerStatus(containerID string, containerState types.ContainerState, annotations map[string]string, spec *specs.Spec) vc.ContainerStatus {
|
||||
return vc.ContainerStatus{
|
||||
ID: containerID,
|
||||
State: containerState,
|
||||
Annotations: annotations,
|
||||
Spec: spec,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,10 +12,12 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
|
||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -54,7 +56,7 @@ func TestNetworkCliFunction(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
||||
@@ -12,9 +12,11 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -41,7 +43,7 @@ func TestPauseCLIFunctionSuccessful(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -87,7 +89,7 @@ func TestPauseCLIFunctionPauseContainerFailure(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -114,7 +116,7 @@ func TestResumeCLIFunctionSuccessful(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -159,7 +161,7 @@ func TestResumeCLIFunctionPauseContainerFailure(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
||||
@@ -16,13 +16,16 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/urfave/cli"
|
||||
|
||||
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/compatoci"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func TestRunCliAction(t *testing.T) {
|
||||
@@ -155,7 +158,7 @@ type runContainerData struct {
|
||||
pidFilePath string
|
||||
consolePath string
|
||||
bundlePath string
|
||||
configJSON string
|
||||
spec *specs.Spec
|
||||
sandbox *vcmock.Sandbox
|
||||
runtimeConfig oci.RuntimeConfig
|
||||
process *os.Process
|
||||
@@ -205,15 +208,15 @@ func testRunContainerSetup(t *testing.T) runContainerData {
|
||||
runtimeConfig, err := newTestRuntimeConfig(tmpdir, consolePath, true)
|
||||
assert.NoError(err)
|
||||
|
||||
configJSON, err := readOCIConfigJSON(bundlePath)
|
||||
ociSpec, err := compatoci.ParseConfigJSON(bundlePath)
|
||||
assert.NoError(err)
|
||||
|
||||
return runContainerData{
|
||||
pidFilePath: pidFilePath,
|
||||
consolePath: consolePath,
|
||||
bundlePath: bundlePath,
|
||||
configJSON: configJSON,
|
||||
sandbox: sandbox,
|
||||
spec: &ociSpec,
|
||||
runtimeConfig: runtimeConfig,
|
||||
process: cmd.Process,
|
||||
tmpDir: tmpdir,
|
||||
@@ -259,8 +262,8 @@ func TestRunContainerSuccessful(t *testing.T) {
|
||||
ID: d.sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||
vcAnnotations.ConfigJSONKey: d.configJSON,
|
||||
},
|
||||
Spec: d.spec,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -368,8 +371,8 @@ func TestRunContainerDetachSuccessful(t *testing.T) {
|
||||
ID: d.sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||
vcAnnotations.ConfigJSONKey: d.configJSON,
|
||||
},
|
||||
Spec: d.spec,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -439,8 +442,8 @@ func TestRunContainerDeleteFail(t *testing.T) {
|
||||
ID: d.sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||
vcAnnotations.ConfigJSONKey: d.configJSON,
|
||||
},
|
||||
Spec: d.spec,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -513,8 +516,8 @@ func TestRunContainerWaitFail(t *testing.T) {
|
||||
ID: d.sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||
vcAnnotations.ConfigJSONKey: d.configJSON,
|
||||
},
|
||||
Spec: d.spec,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -595,8 +598,8 @@ func TestRunContainerStartFail(t *testing.T) {
|
||||
ID: d.sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||
vcAnnotations.ConfigJSONKey: d.configJSON,
|
||||
},
|
||||
Spec: d.spec,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -62,16 +61,13 @@ func TestStartSandbox(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
ociSpecJSON, err := json.Marshal(specs.Spec{})
|
||||
assert.NoError(err)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||
vcAnnotations.ConfigJSONKey: string(ociSpecJSON),
|
||||
},
|
||||
Spec: &specs.Spec{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -140,16 +136,13 @@ func TestStartContainerSucessFailure(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
ociSpecJSON, err := json.Marshal(specs.Spec{})
|
||||
assert.NoError(err)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: testContainerID,
|
||||
Annotations: map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||
vcAnnotations.ConfigJSONKey: string(ociSpecJSON),
|
||||
},
|
||||
Spec: &specs.Spec{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -218,16 +211,13 @@ func TestStartCLIFunctionSuccess(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
ociSpecJSON, err := json.Marshal(specs.Spec{})
|
||||
assert.NoError(err)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: testContainerID,
|
||||
Annotations: map[string]string{
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||
vcAnnotations.ConfigJSONKey: string(ociSpecJSON),
|
||||
},
|
||||
Spec: &specs.Spec{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user