mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 02:56:18 +00:00
tracing: Add context to virtcontainers API
Add a `context.Context` parameter to all the virtcontainers API's to support tracing. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
parent
f0073bec2f
commit
c200b28dc7
@ -99,11 +99,11 @@ func create(ctx context.Context, containerID, bundlePath, console, pidFilePath s
|
||||
defer span.Finish()
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("container", containerID)
|
||||
|
||||
// Checks the MUST and MUST NOT from OCI runtime specification
|
||||
if bundlePath, err = validCreateParams(containerID, bundlePath); err != nil {
|
||||
if bundlePath, err = validCreateParams(ctx, containerID, bundlePath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ func create(ctx context.Context, containerID, bundlePath, console, pidFilePath s
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
vci.SetFactory(f)
|
||||
vci.SetFactory(ctx, f)
|
||||
}
|
||||
}
|
||||
|
||||
@ -266,14 +266,14 @@ func createSandbox(ctx context.Context, ociSpec oci.CompatOCISpec, runtimeConfig
|
||||
return vc.Process{}, err
|
||||
}
|
||||
|
||||
sandbox, err := vci.CreateSandbox(sandboxConfig)
|
||||
sandbox, err := vci.CreateSandbox(ctx, sandboxConfig)
|
||||
if err != nil {
|
||||
return vc.Process{}, err
|
||||
}
|
||||
|
||||
sid := sandbox.ID()
|
||||
kataLog = kataLog.WithField("sandbox", sid)
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("sandbox", sid)
|
||||
|
||||
containers := sandbox.GetAllContainers()
|
||||
@ -321,10 +321,10 @@ func createContainer(ctx context.Context, ociSpec oci.CompatOCISpec, containerID
|
||||
}
|
||||
|
||||
kataLog = kataLog.WithField("sandbox", sandboxID)
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("sandbox", sandboxID)
|
||||
|
||||
_, c, err := vci.CreateContainer(sandboxID, contConfig)
|
||||
_, c, err := vci.CreateContainer(ctx, sandboxID, contConfig)
|
||||
if err != nil {
|
||||
return vc.Process{}, err
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ func TestCreateInvalidArgs(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
}
|
||||
|
||||
@ -488,7 +488,7 @@ func TestCreateProcessCgroupsPathSuccessful(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
ctrsMapTreePath = path
|
||||
|
||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
}
|
||||
|
||||
@ -583,7 +583,7 @@ func TestCreateCreateCgroupsFilesFail(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
ctrsMapTreePath = path
|
||||
|
||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
}
|
||||
|
||||
@ -668,7 +668,7 @@ func TestCreateCreateCreatePidFileFail(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
ctrsMapTreePath = path
|
||||
|
||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
}
|
||||
|
||||
@ -739,7 +739,7 @@ func TestCreate(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
ctrsMapTreePath = path
|
||||
|
||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
}
|
||||
|
||||
@ -1028,7 +1028,7 @@ func TestCreateCreateContainer(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
ctrsMapTreePath = path
|
||||
|
||||
testingImpl.CreateContainerFunc = func(sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) {
|
||||
testingImpl.CreateContainerFunc = func(ctx context.Context, sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) {
|
||||
return &vcmock.Sandbox{}, &vcmock.Container{}, nil
|
||||
}
|
||||
|
||||
|
@ -63,11 +63,11 @@ func delete(ctx context.Context, containerID string, force bool) error {
|
||||
defer span.Finish()
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("container", containerID)
|
||||
|
||||
// Checks the MUST and MUST NOT from OCI runtime specification
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
status, sandboxID, err := getExistingContainerInfo(ctx, containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -79,7 +79,7 @@ func delete(ctx context.Context, containerID string, force bool) error {
|
||||
"sandbox": sandboxID,
|
||||
})
|
||||
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
|
||||
span.SetTag("container", containerID)
|
||||
span.SetTag("sandbox", sandboxID)
|
||||
@ -136,18 +136,18 @@ func deleteSandbox(ctx context.Context, sandboxID string) error {
|
||||
span, _ := trace(ctx, "deleteSandbox")
|
||||
defer span.Finish()
|
||||
|
||||
status, err := vci.StatusSandbox(sandboxID)
|
||||
status, err := vci.StatusSandbox(ctx, sandboxID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if oci.StateToOCIState(status.State) != oci.StateStopped {
|
||||
if _, err := vci.StopSandbox(sandboxID); err != nil {
|
||||
if _, err := vci.StopSandbox(ctx, sandboxID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := vci.DeleteSandbox(sandboxID); err != nil {
|
||||
if _, err := vci.DeleteSandbox(ctx, sandboxID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -159,12 +159,12 @@ func deleteContainer(ctx context.Context, sandboxID, containerID string, forceSt
|
||||
defer span.Finish()
|
||||
|
||||
if forceStop {
|
||||
if _, err := vci.StopContainer(sandboxID, containerID); err != nil {
|
||||
if _, err := vci.StopContainer(ctx, sandboxID, containerID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := vci.DeleteContainer(sandboxID, containerID); err != nil {
|
||||
if _, err := vci.DeleteContainer(ctx, sandboxID, containerID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ func TestDeleteMissingContainerTypeAnnotation(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{},
|
||||
@ -104,7 +104,7 @@ func TestDeleteInvalidConfig(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
@ -156,7 +156,7 @@ func TestDeleteSandbox(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
@ -177,7 +177,7 @@ func TestDeleteSandbox(t *testing.T) {
|
||||
assert.Error(err)
|
||||
assert.True(vcmock.IsMockError(err))
|
||||
|
||||
testingImpl.StatusSandboxFunc = func(sandboxID string) (vc.SandboxStatus, error) {
|
||||
testingImpl.StatusSandboxFunc = func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error) {
|
||||
return vc.SandboxStatus{
|
||||
ID: sandbox.ID(),
|
||||
State: vc.State{
|
||||
@ -194,7 +194,7 @@ func TestDeleteSandbox(t *testing.T) {
|
||||
assert.Error(err)
|
||||
assert.True(vcmock.IsMockError(err))
|
||||
|
||||
testingImpl.StopSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.StopSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ func TestDeleteSandbox(t *testing.T) {
|
||||
assert.Error(err)
|
||||
assert.True(vcmock.IsMockError(err))
|
||||
|
||||
testingImpl.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.DeleteSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
}
|
||||
|
||||
@ -234,7 +234,7 @@ func TestDeleteInvalidContainerType(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
@ -273,7 +273,7 @@ func TestDeleteSandboxRunning(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
@ -295,7 +295,7 @@ func TestDeleteSandboxRunning(t *testing.T) {
|
||||
assert.Error(err)
|
||||
assert.False(vcmock.IsMockError(err))
|
||||
|
||||
testingImpl.StatusSandboxFunc = func(sandboxID string) (vc.SandboxStatus, error) {
|
||||
testingImpl.StatusSandboxFunc = func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error) {
|
||||
return vc.SandboxStatus{
|
||||
ID: sandbox.ID(),
|
||||
State: vc.State{
|
||||
@ -304,7 +304,7 @@ func TestDeleteSandboxRunning(t *testing.T) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
testingImpl.StopSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.StopSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
}
|
||||
|
||||
@ -318,7 +318,7 @@ func TestDeleteSandboxRunning(t *testing.T) {
|
||||
assert.Error(err)
|
||||
assert.True(vcmock.IsMockError(err))
|
||||
|
||||
testingImpl.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.DeleteSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ func TestDeleteRunningContainer(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.MockContainers[0].ID(),
|
||||
Annotations: map[string]string{
|
||||
@ -397,7 +397,7 @@ func TestDeleteRunningContainer(t *testing.T) {
|
||||
assert.Error(err)
|
||||
assert.True(vcmock.IsMockError(err))
|
||||
|
||||
testingImpl.DeleteContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
testingImpl.DeleteContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
return &vcmock.Container{}, nil
|
||||
}
|
||||
|
||||
@ -436,7 +436,7 @@ func TestDeleteContainer(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.MockContainers[0].ID(),
|
||||
Annotations: map[string]string{
|
||||
@ -470,7 +470,7 @@ func TestDeleteContainer(t *testing.T) {
|
||||
assert.Error(err)
|
||||
assert.True(vcmock.IsMockError(err))
|
||||
|
||||
testingImpl.DeleteContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
testingImpl.DeleteContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
return &vcmock.Container{}, nil
|
||||
}
|
||||
|
||||
@ -536,7 +536,7 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
@ -549,7 +549,7 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
testingImpl.StatusSandboxFunc = func(sandboxID string) (vc.SandboxStatus, error) {
|
||||
testingImpl.StatusSandboxFunc = func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error) {
|
||||
return vc.SandboxStatus{
|
||||
ID: sandbox.ID(),
|
||||
State: vc.State{
|
||||
@ -558,11 +558,11 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
testingImpl.StopSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.StopSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
}
|
||||
|
||||
testingImpl.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.DeleteSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ information is displayed once every 5 seconds.`,
|
||||
}
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("container", containerID)
|
||||
|
||||
duration := context.Duration("interval")
|
||||
@ -158,7 +158,7 @@ information is displayed once every 5 seconds.`,
|
||||
return fmt.Errorf("duration interval must be greater than 0")
|
||||
}
|
||||
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
status, sandboxID, err := getExistingContainerInfo(ctx, containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -170,7 +170,7 @@ information is displayed once every 5 seconds.`,
|
||||
"sandbox": sandboxID,
|
||||
})
|
||||
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("container", containerID)
|
||||
span.SetTag("sandbox", sandboxID)
|
||||
|
||||
@ -195,7 +195,7 @@ information is displayed once every 5 seconds.`,
|
||||
}()
|
||||
|
||||
if context.Bool("stats") {
|
||||
s, err := vci.StatsContainer(sandboxID, containerID)
|
||||
s, err := vci.StatsContainer(ctx, sandboxID, containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -207,7 +207,7 @@ information is displayed once every 5 seconds.`,
|
||||
|
||||
go func() {
|
||||
for range time.Tick(context.Duration("interval")) {
|
||||
s, err := vci.StatsContainer(sandboxID, containerID)
|
||||
s, err := vci.StatsContainer(ctx, sandboxID, containerID)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
continue
|
||||
|
@ -6,6 +6,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
@ -74,7 +75,7 @@ func TestEventsCLIFailure(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
@ -104,7 +105,7 @@ func TestEventsCLISuccessful(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
@ -116,7 +117,7 @@ func TestEventsCLISuccessful(t *testing.T) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
testingImpl.StatsContainerFunc = func(sandboxID, containerID string) (vc.ContainerStats, error) {
|
||||
testingImpl.StatsContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStats, error) {
|
||||
return vc.ContainerStats{}, nil
|
||||
}
|
||||
|
||||
|
10
cli/exec.go
10
cli/exec.go
@ -194,16 +194,16 @@ func execute(ctx context.Context, context *cli.Context) error {
|
||||
containerID := context.Args().First()
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("container", containerID)
|
||||
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
status, sandboxID, err := getExistingContainerInfo(ctx, containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
kataLog = kataLog.WithField("sandbox", sandboxID)
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("sandbox", sandboxID)
|
||||
|
||||
// Retrieve OCI spec configuration.
|
||||
@ -221,7 +221,7 @@ func execute(ctx context.Context, context *cli.Context) error {
|
||||
containerID = params.cID
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("container", containerID)
|
||||
|
||||
// container MUST be ready or running.
|
||||
@ -257,7 +257,7 @@ func execute(ctx context.Context, context *cli.Context) error {
|
||||
Detach: noNeedForOutput(params.detach, params.ociProcess.Terminal),
|
||||
}
|
||||
|
||||
_, _, process, err := vci.EnterContainer(sandboxID, params.cID, cmd)
|
||||
_, _, process, err := vci.EnterContainer(ctx, sandboxID, params.cID, cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ func TestExecuteErrors(t *testing.T) {
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||
}
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, vc.State{}, annotations), nil
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ func TestExecuteErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
containerState := vc.State{}
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, containerState, annotations), nil
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ func TestExecuteErrors(t *testing.T) {
|
||||
containerState = vc.State{
|
||||
State: vc.StatePaused,
|
||||
}
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, containerState, annotations), nil
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ func TestExecuteErrors(t *testing.T) {
|
||||
containerState = vc.State{
|
||||
State: vc.StateStopped,
|
||||
}
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, containerState, annotations), nil
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ func TestExecuteErrorReadingProcessJson(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
}
|
||||
|
||||
@ -215,7 +215,7 @@ func TestExecuteErrorOpeningConsole(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
}
|
||||
|
||||
@ -282,7 +282,7 @@ func TestExecuteWithFlags(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
}
|
||||
|
||||
@ -299,7 +299,7 @@ func TestExecuteWithFlags(t *testing.T) {
|
||||
|
||||
assert.True(vcmock.IsMockError(err))
|
||||
|
||||
testingImpl.EnterContainerFunc = func(sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
return &vcmock.Sandbox{}, &vcmock.Container{}, &vc.Process{}, nil
|
||||
}
|
||||
|
||||
@ -316,7 +316,7 @@ func TestExecuteWithFlags(t *testing.T) {
|
||||
os.Remove(pidFilePath)
|
||||
|
||||
// Process ran and exited successfully
|
||||
testingImpl.EnterContainerFunc = func(sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
// create a fake container process
|
||||
workload := []string{"cat", "/dev/null"}
|
||||
command := exec.Command(workload[0], workload[1:]...)
|
||||
@ -372,7 +372,7 @@ func TestExecuteWithFlagsDetached(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
}
|
||||
|
||||
@ -380,7 +380,7 @@ func TestExecuteWithFlagsDetached(t *testing.T) {
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
}()
|
||||
|
||||
testingImpl.EnterContainerFunc = func(sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
// create a fake container process
|
||||
workload := []string{"cat", "/dev/null"}
|
||||
command := exec.Command(workload[0], workload[1:]...)
|
||||
@ -451,7 +451,7 @@ func TestExecuteWithInvalidProcessJson(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
}
|
||||
|
||||
@ -503,7 +503,7 @@ func TestExecuteWithValidProcessJson(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
}
|
||||
|
||||
@ -542,7 +542,7 @@ func TestExecuteWithValidProcessJson(t *testing.T) {
|
||||
|
||||
workload := []string{"cat", "/dev/null"}
|
||||
|
||||
testingImpl.EnterContainerFunc = func(sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
// create a fake container process
|
||||
command := exec.Command(workload[0], workload[1:]...)
|
||||
err := command.Start()
|
||||
@ -604,7 +604,7 @@ func TestExecuteWithEmptyEnvironmentValue(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
}
|
||||
|
||||
@ -644,7 +644,7 @@ func TestExecuteWithEmptyEnvironmentValue(t *testing.T) {
|
||||
|
||||
workload := []string{"cat", "/dev/null"}
|
||||
|
||||
testingImpl.EnterContainerFunc = func(sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
testingImpl.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
// create a fake container process
|
||||
command := exec.Command(workload[0], workload[1:]...)
|
||||
err := command.Start()
|
||||
|
12
cli/kill.go
12
cli/kill.go
@ -101,11 +101,11 @@ func kill(ctx context.Context, containerID, signal string, all bool) error {
|
||||
defer span.Finish()
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("container", containerID)
|
||||
|
||||
// Checks the MUST and MUST NOT from OCI runtime specification
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
status, sandboxID, err := getExistingContainerInfo(ctx, containerID)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@ -121,7 +121,7 @@ func kill(ctx context.Context, containerID, signal string, all bool) error {
|
||||
span.SetTag("container", containerID)
|
||||
span.SetTag("sandbox", sandboxID)
|
||||
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
|
||||
signum, err := processSignal(signal)
|
||||
if err != nil {
|
||||
@ -133,7 +133,7 @@ func kill(ctx context.Context, containerID, signal string, all bool) error {
|
||||
return fmt.Errorf("Container %s not ready, running or paused, cannot send a signal", containerID)
|
||||
}
|
||||
|
||||
if err := vci.KillContainer(sandboxID, containerID, signum, all); err != nil {
|
||||
if err := vci.KillContainer(ctx, sandboxID, containerID, signum, all); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -148,9 +148,9 @@ func kill(ctx context.Context, containerID, signal string, all bool) error {
|
||||
|
||||
switch containerType {
|
||||
case vc.PodSandbox:
|
||||
_, err = vci.StopSandbox(sandboxID)
|
||||
_, err = vci.StopSandbox(ctx, sandboxID)
|
||||
case vc.PodContainer:
|
||||
_, err = vci.StopContainer(sandboxID, containerID)
|
||||
_, err = vci.StopContainer(ctx, sandboxID, containerID)
|
||||
default:
|
||||
return fmt.Errorf("Invalid container type found")
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -19,15 +20,15 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
testKillContainerFuncReturnNil = func(sandboxID, containerID string, signal syscall.Signal, all bool) error {
|
||||
testKillContainerFuncReturnNil = func(ctx context.Context, sandboxID, containerID string, signal syscall.Signal, all bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
testStopContainerFuncReturnNil = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
testStopContainerFuncReturnNil = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
return &vcmock.Container{}, nil
|
||||
}
|
||||
|
||||
testStopSandboxFuncReturnNil = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testStopSandboxFuncReturnNil = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return &vcmock.Sandbox{}, nil
|
||||
}
|
||||
)
|
||||
@ -78,7 +79,7 @@ func testKillCLIFunctionTerminationSignalSuccessful(t *testing.T, sig string) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
}
|
||||
|
||||
@ -97,7 +98,7 @@ func testKillCLIFunctionTerminationSignalSuccessful(t *testing.T, sig string) {
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||
}
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
}
|
||||
|
||||
@ -131,7 +132,7 @@ func TestKillCLIFunctionNotTerminationSignalSuccessful(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
}
|
||||
|
||||
@ -164,7 +165,7 @@ func TestKillCLIFunctionNoSignalSuccessful(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
}
|
||||
|
||||
@ -183,7 +184,7 @@ func TestKillCLIFunctionNoSignalSuccessful(t *testing.T) {
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||
}
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
}
|
||||
|
||||
@ -207,7 +208,7 @@ func TestKillCLIFunctionEnableAllSuccessful(t *testing.T) {
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||
}
|
||||
|
||||
testingImpl.KillContainerFunc = func(sandboxID, containerID string, signal syscall.Signal, all bool) error {
|
||||
testingImpl.KillContainerFunc = func(ctx context.Context, sandboxID, containerID string, signal syscall.Signal, all bool) error {
|
||||
if !all {
|
||||
return fmt.Errorf("Expecting -all flag = true, Got false")
|
||||
}
|
||||
@ -220,7 +221,7 @@ func TestKillCLIFunctionEnableAllSuccessful(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
}
|
||||
|
||||
@ -240,7 +241,7 @@ func TestKillCLIFunctionEnableAllSuccessful(t *testing.T) {
|
||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||
}
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||
}
|
||||
|
||||
@ -270,7 +271,7 @@ func TestKillCLIFunctionContainerNotExistFailure(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{}, nil
|
||||
}
|
||||
|
||||
@ -297,7 +298,7 @@ func TestKillCLIFunctionInvalidSignalFailure(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
}
|
||||
|
||||
@ -326,7 +327,7 @@ func TestKillCLIFunctionStatePausedSuccessful(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
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
|
||||
}
|
||||
@ -356,7 +357,7 @@ func TestKillCLIFunctionInvalidStateStoppedFailure(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
}
|
||||
|
||||
@ -382,7 +383,7 @@ func TestKillCLIFunctionKillContainerFailure(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -113,10 +114,10 @@ To list containers created using a non-default value for "--root":
|
||||
return err
|
||||
}
|
||||
|
||||
span, _ := trace(ctx, "list")
|
||||
span, ctx := trace(ctx, "list")
|
||||
defer span.Finish()
|
||||
|
||||
s, err := getContainers(context)
|
||||
s, err := getContainers(ctx, context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -300,7 +301,7 @@ func getDirOwner(dir string) (uint32, error) {
|
||||
return statType.Uid, nil
|
||||
}
|
||||
|
||||
func getContainers(context *cli.Context) ([]fullContainerState, error) {
|
||||
func getContainers(ctx context.Context, context *cli.Context) ([]fullContainerState, error) {
|
||||
runtimeConfig, ok := context.App.Metadata["runtimeConfig"].(oci.RuntimeConfig)
|
||||
if !ok {
|
||||
return nil, errors.New("invalid runtime config")
|
||||
@ -308,7 +309,7 @@ func getContainers(context *cli.Context) ([]fullContainerState, error) {
|
||||
|
||||
latestHypervisorDetails := getHypervisorDetails(&runtimeConfig.HypervisorConfig)
|
||||
|
||||
sandboxList, err := vci.ListSandbox()
|
||||
sandboxList, err := vci.ListSandbox(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
@ -380,7 +381,7 @@ func TestListGetContainersListSandboxFail(t *testing.T) {
|
||||
"runtimeConfig": runtimeConfig,
|
||||
}
|
||||
|
||||
_, err = getContainers(ctx)
|
||||
_, err = getContainers(context.Background(), ctx)
|
||||
assert.Error(err)
|
||||
assert.True(vcmock.IsMockError(err))
|
||||
}
|
||||
@ -388,7 +389,7 @@ func TestListGetContainersListSandboxFail(t *testing.T) {
|
||||
func TestListGetContainers(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
||||
testingImpl.ListSandboxFunc = func(ctx context.Context) ([]vc.SandboxStatus, error) {
|
||||
// No pre-existing sandboxes
|
||||
return []vc.SandboxStatus{}, nil
|
||||
}
|
||||
@ -411,7 +412,7 @@ func TestListGetContainers(t *testing.T) {
|
||||
"runtimeConfig": runtimeConfig,
|
||||
}
|
||||
|
||||
state, err := getContainers(ctx)
|
||||
state, err := getContainers(context.Background(), ctx)
|
||||
assert.NoError(err)
|
||||
assert.Equal(state, []fullContainerState(nil))
|
||||
}
|
||||
@ -423,7 +424,7 @@ func TestListGetContainersSandboxWithoutContainers(t *testing.T) {
|
||||
MockID: testSandboxID,
|
||||
}
|
||||
|
||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
||||
testingImpl.ListSandboxFunc = func(ctx context.Context) ([]vc.SandboxStatus, error) {
|
||||
return []vc.SandboxStatus{
|
||||
{
|
||||
ID: sandbox.ID(),
|
||||
@ -450,7 +451,7 @@ func TestListGetContainersSandboxWithoutContainers(t *testing.T) {
|
||||
"runtimeConfig": runtimeConfig,
|
||||
}
|
||||
|
||||
state, err := getContainers(ctx)
|
||||
state, err := getContainers(context.Background(), ctx)
|
||||
assert.NoError(err)
|
||||
assert.Equal(state, []fullContainerState(nil))
|
||||
}
|
||||
@ -470,7 +471,7 @@ func TestListGetContainersSandboxWithContainer(t *testing.T) {
|
||||
err = os.MkdirAll(rootfs, testDirMode)
|
||||
assert.NoError(err)
|
||||
|
||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
||||
testingImpl.ListSandboxFunc = func(ctx context.Context) ([]vc.SandboxStatus, error) {
|
||||
return []vc.SandboxStatus{
|
||||
{
|
||||
ID: sandbox.ID(),
|
||||
@ -497,7 +498,7 @@ func TestListGetContainersSandboxWithContainer(t *testing.T) {
|
||||
|
||||
ctx.App.Metadata["runtimeConfig"] = runtimeConfig
|
||||
|
||||
_, err = getContainers(ctx)
|
||||
_, err = getContainers(context.Background(), ctx)
|
||||
assert.NoError(err)
|
||||
}
|
||||
|
||||
@ -538,7 +539,7 @@ func TestListCLIFunctionFormatFail(t *testing.T) {
|
||||
|
||||
rootfs := filepath.Join(tmpdir, "rootfs")
|
||||
|
||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
||||
testingImpl.ListSandboxFunc = func(ctx context.Context) ([]vc.SandboxStatus, error) {
|
||||
return []vc.SandboxStatus{
|
||||
{
|
||||
ID: sandbox.ID(),
|
||||
@ -638,7 +639,7 @@ func TestListCLIFunctionQuiet(t *testing.T) {
|
||||
err = os.MkdirAll(rootfs, testDirMode)
|
||||
assert.NoError(err)
|
||||
|
||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
||||
testingImpl.ListSandboxFunc = func(ctx context.Context) ([]vc.SandboxStatus, error) {
|
||||
return []vc.SandboxStatus{
|
||||
{
|
||||
ID: sandbox.ID(),
|
||||
|
53
cli/main.go
53
cli/main.go
@ -208,23 +208,35 @@ func setupSignalHandler(ctx context.Context) {
|
||||
|
||||
// setExternalLoggers registers the specified logger with the external
|
||||
// packages which accept a logger to handle their own logging.
|
||||
func setExternalLoggers(logger *logrus.Entry) {
|
||||
func setExternalLoggers(ctx context.Context, logger *logrus.Entry) {
|
||||
var span opentracing.Span
|
||||
|
||||
// Only create a new span if a root span already exists. This is
|
||||
// required to ensure that this function will not disrupt the root
|
||||
// span logic by creating a span before the proper root span has been
|
||||
// created.
|
||||
|
||||
if opentracing.SpanFromContext(ctx) != nil {
|
||||
span, ctx = trace(ctx, "setExternalLoggers")
|
||||
defer span.Finish()
|
||||
}
|
||||
|
||||
// Set virtcontainers logger.
|
||||
vci.SetLogger(logger)
|
||||
vci.SetLogger(ctx, logger)
|
||||
|
||||
// Set vm factory logger.
|
||||
vf.SetLogger(logger)
|
||||
vf.SetLogger(ctx, logger)
|
||||
|
||||
// Set the OCI package logger.
|
||||
oci.SetLogger(logger)
|
||||
oci.SetLogger(ctx, logger)
|
||||
}
|
||||
|
||||
// beforeSubcommands is the function to perform preliminary checks
|
||||
// before command-line parsing occurs.
|
||||
func beforeSubcommands(context *cli.Context) error {
|
||||
handleShowConfig(context)
|
||||
func beforeSubcommands(c *cli.Context) error {
|
||||
handleShowConfig(c)
|
||||
|
||||
if userWantsUsage(context) || (context.NArg() == 1 && (context.Args()[0] == checkCmd)) {
|
||||
if userWantsUsage(c) || (c.NArg() == 1 && (c.Args()[0] == checkCmd)) {
|
||||
// No setup required if the user just
|
||||
// wants to see the usage statement or are
|
||||
// running a command that does not manipulate
|
||||
@ -232,7 +244,7 @@ func beforeSubcommands(context *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if path := context.GlobalString("log"); path != "" {
|
||||
if path := c.GlobalString("log"); path != "" {
|
||||
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND|os.O_SYNC, 0640)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -240,21 +252,21 @@ func beforeSubcommands(context *cli.Context) error {
|
||||
kataLog.Logger.Out = f
|
||||
}
|
||||
|
||||
switch context.GlobalString("log-format") {
|
||||
switch c.GlobalString("log-format") {
|
||||
case "text":
|
||||
// retain logrus's default.
|
||||
case "json":
|
||||
kataLog.Logger.Formatter = new(logrus.JSONFormatter)
|
||||
default:
|
||||
return fmt.Errorf("unknown log-format %q", context.GlobalString("log-format"))
|
||||
return fmt.Errorf("unknown log-format %q", c.GlobalString("log-format"))
|
||||
}
|
||||
|
||||
var traceRootSpan string
|
||||
|
||||
// Add the name of the sub-command to each log entry for easier
|
||||
// debugging.
|
||||
cmdName := context.Args().First()
|
||||
if context.App.Command(cmdName) != nil {
|
||||
cmdName := c.Args().First()
|
||||
if c.App.Command(cmdName) != nil {
|
||||
kataLog = kataLog.WithField("command", cmdName)
|
||||
|
||||
// Name for the root span (used for tracing) now the
|
||||
@ -262,16 +274,19 @@ func beforeSubcommands(context *cli.Context) error {
|
||||
traceRootSpan = name + " " + cmdName
|
||||
}
|
||||
|
||||
setExternalLoggers(kataLog)
|
||||
// Since a context is required, pass a new (throw-away) one - we
|
||||
// cannot use the main context as tracing hasn't been enabled yet
|
||||
// (meaning any spans created at this point will be silently ignored).
|
||||
setExternalLoggers(context.Background(), kataLog)
|
||||
|
||||
ignoreLogging := false
|
||||
|
||||
if context.NArg() == 1 && context.Args()[0] == envCmd {
|
||||
if c.NArg() == 1 && c.Args()[0] == envCmd {
|
||||
// simply report the logging setup
|
||||
ignoreLogging = true
|
||||
}
|
||||
|
||||
configFile, runtimeConfig, err := loadConfiguration(context.GlobalString(configFilePathOption), ignoreLogging)
|
||||
configFile, runtimeConfig, err := loadConfiguration(c.GlobalString(configFilePathOption), ignoreLogging)
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
@ -283,13 +298,13 @@ func beforeSubcommands(context *cli.Context) error {
|
||||
// This delays collection of trace data slightly but benefits the user by
|
||||
// ensuring the first span is the name of the sub-command being
|
||||
// invoked from the command-line.
|
||||
err = setupTracing(context, traceRootSpan)
|
||||
err = setupTracing(c, traceRootSpan)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
args := strings.Join(context.Args(), " ")
|
||||
args := strings.Join(c.Args(), " ")
|
||||
|
||||
fields := logrus.Fields{
|
||||
"version": version,
|
||||
@ -300,8 +315,8 @@ func beforeSubcommands(context *cli.Context) error {
|
||||
kataLog.WithFields(fields).Info()
|
||||
|
||||
// make the data accessible to the sub-commands.
|
||||
context.App.Metadata["runtimeConfig"] = runtimeConfig
|
||||
context.App.Metadata["configFile"] = configFile
|
||||
c.App.Metadata["runtimeConfig"] = runtimeConfig
|
||||
c.App.Metadata["configFile"] = configFile
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -46,7 +47,12 @@ var addIfaceCommand = cli.Command{
|
||||
ArgsUsage: `add-iface <container-id> file or - for stdin`,
|
||||
Flags: []cli.Flag{},
|
||||
Action: func(context *cli.Context) error {
|
||||
return networkModifyCommand(context.Args().First(), context.Args().Get(1), interfaceType, true)
|
||||
ctx, err := cliContextToContext(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return networkModifyCommand(ctx, context.Args().First(), context.Args().Get(1), interfaceType, true)
|
||||
},
|
||||
}
|
||||
|
||||
@ -56,7 +62,12 @@ var delIfaceCommand = cli.Command{
|
||||
ArgsUsage: `del-iface <container-id> file or - for stdin`,
|
||||
Flags: []cli.Flag{},
|
||||
Action: func(context *cli.Context) error {
|
||||
return networkModifyCommand(context.Args().First(), context.Args().Get(1), interfaceType, false)
|
||||
ctx, err := cliContextToContext(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return networkModifyCommand(ctx, context.Args().First(), context.Args().Get(1), interfaceType, false)
|
||||
},
|
||||
}
|
||||
|
||||
@ -66,7 +77,12 @@ var listIfacesCommand = cli.Command{
|
||||
ArgsUsage: `list-ifaces <container-id>`,
|
||||
Flags: []cli.Flag{},
|
||||
Action: func(context *cli.Context) error {
|
||||
return networkListCommand(context.Args().First(), interfaceType)
|
||||
ctx, err := cliContextToContext(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return networkListCommand(ctx, context.Args().First(), interfaceType)
|
||||
},
|
||||
}
|
||||
|
||||
@ -76,7 +92,12 @@ var updateRoutesCommand = cli.Command{
|
||||
ArgsUsage: `update-routes <container-id> file or - for stdin`,
|
||||
Flags: []cli.Flag{},
|
||||
Action: func(context *cli.Context) error {
|
||||
return networkModifyCommand(context.Args().First(), context.Args().Get(1), routeType, true)
|
||||
ctx, err := cliContextToContext(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return networkModifyCommand(ctx, context.Args().First(), context.Args().Get(1), routeType, true)
|
||||
},
|
||||
}
|
||||
|
||||
@ -86,12 +107,17 @@ var listRoutesCommand = cli.Command{
|
||||
ArgsUsage: `list-routes <container-id>`,
|
||||
Flags: []cli.Flag{},
|
||||
Action: func(context *cli.Context) error {
|
||||
return networkListCommand(context.Args().First(), routeType)
|
||||
ctx, err := cliContextToContext(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return networkListCommand(ctx, context.Args().First(), routeType)
|
||||
},
|
||||
}
|
||||
|
||||
func networkModifyCommand(containerID, input string, opType networkType, add bool) (err error) {
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
func networkModifyCommand(ctx context.Context, containerID, input string, opType networkType, add bool) (err error) {
|
||||
status, sandboxID, err := getExistingContainerInfo(ctx, containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -103,7 +129,7 @@ func networkModifyCommand(containerID, input string, opType networkType, add boo
|
||||
"sandbox": sandboxID,
|
||||
})
|
||||
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
|
||||
// container MUST be running
|
||||
if status.State.State != vc.StateRunning {
|
||||
@ -131,13 +157,13 @@ func networkModifyCommand(containerID, input string, opType networkType, add boo
|
||||
return err
|
||||
}
|
||||
if add {
|
||||
resultingInf, err = vci.AddInterface(sandboxID, inf)
|
||||
resultingInf, err = vci.AddInterface(ctx, sandboxID, inf)
|
||||
if err != nil {
|
||||
kataLog.WithField("resulting-interface", fmt.Sprintf("%+v", resultingInf)).
|
||||
WithError(err).Error("add interface failed")
|
||||
}
|
||||
} else {
|
||||
resultingInf, err = vci.RemoveInterface(sandboxID, inf)
|
||||
resultingInf, err = vci.RemoveInterface(ctx, sandboxID, inf)
|
||||
if err != nil {
|
||||
kataLog.WithField("resulting-interface", fmt.Sprintf("%+v", resultingInf)).
|
||||
WithError(err).Error("delete interface failed")
|
||||
@ -149,7 +175,7 @@ func networkModifyCommand(containerID, input string, opType networkType, add boo
|
||||
if err = json.NewDecoder(f).Decode(&routes); err != nil {
|
||||
return err
|
||||
}
|
||||
resultingRoutes, err = vci.UpdateRoutes(sandboxID, routes)
|
||||
resultingRoutes, err = vci.UpdateRoutes(ctx, sandboxID, routes)
|
||||
json.NewEncoder(output).Encode(resultingRoutes)
|
||||
if err != nil {
|
||||
kataLog.WithField("resulting-routes", fmt.Sprintf("%+v", resultingRoutes)).
|
||||
@ -159,8 +185,8 @@ func networkModifyCommand(containerID, input string, opType networkType, add boo
|
||||
return err
|
||||
}
|
||||
|
||||
func networkListCommand(containerID string, opType networkType) (err error) {
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
func networkListCommand(ctx context.Context, containerID string, opType networkType) (err error) {
|
||||
status, sandboxID, err := getExistingContainerInfo(ctx, containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -172,7 +198,7 @@ func networkListCommand(containerID string, opType networkType) (err error) {
|
||||
"sandbox": sandboxID,
|
||||
})
|
||||
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
|
||||
// container MUST be running
|
||||
if status.State.State != vc.StateRunning {
|
||||
@ -184,7 +210,7 @@ func networkListCommand(containerID string, opType networkType) (err error) {
|
||||
switch opType {
|
||||
case interfaceType:
|
||||
var interfaces []*grpc.Interface
|
||||
interfaces, err = vci.ListInterfaces(sandboxID)
|
||||
interfaces, err = vci.ListInterfaces(ctx, sandboxID)
|
||||
if err != nil {
|
||||
kataLog.WithField("existing-interfaces", fmt.Sprintf("%+v", interfaces)).
|
||||
WithError(err).Error("list interfaces failed")
|
||||
@ -192,7 +218,7 @@ func networkListCommand(containerID string, opType networkType) (err error) {
|
||||
json.NewEncoder(file).Encode(interfaces)
|
||||
case routeType:
|
||||
var routes []*grpc.Route
|
||||
routes, err = vci.ListRoutes(sandboxID)
|
||||
routes, err = vci.ListRoutes(ctx, sandboxID)
|
||||
if err != nil {
|
||||
kataLog.WithField("resulting-routes", fmt.Sprintf("%+v", routes)).
|
||||
WithError(err).Error("update routes failed")
|
||||
|
@ -6,6 +6,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -17,19 +18,19 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
testAddInterfaceFuncReturnNil = func(sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
testAddInterfaceFuncReturnNil = func(ctx context.Context, sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
testRemoveInterfaceFuncReturnNil = func(sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
testRemoveInterfaceFuncReturnNil = func(ctx context.Context, sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
testListInterfacesFuncReturnNil = func(sandboxID string) ([]*grpc.Interface, error) {
|
||||
testListInterfacesFuncReturnNil = func(ctx context.Context, sandboxID string) ([]*grpc.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
testUpdateRoutsFuncReturnNil = func(sandboxID string, routes []*grpc.Route) ([]*grpc.Route, error) {
|
||||
testUpdateRoutsFuncReturnNil = func(ctx context.Context, sandboxID string, routes []*grpc.Route) ([]*grpc.Route, error) {
|
||||
return nil, nil
|
||||
}
|
||||
testListRoutesFuncReturnNil = func(sandboxID string) ([]*grpc.Route, error) {
|
||||
testListRoutesFuncReturnNil = func(ctx context.Context, sandboxID string) ([]*grpc.Route, error) {
|
||||
return nil, nil
|
||||
}
|
||||
)
|
||||
@ -51,7 +52,7 @@ func TestNetworkCliFunction(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
}
|
||||
|
||||
|
12
cli/oci.go
12
cli/oci.go
@ -46,7 +46,7 @@ var procMountInfo = "/proc/self/mountinfo"
|
||||
var ctrsMapTreePath = "/var/run/kata-containers/containers-mapping"
|
||||
|
||||
// getContainerInfo returns the container status and its sandbox ID.
|
||||
func getContainerInfo(containerID string) (vc.ContainerStatus, string, error) {
|
||||
func getContainerInfo(ctx context.Context, containerID string) (vc.ContainerStatus, string, error) {
|
||||
// container ID MUST be provided.
|
||||
if containerID == "" {
|
||||
return vc.ContainerStatus{}, "", fmt.Errorf("Missing container ID")
|
||||
@ -63,7 +63,7 @@ func getContainerInfo(containerID string) (vc.ContainerStatus, string, error) {
|
||||
return vc.ContainerStatus{}, "", nil
|
||||
}
|
||||
|
||||
ctrStatus, err := vci.StatusContainer(sandboxID, containerID)
|
||||
ctrStatus, err := vci.StatusContainer(ctx, sandboxID, containerID)
|
||||
if err != nil {
|
||||
return vc.ContainerStatus{}, "", err
|
||||
}
|
||||
@ -71,8 +71,8 @@ func getContainerInfo(containerID string) (vc.ContainerStatus, string, error) {
|
||||
return ctrStatus, sandboxID, nil
|
||||
}
|
||||
|
||||
func getExistingContainerInfo(containerID string) (vc.ContainerStatus, string, error) {
|
||||
cStatus, sandboxID, err := getContainerInfo(containerID)
|
||||
func getExistingContainerInfo(ctx context.Context, containerID string) (vc.ContainerStatus, string, error) {
|
||||
cStatus, sandboxID, err := getContainerInfo(ctx, containerID)
|
||||
if err != nil {
|
||||
return vc.ContainerStatus{}, "", err
|
||||
}
|
||||
@ -85,14 +85,14 @@ func getExistingContainerInfo(containerID string) (vc.ContainerStatus, string, e
|
||||
return cStatus, sandboxID, nil
|
||||
}
|
||||
|
||||
func validCreateParams(containerID, bundlePath string) (string, error) {
|
||||
func validCreateParams(ctx context.Context, containerID, bundlePath string) (string, error) {
|
||||
// container ID MUST be provided.
|
||||
if containerID == "" {
|
||||
return "", fmt.Errorf("Missing container ID")
|
||||
}
|
||||
|
||||
// container ID MUST be unique.
|
||||
cStatus, _, err := getContainerInfo(containerID)
|
||||
cStatus, _, err := getContainerInfo(ctx, containerID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ var cgroupTestData = []cgroupTestDataType{
|
||||
|
||||
func TestGetContainerInfoContainerIDEmptyFailure(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
status, _, err := getContainerInfo("")
|
||||
status, _, err := getContainerInfo(context.Background(), "")
|
||||
|
||||
assert.Error(err, "This test should fail because containerID is empty")
|
||||
assert.Empty(status.ID, "Expected blank fullID, but got %v", status.ID)
|
||||
@ -92,7 +92,7 @@ func TestGetContainerInfo(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return containerStatus, nil
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ func TestGetContainerInfo(t *testing.T) {
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
}()
|
||||
|
||||
status, sandboxID, err := getContainerInfo(testContainerID)
|
||||
status, sandboxID, err := getContainerInfo(context.Background(), testContainerID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandboxID, sandbox.ID())
|
||||
assert.Equal(status, containerStatus)
|
||||
@ -108,7 +108,7 @@ func TestGetContainerInfo(t *testing.T) {
|
||||
|
||||
func TestValidCreateParamsContainerIDEmptyFailure(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
_, err := validCreateParams("", "")
|
||||
_, err := validCreateParams(context.Background(), "", "")
|
||||
|
||||
assert.Error(err, "This test should fail because containerID is empty")
|
||||
assert.False(vcmock.IsMockError(err))
|
||||
@ -116,7 +116,7 @@ func TestValidCreateParamsContainerIDEmptyFailure(t *testing.T) {
|
||||
|
||||
func TestGetExistingContainerInfoContainerIDEmptyFailure(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
status, _, err := getExistingContainerInfo("")
|
||||
status, _, err := getExistingContainerInfo(context.Background(), "")
|
||||
|
||||
assert.Error(err, "This test should fail because containerID is empty")
|
||||
assert.Empty(status.ID, "Expected blank fullID, but got %v", status.ID)
|
||||
@ -133,7 +133,7 @@ func TestValidCreateParamsContainerIDNotUnique(t *testing.T) {
|
||||
err = os.MkdirAll(filepath.Join(ctrsMapTreePath, testContainerID, testSandboxID2), 0750)
|
||||
assert.NoError(err)
|
||||
|
||||
_, err = validCreateParams(testContainerID, "")
|
||||
_, err = validCreateParams(context.Background(), testContainerID, "")
|
||||
|
||||
assert.Error(err)
|
||||
assert.False(vcmock.IsMockError(err))
|
||||
@ -153,7 +153,7 @@ func TestValidCreateParamsInvalidBundle(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
ctrsMapTreePath = path
|
||||
|
||||
_, err = validCreateParams(testContainerID, bundlePath)
|
||||
_, err = validCreateParams(context.Background(), testContainerID, bundlePath)
|
||||
// bundle is ENOENT
|
||||
assert.Error(err)
|
||||
assert.False(vcmock.IsMockError(err))
|
||||
@ -175,7 +175,7 @@ func TestValidCreateParamsBundleIsAFile(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
ctrsMapTreePath = path
|
||||
|
||||
_, err = validCreateParams(testContainerID, bundlePath)
|
||||
_, err = validCreateParams(context.Background(), testContainerID, bundlePath)
|
||||
// bundle exists as a file, not a directory
|
||||
assert.Error(err)
|
||||
assert.False(vcmock.IsMockError(err))
|
||||
|
10
cli/pause.go
10
cli/pause.go
@ -62,11 +62,11 @@ func toggleContainerPause(ctx context.Context, containerID string, pause bool) (
|
||||
span.SetTag("pause", pause)
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("container", containerID)
|
||||
|
||||
// Checks the MUST and MUST NOT from OCI runtime specification
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
status, sandboxID, err := getExistingContainerInfo(ctx, containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -78,14 +78,14 @@ func toggleContainerPause(ctx context.Context, containerID string, pause bool) (
|
||||
"sandbox": sandboxID,
|
||||
})
|
||||
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("container", containerID)
|
||||
span.SetTag("sandbox", sandboxID)
|
||||
|
||||
if pause {
|
||||
err = vci.PauseContainer(sandboxID, containerID)
|
||||
err = vci.PauseContainer(ctx, sandboxID, containerID)
|
||||
} else {
|
||||
err = vci.ResumeContainer(sandboxID, containerID)
|
||||
err = vci.ResumeContainer(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
return err
|
||||
|
@ -6,6 +6,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -16,11 +17,11 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
testPauseContainerFuncReturnNil = func(sandboxID, containerID string) error {
|
||||
testPauseContainerFuncReturnNil = func(ctx context.Context, sandboxID, containerID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
testResumeContainerFuncReturnNil = func(sandboxID, containerID string) error {
|
||||
testResumeContainerFuncReturnNil = func(ctx context.Context, sandboxID, containerID string) error {
|
||||
return nil
|
||||
}
|
||||
)
|
||||
@ -38,7 +39,7 @@ func TestPauseCLIFunctionSuccessful(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
}
|
||||
|
||||
@ -84,7 +85,7 @@ func TestPauseCLIFunctionPauseContainerFailure(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
}
|
||||
|
||||
@ -111,7 +112,7 @@ func TestResumeCLIFunctionSuccessful(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
}
|
||||
|
||||
@ -156,7 +157,7 @@ func TestResumeCLIFunctionPauseContainerFailure(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
}
|
||||
|
||||
|
@ -58,11 +58,11 @@ func ps(ctx context.Context, containerID, format string, args []string) error {
|
||||
}
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("container", containerID)
|
||||
|
||||
// Checks the MUST and MUST NOT from OCI runtime specification
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
status, sandboxID, err := getExistingContainerInfo(ctx, containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -74,7 +74,7 @@ func ps(ctx context.Context, containerID, format string, args []string) error {
|
||||
"sandbox": sandboxID,
|
||||
})
|
||||
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("container", containerID)
|
||||
span.SetTag("sandbox", sandboxID)
|
||||
|
||||
@ -92,7 +92,7 @@ func ps(ctx context.Context, containerID, format string, args []string) error {
|
||||
|
||||
options.Format = format
|
||||
|
||||
msg, err := vci.ProcessListContainer(containerID, sandboxID, options)
|
||||
msg, err := vci.ProcessListContainer(ctx, containerID, sandboxID, options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ func TestPSFailure(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
@ -93,7 +93,7 @@ func TestPSSuccessful(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
State: vc.State{
|
||||
State: vc.StateRunning,
|
||||
@ -105,7 +105,7 @@ func TestPSSuccessful(t *testing.T) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
testingImpl.ProcessListContainerFunc = func(sandboxID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) {
|
||||
testingImpl.ProcessListContainerFunc = func(ctx context.Context, sandboxID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) {
|
||||
return []byte("echo,sleep,grep"), nil
|
||||
}
|
||||
|
||||
|
@ -67,11 +67,11 @@ func TestRunInvalidArgs(t *testing.T) {
|
||||
}
|
||||
|
||||
// fake functions used to run containers
|
||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
}
|
||||
|
||||
testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.StartSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
}
|
||||
|
||||
@ -230,12 +230,12 @@ func TestRunContainerSuccessful(t *testing.T) {
|
||||
flagCreate := false
|
||||
|
||||
// fake functions used to run containers
|
||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
flagCreate = true
|
||||
return d.sandbox, nil
|
||||
}
|
||||
|
||||
testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.StartSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return d.sandbox, nil
|
||||
}
|
||||
|
||||
@ -244,7 +244,7 @@ func TestRunContainerSuccessful(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
ctrsMapTreePath = path
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
// return an empty list on create
|
||||
if !flagCreate {
|
||||
return vc.ContainerStatus{}, nil
|
||||
@ -260,7 +260,7 @@ func TestRunContainerSuccessful(t *testing.T) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
testingImpl.StartContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
testingImpl.StartContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
// now we can kill the fake container workload
|
||||
err := d.process.Kill()
|
||||
assert.NoError(err)
|
||||
@ -268,11 +268,11 @@ func TestRunContainerSuccessful(t *testing.T) {
|
||||
return d.sandbox.MockContainers[0], nil
|
||||
}
|
||||
|
||||
testingImpl.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.DeleteSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return d.sandbox, nil
|
||||
}
|
||||
|
||||
testingImpl.DeleteContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
testingImpl.DeleteContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
return d.sandbox.MockContainers[0], nil
|
||||
}
|
||||
|
||||
@ -304,12 +304,12 @@ func TestRunContainerDetachSuccessful(t *testing.T) {
|
||||
flagCreate := false
|
||||
|
||||
// fake functions used to run containers
|
||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
flagCreate = true
|
||||
return d.sandbox, nil
|
||||
}
|
||||
|
||||
testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.StartSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return d.sandbox, nil
|
||||
}
|
||||
|
||||
@ -318,7 +318,7 @@ func TestRunContainerDetachSuccessful(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
ctrsMapTreePath = path
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
// return an empty list on create
|
||||
if !flagCreate {
|
||||
return vc.ContainerStatus{}, nil
|
||||
@ -334,7 +334,7 @@ func TestRunContainerDetachSuccessful(t *testing.T) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
testingImpl.StartContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
testingImpl.StartContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
// now we can kill the fake container workload
|
||||
err := d.process.Kill()
|
||||
assert.NoError(err)
|
||||
@ -342,11 +342,11 @@ func TestRunContainerDetachSuccessful(t *testing.T) {
|
||||
return d.sandbox.MockContainers[0], nil
|
||||
}
|
||||
|
||||
testingImpl.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.DeleteSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return d.sandbox, nil
|
||||
}
|
||||
|
||||
testingImpl.DeleteContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
testingImpl.DeleteContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
return d.sandbox.MockContainers[0], nil
|
||||
}
|
||||
|
||||
@ -375,12 +375,12 @@ func TestRunContainerDeleteFail(t *testing.T) {
|
||||
flagCreate := false
|
||||
|
||||
// fake functions used to run containers
|
||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
flagCreate = true
|
||||
return d.sandbox, nil
|
||||
}
|
||||
|
||||
testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.StartSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return d.sandbox, nil
|
||||
}
|
||||
|
||||
@ -389,7 +389,7 @@ func TestRunContainerDeleteFail(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
ctrsMapTreePath = path
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
// return an empty list on create
|
||||
if !flagCreate {
|
||||
return vc.ContainerStatus{}, nil
|
||||
@ -405,7 +405,7 @@ func TestRunContainerDeleteFail(t *testing.T) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
testingImpl.StartContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
testingImpl.StartContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
// now we can kill the fake container workload
|
||||
err := d.process.Kill()
|
||||
assert.NoError(err)
|
||||
@ -413,12 +413,12 @@ func TestRunContainerDeleteFail(t *testing.T) {
|
||||
return d.sandbox.MockContainers[0], nil
|
||||
}
|
||||
|
||||
testingImpl.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.DeleteSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
// return an error to provoke a failure in delete
|
||||
return nil, fmt.Errorf("DeleteSandboxFunc")
|
||||
}
|
||||
|
||||
testingImpl.DeleteContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
testingImpl.DeleteContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
// return an error to provoke a failure in delete
|
||||
return d.sandbox.MockContainers[0], fmt.Errorf("DeleteContainerFunc")
|
||||
}
|
||||
@ -449,12 +449,12 @@ func TestRunContainerWaitFail(t *testing.T) {
|
||||
flagCreate := false
|
||||
|
||||
// fake functions used to run containers
|
||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
flagCreate = true
|
||||
return d.sandbox, nil
|
||||
}
|
||||
|
||||
testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.StartSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return d.sandbox, nil
|
||||
}
|
||||
|
||||
@ -463,7 +463,7 @@ func TestRunContainerWaitFail(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
ctrsMapTreePath = path
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
// return an empty list on create
|
||||
if !flagCreate {
|
||||
return vc.ContainerStatus{}, nil
|
||||
@ -479,7 +479,7 @@ func TestRunContainerWaitFail(t *testing.T) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
testingImpl.StartContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
testingImpl.StartContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
// now we can kill the fake container workload
|
||||
err := d.process.Kill()
|
||||
assert.NoError(err)
|
||||
@ -490,12 +490,12 @@ func TestRunContainerWaitFail(t *testing.T) {
|
||||
return d.sandbox.MockContainers[0], nil
|
||||
}
|
||||
|
||||
testingImpl.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.DeleteSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
// return an error to provoke a failure in delete
|
||||
return nil, fmt.Errorf("DeleteSandboxFunc")
|
||||
}
|
||||
|
||||
testingImpl.DeleteContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
testingImpl.DeleteContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
// return an error to provoke a failure in delete
|
||||
return d.sandbox.MockContainers[0], fmt.Errorf("DeleteContainerFunc")
|
||||
}
|
||||
@ -530,12 +530,12 @@ func TestRunContainerStartFail(t *testing.T) {
|
||||
flagCreate := false
|
||||
|
||||
// fake functions used to run containers
|
||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
flagCreate = true
|
||||
return d.sandbox, nil
|
||||
}
|
||||
|
||||
testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.StartSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
// start fails
|
||||
return nil, fmt.Errorf("StartSandbox")
|
||||
}
|
||||
@ -545,7 +545,7 @@ func TestRunContainerStartFail(t *testing.T) {
|
||||
defer os.RemoveAll(path)
|
||||
ctrsMapTreePath = path
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
// return an empty list on create
|
||||
if !flagCreate {
|
||||
return vc.ContainerStatus{}, nil
|
||||
@ -595,7 +595,7 @@ func TestRunContainerStartFailExistingContainer(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
// return the container status
|
||||
return vc.ContainerStatus{
|
||||
ID: testContainerID,
|
||||
@ -605,11 +605,11 @@ func TestRunContainerStartFailExistingContainer(t *testing.T) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
}
|
||||
|
||||
testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.StartSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
// force no containers
|
||||
sandbox.MockContainers = nil
|
||||
|
||||
|
10
cli/start.go
10
cli/start.go
@ -51,11 +51,11 @@ func start(ctx context.Context, containerID string) (vc.VCSandbox, error) {
|
||||
defer span.Finish()
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("container", containerID)
|
||||
|
||||
// Checks the MUST and MUST NOT from OCI runtime specification
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
status, sandboxID, err := getExistingContainerInfo(ctx, containerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -67,7 +67,7 @@ func start(ctx context.Context, containerID string) (vc.VCSandbox, error) {
|
||||
"sandbox": sandboxID,
|
||||
})
|
||||
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("container", containerID)
|
||||
span.SetTag("sandbox", sandboxID)
|
||||
|
||||
@ -77,10 +77,10 @@ func start(ctx context.Context, containerID string) (vc.VCSandbox, error) {
|
||||
}
|
||||
|
||||
if containerType.IsSandbox() {
|
||||
return vci.StartSandbox(sandboxID)
|
||||
return vci.StartSandbox(ctx, sandboxID)
|
||||
}
|
||||
|
||||
c, err := vci.StartContainer(sandboxID, containerID)
|
||||
c, err := vci.StartContainer(ctx, sandboxID, containerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ func TestStartSandbox(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
@ -75,7 +75,7 @@ func TestStartSandbox(t *testing.T) {
|
||||
assert.Error(err)
|
||||
assert.True(vcmock.IsMockError(err))
|
||||
|
||||
testingImpl.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
testingImpl.StartSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ func TestStartMissingAnnotation(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{},
|
||||
@ -132,7 +132,7 @@ func TestStartContainerSucessFailure(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: testContainerID,
|
||||
Annotations: map[string]string{
|
||||
@ -149,7 +149,7 @@ func TestStartContainerSucessFailure(t *testing.T) {
|
||||
assert.Error(err)
|
||||
assert.True(vcmock.IsMockError(err))
|
||||
|
||||
testingImpl.StartContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
testingImpl.StartContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
return sandbox.MockContainers[0], nil
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ func TestStartCLIFunctionSuccess(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: testContainerID,
|
||||
Annotations: map[string]string{
|
||||
@ -215,7 +215,7 @@ func TestStartCLIFunctionSuccess(t *testing.T) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
testingImpl.StartContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
testingImpl.StartContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
return sandbox.MockContainers[0], nil
|
||||
}
|
||||
|
||||
|
@ -46,10 +46,10 @@ func state(ctx context.Context, containerID string) error {
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
span.SetTag("container", containerID)
|
||||
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
|
||||
// Checks the MUST and MUST NOT from OCI runtime specification
|
||||
status, _, err := getExistingContainerInfo(containerID)
|
||||
status, _, err := getExistingContainerInfo(ctx, containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ func TestStateSuccessful(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: testContainerID,
|
||||
Annotations: map[string]string{
|
||||
|
@ -142,10 +142,10 @@ other options are ignored.
|
||||
containerID := context.Args().First()
|
||||
|
||||
kataLog = kataLog.WithField("container", containerID)
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
span.SetTag("container", containerID)
|
||||
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
status, sandboxID, err := getExistingContainerInfo(ctx, containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -157,7 +157,7 @@ other options are ignored.
|
||||
"sandbox": sandboxID,
|
||||
})
|
||||
|
||||
setExternalLoggers(kataLog)
|
||||
setExternalLoggers(ctx, kataLog)
|
||||
|
||||
span.SetTag("container", containerID)
|
||||
span.SetTag("sandbox", sandboxID)
|
||||
@ -281,6 +281,6 @@ other options are ignored.
|
||||
r.Pids.Limit = int64(context.Int("pids-limit"))
|
||||
}
|
||||
|
||||
return vci.UpdateContainer(sandboxID, containerID, r)
|
||||
return vci.UpdateContainer(ctx, sandboxID, containerID, r)
|
||||
},
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -71,7 +72,7 @@ func TestUpdateCLIFailure(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
@ -87,7 +88,7 @@ func TestUpdateCLIFailure(t *testing.T) {
|
||||
assert.Error(err)
|
||||
|
||||
// resources file does not exist
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
@ -98,7 +99,7 @@ func TestUpdateCLIFailure(t *testing.T) {
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
testingImpl.UpdateContainerFunc = func(sandboxID, containerID string, resources specs.LinuxResources) error {
|
||||
testingImpl.UpdateContainerFunc = func(ctx context.Context, sandboxID, containerID string, resources specs.LinuxResources) error {
|
||||
return nil
|
||||
}
|
||||
defer func() {
|
||||
@ -160,7 +161,7 @@ func TestUpdateCLISuccessful(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
@ -171,7 +172,7 @@ func TestUpdateCLISuccessful(t *testing.T) {
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
testingImpl.UpdateContainerFunc = func(sandboxID, containerID string, resources specs.LinuxResources) error {
|
||||
testingImpl.UpdateContainerFunc = func(ctx context.Context, sandboxID, containerID string, resources specs.LinuxResources) error {
|
||||
return nil
|
||||
}
|
||||
defer func() {
|
||||
|
@ -6,6 +6,7 @@
|
||||
package virtcontainers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"runtime"
|
||||
"syscall"
|
||||
@ -24,7 +25,7 @@ func init() {
|
||||
var virtLog = logrus.WithField("source", "virtcontainers")
|
||||
|
||||
// SetLogger sets the logger for virtcontainers package.
|
||||
func SetLogger(logger *logrus.Entry) {
|
||||
func SetLogger(ctx context.Context, logger *logrus.Entry) {
|
||||
fields := virtLog.Data
|
||||
virtLog = logger.WithFields(fields)
|
||||
|
||||
@ -33,7 +34,7 @@ func SetLogger(logger *logrus.Entry) {
|
||||
|
||||
// CreateSandbox is the virtcontainers sandbox creation entry point.
|
||||
// CreateSandbox creates a sandbox and its containers. It does not start them.
|
||||
func CreateSandbox(sandboxConfig SandboxConfig, factory Factory) (VCSandbox, error) {
|
||||
func CreateSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factory) (VCSandbox, error) {
|
||||
s, err := createSandboxFromConfig(sandboxConfig, factory)
|
||||
if err == nil {
|
||||
s.releaseStatelessSandbox()
|
||||
@ -104,7 +105,7 @@ func createSandboxFromConfig(sandboxConfig SandboxConfig, factory Factory) (*San
|
||||
|
||||
// DeleteSandbox is the virtcontainers sandbox deletion entry point.
|
||||
// DeleteSandbox will stop an already running container and then delete it.
|
||||
func DeleteSandbox(sandboxID string) (VCSandbox, error) {
|
||||
func DeleteSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, errNeedSandboxID
|
||||
}
|
||||
@ -134,7 +135,7 @@ func DeleteSandbox(sandboxID string) (VCSandbox, error) {
|
||||
// FetchSandbox will find out and connect to an existing sandbox and
|
||||
// return the sandbox structure. The caller is responsible of calling
|
||||
// VCSandbox.Release() after done with it.
|
||||
func FetchSandbox(sandboxID string) (VCSandbox, error) {
|
||||
func FetchSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, errNeedSandboxID
|
||||
}
|
||||
@ -168,7 +169,7 @@ func FetchSandbox(sandboxID string) (VCSandbox, error) {
|
||||
// StartSandbox will talk to the given hypervisor to start an existing
|
||||
// sandbox and all its containers.
|
||||
// It returns the sandbox ID.
|
||||
func StartSandbox(sandboxID string) (VCSandbox, error) {
|
||||
func StartSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, errNeedSandboxID
|
||||
}
|
||||
@ -206,7 +207,7 @@ func startSandbox(s *Sandbox) (*Sandbox, error) {
|
||||
|
||||
// StopSandbox is the virtcontainers sandbox stopping entry point.
|
||||
// StopSandbox will talk to the given agent to stop an existing sandbox and destroy all containers within that sandbox.
|
||||
func StopSandbox(sandboxID string) (VCSandbox, error) {
|
||||
func StopSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, errNeedSandbox
|
||||
}
|
||||
@ -245,7 +246,7 @@ func StopSandbox(sandboxID string) (VCSandbox, error) {
|
||||
|
||||
// RunSandbox is the virtcontainers sandbox running entry point.
|
||||
// RunSandbox creates a sandbox and its containers and then it starts them.
|
||||
func RunSandbox(sandboxConfig SandboxConfig, factory Factory) (VCSandbox, error) {
|
||||
func RunSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factory) (VCSandbox, error) {
|
||||
s, err := createSandboxFromConfig(sandboxConfig, factory)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -262,7 +263,7 @@ func RunSandbox(sandboxConfig SandboxConfig, factory Factory) (VCSandbox, error)
|
||||
}
|
||||
|
||||
// ListSandbox is the virtcontainers sandbox listing entry point.
|
||||
func ListSandbox() ([]SandboxStatus, error) {
|
||||
func ListSandbox(ctx context.Context) ([]SandboxStatus, error) {
|
||||
dir, err := os.Open(configStoragePath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
@ -282,7 +283,7 @@ func ListSandbox() ([]SandboxStatus, error) {
|
||||
var sandboxStatusList []SandboxStatus
|
||||
|
||||
for _, sandboxID := range sandboxesID {
|
||||
sandboxStatus, err := StatusSandbox(sandboxID)
|
||||
sandboxStatus, err := StatusSandbox(ctx, sandboxID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@ -294,7 +295,7 @@ func ListSandbox() ([]SandboxStatus, error) {
|
||||
}
|
||||
|
||||
// StatusSandbox is the virtcontainers sandbox status entry point.
|
||||
func StatusSandbox(sandboxID string) (SandboxStatus, error) {
|
||||
func StatusSandbox(ctx context.Context, sandboxID string) (SandboxStatus, error) {
|
||||
if sandboxID == "" {
|
||||
return SandboxStatus{}, errNeedSandboxID
|
||||
}
|
||||
@ -346,7 +347,7 @@ func StatusSandbox(sandboxID string) (SandboxStatus, error) {
|
||||
|
||||
// CreateContainer is the virtcontainers container creation entry point.
|
||||
// CreateContainer creates a container on a given sandbox.
|
||||
func CreateContainer(sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error) {
|
||||
func CreateContainer(ctx context.Context, sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, nil, errNeedSandboxID
|
||||
}
|
||||
@ -374,7 +375,7 @@ func CreateContainer(sandboxID string, containerConfig ContainerConfig) (VCSandb
|
||||
// DeleteContainer is the virtcontainers container deletion entry point.
|
||||
// DeleteContainer deletes a Container from a Sandbox. If the container is running,
|
||||
// it needs to be stopped first.
|
||||
func DeleteContainer(sandboxID, containerID string) (VCContainer, error) {
|
||||
func DeleteContainer(ctx context.Context, sandboxID, containerID string) (VCContainer, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, errNeedSandboxID
|
||||
}
|
||||
@ -400,7 +401,7 @@ func DeleteContainer(sandboxID, containerID string) (VCContainer, error) {
|
||||
|
||||
// StartContainer is the virtcontainers container starting entry point.
|
||||
// StartContainer starts an already created container.
|
||||
func StartContainer(sandboxID, containerID string) (VCContainer, error) {
|
||||
func StartContainer(ctx context.Context, sandboxID, containerID string) (VCContainer, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, errNeedSandboxID
|
||||
}
|
||||
@ -431,7 +432,7 @@ func StartContainer(sandboxID, containerID string) (VCContainer, error) {
|
||||
|
||||
// StopContainer is the virtcontainers container stopping entry point.
|
||||
// StopContainer stops an already running container.
|
||||
func StopContainer(sandboxID, containerID string) (VCContainer, error) {
|
||||
func StopContainer(ctx context.Context, sandboxID, containerID string) (VCContainer, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, errNeedSandboxID
|
||||
}
|
||||
@ -469,7 +470,7 @@ func StopContainer(sandboxID, containerID string) (VCContainer, error) {
|
||||
|
||||
// EnterContainer is the virtcontainers container command execution entry point.
|
||||
// EnterContainer enters an already running container and runs a given command.
|
||||
func EnterContainer(sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContainer, *Process, error) {
|
||||
func EnterContainer(ctx context.Context, sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContainer, *Process, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, nil, nil, errNeedSandboxID
|
||||
}
|
||||
@ -500,7 +501,7 @@ func EnterContainer(sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContai
|
||||
|
||||
// StatusContainer is the virtcontainers container status entry point.
|
||||
// StatusContainer returns a detailed container status.
|
||||
func StatusContainer(sandboxID, containerID string) (ContainerStatus, error) {
|
||||
func StatusContainer(ctx context.Context, sandboxID, containerID string) (ContainerStatus, error) {
|
||||
if sandboxID == "" {
|
||||
return ContainerStatus{}, errNeedSandboxID
|
||||
}
|
||||
@ -587,7 +588,7 @@ func statusContainer(sandbox *Sandbox, containerID string) (ContainerStatus, err
|
||||
// KillContainer is the virtcontainers entry point to send a signal
|
||||
// to a container running inside a sandbox. If all is true, all processes in
|
||||
// the container will be sent the signal.
|
||||
func KillContainer(sandboxID, containerID string, signal syscall.Signal, all bool) error {
|
||||
func KillContainer(ctx context.Context, sandboxID, containerID string, signal syscall.Signal, all bool) error {
|
||||
if sandboxID == "" {
|
||||
return errNeedSandboxID
|
||||
}
|
||||
@ -625,19 +626,19 @@ func KillContainer(sandboxID, containerID string, signal syscall.Signal, all boo
|
||||
|
||||
// PauseSandbox is the virtcontainers pausing entry point which pauses an
|
||||
// already running sandbox.
|
||||
func PauseSandbox(sandboxID string) (VCSandbox, error) {
|
||||
func PauseSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
||||
return togglePauseSandbox(sandboxID, true)
|
||||
}
|
||||
|
||||
// ResumeSandbox is the virtcontainers resuming entry point which resumes
|
||||
// (or unpauses) and already paused sandbox.
|
||||
func ResumeSandbox(sandboxID string) (VCSandbox, error) {
|
||||
func ResumeSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
||||
return togglePauseSandbox(sandboxID, false)
|
||||
}
|
||||
|
||||
// ProcessListContainer is the virtcontainers entry point to list
|
||||
// processes running inside a container
|
||||
func ProcessListContainer(sandboxID, containerID string, options ProcessListOptions) (ProcessList, error) {
|
||||
func ProcessListContainer(ctx context.Context, sandboxID, containerID string, options ProcessListOptions) (ProcessList, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, errNeedSandboxID
|
||||
}
|
||||
@ -669,7 +670,7 @@ func ProcessListContainer(sandboxID, containerID string, options ProcessListOpti
|
||||
|
||||
// UpdateContainer is the virtcontainers entry point to update
|
||||
// container's resources.
|
||||
func UpdateContainer(sandboxID, containerID string, resources specs.LinuxResources) error {
|
||||
func UpdateContainer(ctx context.Context, sandboxID, containerID string, resources specs.LinuxResources) error {
|
||||
if sandboxID == "" {
|
||||
return errNeedSandboxID
|
||||
}
|
||||
@ -695,7 +696,7 @@ func UpdateContainer(sandboxID, containerID string, resources specs.LinuxResourc
|
||||
|
||||
// StatsContainer is the virtcontainers container stats entry point.
|
||||
// StatsContainer returns a detailed container stats.
|
||||
func StatsContainer(sandboxID, containerID string) (ContainerStats, error) {
|
||||
func StatsContainer(ctx context.Context, sandboxID, containerID string) (ContainerStats, error) {
|
||||
if sandboxID == "" {
|
||||
return ContainerStats{}, errNeedSandboxID
|
||||
}
|
||||
@ -754,17 +755,17 @@ func togglePauseContainer(sandboxID, containerID string, pause bool) error {
|
||||
}
|
||||
|
||||
// PauseContainer is the virtcontainers container pause entry point.
|
||||
func PauseContainer(sandboxID, containerID string) error {
|
||||
func PauseContainer(ctx context.Context, sandboxID, containerID string) error {
|
||||
return togglePauseContainer(sandboxID, containerID, true)
|
||||
}
|
||||
|
||||
// ResumeContainer is the virtcontainers container resume entry point.
|
||||
func ResumeContainer(sandboxID, containerID string) error {
|
||||
func ResumeContainer(ctx context.Context, sandboxID, containerID string) error {
|
||||
return togglePauseContainer(sandboxID, containerID, false)
|
||||
}
|
||||
|
||||
// AddDevice will add a device to sandbox
|
||||
func AddDevice(sandboxID string, info deviceConfig.DeviceInfo) (deviceApi.Device, error) {
|
||||
func AddDevice(ctx context.Context, sandboxID string, info deviceConfig.DeviceInfo) (deviceApi.Device, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, errNeedSandboxID
|
||||
}
|
||||
@ -784,7 +785,7 @@ func AddDevice(sandboxID string, info deviceConfig.DeviceInfo) (deviceApi.Device
|
||||
return s.AddDevice(info)
|
||||
}
|
||||
|
||||
func toggleInterface(sandboxID string, inf *grpc.Interface, add bool) (*grpc.Interface, error) {
|
||||
func toggleInterface(ctx context.Context, sandboxID string, inf *grpc.Interface, add bool) (*grpc.Interface, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, errNeedSandboxID
|
||||
}
|
||||
@ -806,17 +807,17 @@ func toggleInterface(sandboxID string, inf *grpc.Interface, add bool) (*grpc.Int
|
||||
}
|
||||
|
||||
// AddInterface is the virtcontainers add interface entry point.
|
||||
func AddInterface(sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
return toggleInterface(sandboxID, inf, true)
|
||||
func AddInterface(ctx context.Context, sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
return toggleInterface(ctx, sandboxID, inf, true)
|
||||
}
|
||||
|
||||
// RemoveInterface is the virtcontainers remove interface entry point.
|
||||
func RemoveInterface(sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
return toggleInterface(sandboxID, inf, false)
|
||||
func RemoveInterface(ctx context.Context, sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
return toggleInterface(ctx, sandboxID, inf, false)
|
||||
}
|
||||
|
||||
// ListInterfaces is the virtcontainers list interfaces entry point.
|
||||
func ListInterfaces(sandboxID string) ([]*grpc.Interface, error) {
|
||||
func ListInterfaces(ctx context.Context, sandboxID string) ([]*grpc.Interface, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, errNeedSandboxID
|
||||
}
|
||||
@ -836,7 +837,7 @@ func ListInterfaces(sandboxID string) ([]*grpc.Interface, error) {
|
||||
}
|
||||
|
||||
// UpdateRoutes is the virtcontainers update routes entry point.
|
||||
func UpdateRoutes(sandboxID string, routes []*grpc.Route) ([]*grpc.Route, error) {
|
||||
func UpdateRoutes(ctx context.Context, sandboxID string, routes []*grpc.Route) ([]*grpc.Route, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, errNeedSandboxID
|
||||
}
|
||||
@ -855,7 +856,7 @@ func UpdateRoutes(sandboxID string, routes []*grpc.Route) ([]*grpc.Route, error)
|
||||
}
|
||||
|
||||
// ListRoutes is the virtcontainers list routes entry point.
|
||||
func ListRoutes(sandboxID string) ([]*grpc.Route, error) {
|
||||
func ListRoutes(ctx context.Context, sandboxID string) ([]*grpc.Route, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, errNeedSandboxID
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,6 +6,7 @@
|
||||
package virtcontainers_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@ -68,7 +69,7 @@ func Example_createAndStartSandbox() {
|
||||
Containers: []vc.ContainerConfig{container},
|
||||
}
|
||||
|
||||
_, err := vc.RunSandbox(sandboxConfig, nil)
|
||||
_, err := vc.RunSandbox(context.Background(), sandboxConfig, nil)
|
||||
if err != nil {
|
||||
fmt.Printf("Could not run sandbox: %s", err)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
package factory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
@ -68,7 +69,7 @@ func NewFactory(config Config, fetchOnly bool) (vc.Factory, error) {
|
||||
}
|
||||
|
||||
// SetLogger sets the logger for the factory.
|
||||
func SetLogger(logger logrus.FieldLogger) {
|
||||
func SetLogger(ctx context.Context, logger logrus.FieldLogger) {
|
||||
fields := logrus.Fields{
|
||||
"source": "virtcontainers",
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
package factory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
@ -72,7 +73,7 @@ func TestFactorySetLogger(t *testing.T) {
|
||||
|
||||
testLog := logrus.WithFields(logrus.Fields{"testfield": "foobar"})
|
||||
testLog.Level = logrus.DebugLevel
|
||||
SetLogger(testLog)
|
||||
SetLogger(context.Background(), testLog)
|
||||
|
||||
var config Config
|
||||
config.VMConfig.HypervisorConfig = vc.HypervisorConfig{
|
||||
|
@ -6,6 +6,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -24,6 +25,8 @@ var virtcLog *logrus.Entry
|
||||
var listFormat = "%s\t%s\t%s\t%s\n"
|
||||
var statusFormat = "%s\t%s\n"
|
||||
|
||||
var ctx = context.Background()
|
||||
|
||||
var (
|
||||
errNeedContainerID = errors.New("Container ID cannot be empty")
|
||||
errNeedSandboxID = errors.New("Sandbox ID cannot be empty")
|
||||
@ -322,7 +325,7 @@ func runSandbox(context *cli.Context) error {
|
||||
return fmt.Errorf("Could not build sandbox config: %s", err)
|
||||
}
|
||||
|
||||
_, err = vc.RunSandbox(sandboxConfig, nil)
|
||||
_, err = vc.RunSandbox(ctx, sandboxConfig, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not run sandbox: %s", err)
|
||||
}
|
||||
@ -336,7 +339,7 @@ func createSandbox(context *cli.Context) error {
|
||||
return fmt.Errorf("Could not build sandbox config: %s", err)
|
||||
}
|
||||
|
||||
p, err := vc.CreateSandbox(sandboxConfig, nil)
|
||||
p, err := vc.CreateSandbox(ctx, sandboxConfig, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not create sandbox: %s", err)
|
||||
}
|
||||
@ -363,7 +366,7 @@ func checkContainerArgs(context *cli.Context, f func(context *cli.Context) error
|
||||
}
|
||||
|
||||
func deleteSandbox(context *cli.Context) error {
|
||||
p, err := vc.DeleteSandbox(context.String("id"))
|
||||
p, err := vc.DeleteSandbox(ctx, context.String("id"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not delete sandbox: %s", err)
|
||||
}
|
||||
@ -374,7 +377,7 @@ func deleteSandbox(context *cli.Context) error {
|
||||
}
|
||||
|
||||
func startSandbox(context *cli.Context) error {
|
||||
p, err := vc.StartSandbox(context.String("id"))
|
||||
p, err := vc.StartSandbox(ctx, context.String("id"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not start sandbox: %s", err)
|
||||
}
|
||||
@ -385,7 +388,7 @@ func startSandbox(context *cli.Context) error {
|
||||
}
|
||||
|
||||
func stopSandbox(context *cli.Context) error {
|
||||
p, err := vc.StopSandbox(context.String("id"))
|
||||
p, err := vc.StopSandbox(ctx, context.String("id"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not stop sandbox: %s", err)
|
||||
}
|
||||
@ -396,7 +399,7 @@ func stopSandbox(context *cli.Context) error {
|
||||
}
|
||||
|
||||
func pauseSandbox(context *cli.Context) error {
|
||||
p, err := vc.PauseSandbox(context.String("id"))
|
||||
p, err := vc.PauseSandbox(ctx, context.String("id"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not pause sandbox: %s", err)
|
||||
}
|
||||
@ -407,7 +410,7 @@ func pauseSandbox(context *cli.Context) error {
|
||||
}
|
||||
|
||||
func resumeSandbox(context *cli.Context) error {
|
||||
p, err := vc.ResumeSandbox(context.String("id"))
|
||||
p, err := vc.ResumeSandbox(ctx, context.String("id"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not resume sandbox: %s", err)
|
||||
}
|
||||
@ -418,7 +421,7 @@ func resumeSandbox(context *cli.Context) error {
|
||||
}
|
||||
|
||||
func listSandboxes(context *cli.Context) error {
|
||||
sandboxStatusList, err := vc.ListSandbox()
|
||||
sandboxStatusList, err := vc.ListSandbox(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not list sandbox: %s", err)
|
||||
}
|
||||
@ -437,7 +440,7 @@ func listSandboxes(context *cli.Context) error {
|
||||
}
|
||||
|
||||
func statusSandbox(context *cli.Context) error {
|
||||
sandboxStatus, err := vc.StatusSandbox(context.String("id"))
|
||||
sandboxStatus, err := vc.StatusSandbox(ctx, context.String("id"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not get sandbox status: %s", err)
|
||||
}
|
||||
@ -610,7 +613,7 @@ func createContainer(context *cli.Context) error {
|
||||
Cmd: cmd,
|
||||
}
|
||||
|
||||
_, c, err := vc.CreateContainer(context.String("sandbox-id"), containerConfig)
|
||||
_, c, err := vc.CreateContainer(ctx, context.String("sandbox-id"), containerConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not create container: %s", err)
|
||||
}
|
||||
@ -621,7 +624,7 @@ func createContainer(context *cli.Context) error {
|
||||
}
|
||||
|
||||
func deleteContainer(context *cli.Context) error {
|
||||
c, err := vc.DeleteContainer(context.String("sandbox-id"), context.String("id"))
|
||||
c, err := vc.DeleteContainer(ctx, context.String("sandbox-id"), context.String("id"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not delete container: %s", err)
|
||||
}
|
||||
@ -632,7 +635,7 @@ func deleteContainer(context *cli.Context) error {
|
||||
}
|
||||
|
||||
func startContainer(context *cli.Context) error {
|
||||
c, err := vc.StartContainer(context.String("sandbox-id"), context.String("id"))
|
||||
c, err := vc.StartContainer(ctx, context.String("sandbox-id"), context.String("id"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not start container: %s", err)
|
||||
}
|
||||
@ -643,7 +646,7 @@ func startContainer(context *cli.Context) error {
|
||||
}
|
||||
|
||||
func stopContainer(context *cli.Context) error {
|
||||
c, err := vc.StopContainer(context.String("sandbox-id"), context.String("id"))
|
||||
c, err := vc.StopContainer(ctx, context.String("sandbox-id"), context.String("id"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not stop container: %s", err)
|
||||
}
|
||||
@ -676,7 +679,7 @@ func enterContainer(context *cli.Context) error {
|
||||
Console: console,
|
||||
}
|
||||
|
||||
_, c, _, err := vc.EnterContainer(context.String("sandbox-id"), context.String("id"), cmd)
|
||||
_, c, _, err := vc.EnterContainer(ctx, context.String("sandbox-id"), context.String("id"), cmd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not enter container: %s", err)
|
||||
}
|
||||
@ -687,7 +690,7 @@ func enterContainer(context *cli.Context) error {
|
||||
}
|
||||
|
||||
func statusContainer(context *cli.Context) error {
|
||||
contStatus, err := vc.StatusContainer(context.String("sandbox-id"), context.String("id"))
|
||||
contStatus, err := vc.StatusContainer(ctx, context.String("sandbox-id"), context.String("id"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not get container status: %s", err)
|
||||
}
|
||||
@ -926,7 +929,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Set virtcontainers logger.
|
||||
vc.SetLogger(virtcLog)
|
||||
vc.SetLogger(ctx, virtcLog)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
package virtcontainers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"syscall"
|
||||
|
||||
"github.com/kata-containers/agent/protocols/grpc"
|
||||
@ -25,152 +26,152 @@ type VCImpl struct {
|
||||
}
|
||||
|
||||
// SetLogger implements the VC function of the same name.
|
||||
func (impl *VCImpl) SetLogger(logger *logrus.Entry) {
|
||||
SetLogger(logger)
|
||||
func (impl *VCImpl) SetLogger(ctx context.Context, logger *logrus.Entry) {
|
||||
SetLogger(ctx, logger)
|
||||
}
|
||||
|
||||
// SetFactory implements the VC function of the same name.
|
||||
func (impl *VCImpl) SetFactory(factory Factory) {
|
||||
func (impl *VCImpl) SetFactory(ctx context.Context, factory Factory) {
|
||||
impl.factory = factory
|
||||
}
|
||||
|
||||
// CreateSandbox implements the VC function of the same name.
|
||||
func (impl *VCImpl) CreateSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) {
|
||||
return CreateSandbox(sandboxConfig, impl.factory)
|
||||
func (impl *VCImpl) CreateSandbox(ctx context.Context, sandboxConfig SandboxConfig) (VCSandbox, error) {
|
||||
return CreateSandbox(ctx, sandboxConfig, impl.factory)
|
||||
}
|
||||
|
||||
// DeleteSandbox implements the VC function of the same name.
|
||||
func (impl *VCImpl) DeleteSandbox(sandboxID string) (VCSandbox, error) {
|
||||
return DeleteSandbox(sandboxID)
|
||||
func (impl *VCImpl) DeleteSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
||||
return DeleteSandbox(ctx, sandboxID)
|
||||
}
|
||||
|
||||
// StartSandbox implements the VC function of the same name.
|
||||
func (impl *VCImpl) StartSandbox(sandboxID string) (VCSandbox, error) {
|
||||
return StartSandbox(sandboxID)
|
||||
func (impl *VCImpl) StartSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
||||
return StartSandbox(ctx, sandboxID)
|
||||
}
|
||||
|
||||
// StopSandbox implements the VC function of the same name.
|
||||
func (impl *VCImpl) StopSandbox(sandboxID string) (VCSandbox, error) {
|
||||
return StopSandbox(sandboxID)
|
||||
func (impl *VCImpl) StopSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
||||
return StopSandbox(ctx, sandboxID)
|
||||
}
|
||||
|
||||
// RunSandbox implements the VC function of the same name.
|
||||
func (impl *VCImpl) RunSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) {
|
||||
return RunSandbox(sandboxConfig, impl.factory)
|
||||
func (impl *VCImpl) RunSandbox(ctx context.Context, sandboxConfig SandboxConfig) (VCSandbox, error) {
|
||||
return RunSandbox(ctx, sandboxConfig, impl.factory)
|
||||
}
|
||||
|
||||
// ListSandbox implements the VC function of the same name.
|
||||
func (impl *VCImpl) ListSandbox() ([]SandboxStatus, error) {
|
||||
return ListSandbox()
|
||||
func (impl *VCImpl) ListSandbox(ctx context.Context) ([]SandboxStatus, error) {
|
||||
return ListSandbox(ctx)
|
||||
}
|
||||
|
||||
// FetchSandbox will find out and connect to an existing sandbox and
|
||||
// return the sandbox structure.
|
||||
func (impl *VCImpl) FetchSandbox(sandboxID string) (VCSandbox, error) {
|
||||
return FetchSandbox(sandboxID)
|
||||
func (impl *VCImpl) FetchSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
||||
return FetchSandbox(ctx, sandboxID)
|
||||
}
|
||||
|
||||
// StatusSandbox implements the VC function of the same name.
|
||||
func (impl *VCImpl) StatusSandbox(sandboxID string) (SandboxStatus, error) {
|
||||
return StatusSandbox(sandboxID)
|
||||
func (impl *VCImpl) StatusSandbox(ctx context.Context, sandboxID string) (SandboxStatus, error) {
|
||||
return StatusSandbox(ctx, sandboxID)
|
||||
}
|
||||
|
||||
// PauseSandbox implements the VC function of the same name.
|
||||
func (impl *VCImpl) PauseSandbox(sandboxID string) (VCSandbox, error) {
|
||||
return PauseSandbox(sandboxID)
|
||||
func (impl *VCImpl) PauseSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
||||
return PauseSandbox(ctx, sandboxID)
|
||||
}
|
||||
|
||||
// ResumeSandbox implements the VC function of the same name.
|
||||
func (impl *VCImpl) ResumeSandbox(sandboxID string) (VCSandbox, error) {
|
||||
return ResumeSandbox(sandboxID)
|
||||
func (impl *VCImpl) ResumeSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
||||
return ResumeSandbox(ctx, sandboxID)
|
||||
}
|
||||
|
||||
// CreateContainer implements the VC function of the same name.
|
||||
func (impl *VCImpl) CreateContainer(sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error) {
|
||||
return CreateContainer(sandboxID, containerConfig)
|
||||
func (impl *VCImpl) CreateContainer(ctx context.Context, sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error) {
|
||||
return CreateContainer(ctx, sandboxID, containerConfig)
|
||||
}
|
||||
|
||||
// DeleteContainer implements the VC function of the same name.
|
||||
func (impl *VCImpl) DeleteContainer(sandboxID, containerID string) (VCContainer, error) {
|
||||
return DeleteContainer(sandboxID, containerID)
|
||||
func (impl *VCImpl) DeleteContainer(ctx context.Context, sandboxID, containerID string) (VCContainer, error) {
|
||||
return DeleteContainer(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// StartContainer implements the VC function of the same name.
|
||||
func (impl *VCImpl) StartContainer(sandboxID, containerID string) (VCContainer, error) {
|
||||
return StartContainer(sandboxID, containerID)
|
||||
func (impl *VCImpl) StartContainer(ctx context.Context, sandboxID, containerID string) (VCContainer, error) {
|
||||
return StartContainer(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// StopContainer implements the VC function of the same name.
|
||||
func (impl *VCImpl) StopContainer(sandboxID, containerID string) (VCContainer, error) {
|
||||
return StopContainer(sandboxID, containerID)
|
||||
func (impl *VCImpl) StopContainer(ctx context.Context, sandboxID, containerID string) (VCContainer, error) {
|
||||
return StopContainer(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// EnterContainer implements the VC function of the same name.
|
||||
func (impl *VCImpl) EnterContainer(sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContainer, *Process, error) {
|
||||
return EnterContainer(sandboxID, containerID, cmd)
|
||||
func (impl *VCImpl) EnterContainer(ctx context.Context, sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContainer, *Process, error) {
|
||||
return EnterContainer(ctx, sandboxID, containerID, cmd)
|
||||
}
|
||||
|
||||
// StatusContainer implements the VC function of the same name.
|
||||
func (impl *VCImpl) StatusContainer(sandboxID, containerID string) (ContainerStatus, error) {
|
||||
return StatusContainer(sandboxID, containerID)
|
||||
func (impl *VCImpl) StatusContainer(ctx context.Context, sandboxID, containerID string) (ContainerStatus, error) {
|
||||
return StatusContainer(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// StatsContainer implements the VC function of the same name.
|
||||
func (impl *VCImpl) StatsContainer(sandboxID, containerID string) (ContainerStats, error) {
|
||||
return StatsContainer(sandboxID, containerID)
|
||||
func (impl *VCImpl) StatsContainer(ctx context.Context, sandboxID, containerID string) (ContainerStats, error) {
|
||||
return StatsContainer(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// KillContainer implements the VC function of the same name.
|
||||
func (impl *VCImpl) KillContainer(sandboxID, containerID string, signal syscall.Signal, all bool) error {
|
||||
return KillContainer(sandboxID, containerID, signal, all)
|
||||
func (impl *VCImpl) KillContainer(ctx context.Context, sandboxID, containerID string, signal syscall.Signal, all bool) error {
|
||||
return KillContainer(ctx, sandboxID, containerID, signal, all)
|
||||
}
|
||||
|
||||
// ProcessListContainer implements the VC function of the same name.
|
||||
func (impl *VCImpl) ProcessListContainer(sandboxID, containerID string, options ProcessListOptions) (ProcessList, error) {
|
||||
return ProcessListContainer(sandboxID, containerID, options)
|
||||
func (impl *VCImpl) ProcessListContainer(ctx context.Context, sandboxID, containerID string, options ProcessListOptions) (ProcessList, error) {
|
||||
return ProcessListContainer(ctx, sandboxID, containerID, options)
|
||||
}
|
||||
|
||||
// UpdateContainer implements the VC function of the same name.
|
||||
func (impl *VCImpl) UpdateContainer(sandboxID, containerID string, resources specs.LinuxResources) error {
|
||||
return UpdateContainer(sandboxID, containerID, resources)
|
||||
func (impl *VCImpl) UpdateContainer(ctx context.Context, sandboxID, containerID string, resources specs.LinuxResources) error {
|
||||
return UpdateContainer(ctx, sandboxID, containerID, resources)
|
||||
}
|
||||
|
||||
// PauseContainer implements the VC function of the same name.
|
||||
func (impl *VCImpl) PauseContainer(sandboxID, containerID string) error {
|
||||
return PauseContainer(sandboxID, containerID)
|
||||
func (impl *VCImpl) PauseContainer(ctx context.Context, sandboxID, containerID string) error {
|
||||
return PauseContainer(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// ResumeContainer implements the VC function of the same name.
|
||||
func (impl *VCImpl) ResumeContainer(sandboxID, containerID string) error {
|
||||
return ResumeContainer(sandboxID, containerID)
|
||||
func (impl *VCImpl) ResumeContainer(ctx context.Context, sandboxID, containerID string) error {
|
||||
return ResumeContainer(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// AddDevice will add a device to sandbox
|
||||
func (impl *VCImpl) AddDevice(sandboxID string, info config.DeviceInfo) (api.Device, error) {
|
||||
return AddDevice(sandboxID, info)
|
||||
func (impl *VCImpl) AddDevice(ctx context.Context, sandboxID string, info config.DeviceInfo) (api.Device, error) {
|
||||
return AddDevice(ctx, sandboxID, info)
|
||||
}
|
||||
|
||||
// AddInterface implements the VC function of the same name.
|
||||
func (impl *VCImpl) AddInterface(sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
return AddInterface(sandboxID, inf)
|
||||
func (impl *VCImpl) AddInterface(ctx context.Context, sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
return AddInterface(ctx, sandboxID, inf)
|
||||
}
|
||||
|
||||
// RemoveInterface implements the VC function of the same name.
|
||||
func (impl *VCImpl) RemoveInterface(sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
return RemoveInterface(sandboxID, inf)
|
||||
func (impl *VCImpl) RemoveInterface(ctx context.Context, sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
return RemoveInterface(ctx, sandboxID, inf)
|
||||
}
|
||||
|
||||
// ListInterfaces implements the VC function of the same name.
|
||||
func (impl *VCImpl) ListInterfaces(sandboxID string) ([]*grpc.Interface, error) {
|
||||
return ListInterfaces(sandboxID)
|
||||
func (impl *VCImpl) ListInterfaces(ctx context.Context, sandboxID string) ([]*grpc.Interface, error) {
|
||||
return ListInterfaces(ctx, sandboxID)
|
||||
}
|
||||
|
||||
// UpdateRoutes implements the VC function of the same name.
|
||||
func (impl *VCImpl) UpdateRoutes(sandboxID string, routes []*grpc.Route) ([]*grpc.Route, error) {
|
||||
return UpdateRoutes(sandboxID, routes)
|
||||
func (impl *VCImpl) UpdateRoutes(ctx context.Context, sandboxID string, routes []*grpc.Route) ([]*grpc.Route, error) {
|
||||
return UpdateRoutes(ctx, sandboxID, routes)
|
||||
}
|
||||
|
||||
// ListRoutes implements the VC function of the same name.
|
||||
func (impl *VCImpl) ListRoutes(sandboxID string) ([]*grpc.Route, error) {
|
||||
return ListRoutes(sandboxID)
|
||||
func (impl *VCImpl) ListRoutes(ctx context.Context, sandboxID string) ([]*grpc.Route, error) {
|
||||
return ListRoutes(ctx, sandboxID)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
package virtcontainers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"syscall"
|
||||
|
||||
@ -18,40 +19,40 @@ import (
|
||||
|
||||
// VC is the Virtcontainers interface
|
||||
type VC interface {
|
||||
SetLogger(logger *logrus.Entry)
|
||||
SetFactory(Factory)
|
||||
SetLogger(ctx context.Context, logger *logrus.Entry)
|
||||
SetFactory(ctx context.Context, factory Factory)
|
||||
|
||||
CreateSandbox(sandboxConfig SandboxConfig) (VCSandbox, error)
|
||||
DeleteSandbox(sandboxID string) (VCSandbox, error)
|
||||
FetchSandbox(sandboxID string) (VCSandbox, error)
|
||||
ListSandbox() ([]SandboxStatus, error)
|
||||
PauseSandbox(sandboxID string) (VCSandbox, error)
|
||||
ResumeSandbox(sandboxID string) (VCSandbox, error)
|
||||
RunSandbox(sandboxConfig SandboxConfig) (VCSandbox, error)
|
||||
StartSandbox(sandboxID string) (VCSandbox, error)
|
||||
StatusSandbox(sandboxID string) (SandboxStatus, error)
|
||||
StopSandbox(sandboxID string) (VCSandbox, error)
|
||||
CreateSandbox(ctx context.Context, sandboxConfig SandboxConfig) (VCSandbox, error)
|
||||
DeleteSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
|
||||
FetchSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
|
||||
ListSandbox(ctx context.Context) ([]SandboxStatus, error)
|
||||
PauseSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
|
||||
ResumeSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
|
||||
RunSandbox(ctx context.Context, sandboxConfig SandboxConfig) (VCSandbox, error)
|
||||
StartSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
|
||||
StatusSandbox(ctx context.Context, sandboxID string) (SandboxStatus, error)
|
||||
StopSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
|
||||
|
||||
CreateContainer(sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error)
|
||||
DeleteContainer(sandboxID, containerID string) (VCContainer, error)
|
||||
EnterContainer(sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContainer, *Process, error)
|
||||
KillContainer(sandboxID, containerID string, signal syscall.Signal, all bool) error
|
||||
StartContainer(sandboxID, containerID string) (VCContainer, error)
|
||||
StatusContainer(sandboxID, containerID string) (ContainerStatus, error)
|
||||
StatsContainer(sandboxID, containerID string) (ContainerStats, error)
|
||||
StopContainer(sandboxID, containerID string) (VCContainer, error)
|
||||
ProcessListContainer(sandboxID, containerID string, options ProcessListOptions) (ProcessList, error)
|
||||
UpdateContainer(sandboxID, containerID string, resources specs.LinuxResources) error
|
||||
PauseContainer(sandboxID, containerID string) error
|
||||
ResumeContainer(sandboxID, containerID string) error
|
||||
CreateContainer(ctx context.Context, sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error)
|
||||
DeleteContainer(ctx context.Context, sandboxID, containerID string) (VCContainer, error)
|
||||
EnterContainer(ctx context.Context, sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContainer, *Process, error)
|
||||
KillContainer(ctx context.Context, sandboxID, containerID string, signal syscall.Signal, all bool) error
|
||||
StartContainer(ctx context.Context, sandboxID, containerID string) (VCContainer, error)
|
||||
StatusContainer(ctx context.Context, sandboxID, containerID string) (ContainerStatus, error)
|
||||
StatsContainer(ctx context.Context, sandboxID, containerID string) (ContainerStats, error)
|
||||
StopContainer(ctx context.Context, sandboxID, containerID string) (VCContainer, error)
|
||||
ProcessListContainer(ctx context.Context, sandboxID, containerID string, options ProcessListOptions) (ProcessList, error)
|
||||
UpdateContainer(ctx context.Context, sandboxID, containerID string, resources specs.LinuxResources) error
|
||||
PauseContainer(ctx context.Context, sandboxID, containerID string) error
|
||||
ResumeContainer(ctx context.Context, sandboxID, containerID string) error
|
||||
|
||||
AddDevice(sandboxID string, info config.DeviceInfo) (api.Device, error)
|
||||
AddDevice(ctx context.Context, sandboxID string, info config.DeviceInfo) (api.Device, error)
|
||||
|
||||
AddInterface(sandboxID string, inf *grpc.Interface) (*grpc.Interface, error)
|
||||
RemoveInterface(sandboxID string, inf *grpc.Interface) (*grpc.Interface, error)
|
||||
ListInterfaces(sandboxID string) ([]*grpc.Interface, error)
|
||||
UpdateRoutes(sandboxID string, routes []*grpc.Route) ([]*grpc.Route, error)
|
||||
ListRoutes(sandboxID string) ([]*grpc.Route, error)
|
||||
AddInterface(ctx context.Context, sandboxID string, inf *grpc.Interface) (*grpc.Interface, error)
|
||||
RemoveInterface(ctx context.Context, sandboxID string, inf *grpc.Interface) (*grpc.Interface, error)
|
||||
ListInterfaces(ctx context.Context, sandboxID string) ([]*grpc.Interface, error)
|
||||
UpdateRoutes(ctx context.Context, sandboxID string, routes []*grpc.Route) ([]*grpc.Route, error)
|
||||
ListRoutes(ctx context.Context, sandboxID string) ([]*grpc.Route, error)
|
||||
}
|
||||
|
||||
// VCSandbox is the Sandbox interface
|
||||
|
@ -7,6 +7,7 @@
|
||||
package virtcontainers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -14,14 +15,15 @@ func testCreateNoopContainer() (*Sandbox, *Container, error) {
|
||||
contID := "100"
|
||||
config := newTestSandboxConfigNoop()
|
||||
|
||||
p, err := CreateSandbox(config, nil)
|
||||
ctx := context.Background()
|
||||
p, err := CreateSandbox(ctx, config, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
contConfig := newTestContainerConfigNoop(contID)
|
||||
|
||||
p, c, err := CreateContainer(p.ID(), contConfig)
|
||||
p, c, err := CreateContainer(ctx, p.ID(), contConfig)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
package hyperstart
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@ -123,7 +124,7 @@ type Hyperstart struct {
|
||||
var hyperLog = logrus.FieldLogger(logrus.New())
|
||||
|
||||
// SetLogger sets the logger for hyperstart package.
|
||||
func SetLogger(logger logrus.FieldLogger) {
|
||||
func SetLogger(ctx context.Context, logger logrus.FieldLogger) {
|
||||
hyperLog = logger.WithFields(logrus.Fields{
|
||||
"source": "virtcontainers",
|
||||
"subsystem": "hyperstart",
|
||||
|
@ -6,6 +6,7 @@
|
||||
package oci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -134,7 +135,7 @@ var ociLog = logrus.WithFields(logrus.Fields{
|
||||
})
|
||||
|
||||
// SetLogger sets the logger for oci package.
|
||||
func SetLogger(logger *logrus.Entry) {
|
||||
func SetLogger(ctx context.Context, logger *logrus.Entry) {
|
||||
fields := ociLog.Data
|
||||
ociLog = logger.WithFields(fields)
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
package vcmock
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
@ -32,266 +33,266 @@ import (
|
||||
const mockErrorPrefix = "vcmock forced failure"
|
||||
|
||||
// SetLogger implements the VC function of the same name.
|
||||
func (m *VCMock) SetLogger(logger *logrus.Entry) {
|
||||
func (m *VCMock) SetLogger(ctx context.Context, logger *logrus.Entry) {
|
||||
if m.SetLoggerFunc != nil {
|
||||
m.SetLoggerFunc(logger)
|
||||
m.SetLoggerFunc(ctx, logger)
|
||||
}
|
||||
}
|
||||
|
||||
// SetFactory implements the VC function of the same name.
|
||||
func (m *VCMock) SetFactory(factory vc.Factory) {
|
||||
func (m *VCMock) SetFactory(ctx context.Context, factory vc.Factory) {
|
||||
if m.SetFactoryFunc != nil {
|
||||
m.SetFactoryFunc(factory)
|
||||
m.SetFactoryFunc(ctx, factory)
|
||||
}
|
||||
}
|
||||
|
||||
// CreateSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) CreateSandbox(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
func (m *VCMock) CreateSandbox(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
if m.CreateSandboxFunc != nil {
|
||||
return m.CreateSandboxFunc(sandboxConfig)
|
||||
return m.CreateSandboxFunc(ctx, sandboxConfig)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxConfig: %v", mockErrorPrefix, getSelf(), m, sandboxConfig)
|
||||
}
|
||||
|
||||
// DeleteSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) DeleteSandbox(sandboxID string) (vc.VCSandbox, error) {
|
||||
func (m *VCMock) DeleteSandbox(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
if m.DeleteSandboxFunc != nil {
|
||||
return m.DeleteSandboxFunc(sandboxID)
|
||||
return m.DeleteSandboxFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// FetchSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) FetchSandbox(sandboxID string) (vc.VCSandbox, error) {
|
||||
func (m *VCMock) FetchSandbox(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
if m.FetchSandboxFunc != nil {
|
||||
return m.FetchSandboxFunc(sandboxID)
|
||||
return m.FetchSandboxFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// StartSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) StartSandbox(sandboxID string) (vc.VCSandbox, error) {
|
||||
func (m *VCMock) StartSandbox(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
if m.StartSandboxFunc != nil {
|
||||
return m.StartSandboxFunc(sandboxID)
|
||||
return m.StartSandboxFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// StopSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) StopSandbox(sandboxID string) (vc.VCSandbox, error) {
|
||||
func (m *VCMock) StopSandbox(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
if m.StopSandboxFunc != nil {
|
||||
return m.StopSandboxFunc(sandboxID)
|
||||
return m.StopSandboxFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// RunSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) RunSandbox(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
func (m *VCMock) RunSandbox(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
if m.RunSandboxFunc != nil {
|
||||
return m.RunSandboxFunc(sandboxConfig)
|
||||
return m.RunSandboxFunc(ctx, sandboxConfig)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxConfig: %v", mockErrorPrefix, getSelf(), m, sandboxConfig)
|
||||
}
|
||||
|
||||
// ListSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) ListSandbox() ([]vc.SandboxStatus, error) {
|
||||
func (m *VCMock) ListSandbox(ctx context.Context) ([]vc.SandboxStatus, error) {
|
||||
if m.ListSandboxFunc != nil {
|
||||
return m.ListSandboxFunc()
|
||||
return m.ListSandboxFunc(ctx)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s", mockErrorPrefix, getSelf())
|
||||
}
|
||||
|
||||
// StatusSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) StatusSandbox(sandboxID string) (vc.SandboxStatus, error) {
|
||||
func (m *VCMock) StatusSandbox(ctx context.Context, sandboxID string) (vc.SandboxStatus, error) {
|
||||
if m.StatusSandboxFunc != nil {
|
||||
return m.StatusSandboxFunc(sandboxID)
|
||||
return m.StatusSandboxFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return vc.SandboxStatus{}, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// PauseSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) PauseSandbox(sandboxID string) (vc.VCSandbox, error) {
|
||||
func (m *VCMock) PauseSandbox(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
if m.PauseSandboxFunc != nil {
|
||||
return m.PauseSandboxFunc(sandboxID)
|
||||
return m.PauseSandboxFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// ResumeSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) ResumeSandbox(sandboxID string) (vc.VCSandbox, error) {
|
||||
func (m *VCMock) ResumeSandbox(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
if m.ResumeSandboxFunc != nil {
|
||||
return m.ResumeSandboxFunc(sandboxID)
|
||||
return m.ResumeSandboxFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// CreateContainer implements the VC function of the same name.
|
||||
func (m *VCMock) CreateContainer(sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) {
|
||||
func (m *VCMock) CreateContainer(ctx context.Context, sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) {
|
||||
if m.CreateContainerFunc != nil {
|
||||
return m.CreateContainerFunc(sandboxID, containerConfig)
|
||||
return m.CreateContainerFunc(ctx, sandboxID, containerConfig)
|
||||
}
|
||||
|
||||
return nil, nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerConfig: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerConfig)
|
||||
}
|
||||
|
||||
// DeleteContainer implements the VC function of the same name.
|
||||
func (m *VCMock) DeleteContainer(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
func (m *VCMock) DeleteContainer(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
if m.DeleteContainerFunc != nil {
|
||||
return m.DeleteContainerFunc(sandboxID, containerID)
|
||||
return m.DeleteContainerFunc(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// StartContainer implements the VC function of the same name.
|
||||
func (m *VCMock) StartContainer(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
func (m *VCMock) StartContainer(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
if m.StartContainerFunc != nil {
|
||||
return m.StartContainerFunc(sandboxID, containerID)
|
||||
return m.StartContainerFunc(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// StopContainer implements the VC function of the same name.
|
||||
func (m *VCMock) StopContainer(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
func (m *VCMock) StopContainer(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
if m.StopContainerFunc != nil {
|
||||
return m.StopContainerFunc(sandboxID, containerID)
|
||||
return m.StopContainerFunc(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// EnterContainer implements the VC function of the same name.
|
||||
func (m *VCMock) EnterContainer(sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
func (m *VCMock) EnterContainer(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
if m.EnterContainerFunc != nil {
|
||||
return m.EnterContainerFunc(sandboxID, containerID, cmd)
|
||||
return m.EnterContainerFunc(ctx, sandboxID, containerID, cmd)
|
||||
}
|
||||
|
||||
return nil, nil, nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v, cmd: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID, cmd)
|
||||
}
|
||||
|
||||
// StatusContainer implements the VC function of the same name.
|
||||
func (m *VCMock) StatusContainer(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
func (m *VCMock) StatusContainer(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
if m.StatusContainerFunc != nil {
|
||||
return m.StatusContainerFunc(sandboxID, containerID)
|
||||
return m.StatusContainerFunc(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
return vc.ContainerStatus{}, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// StatsContainer implements the VC function of the same name.
|
||||
func (m *VCMock) StatsContainer(sandboxID, containerID string) (vc.ContainerStats, error) {
|
||||
func (m *VCMock) StatsContainer(ctx context.Context, sandboxID, containerID string) (vc.ContainerStats, error) {
|
||||
if m.StatsContainerFunc != nil {
|
||||
return m.StatsContainerFunc(sandboxID, containerID)
|
||||
return m.StatsContainerFunc(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
return vc.ContainerStats{}, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// KillContainer implements the VC function of the same name.
|
||||
func (m *VCMock) KillContainer(sandboxID, containerID string, signal syscall.Signal, all bool) error {
|
||||
func (m *VCMock) KillContainer(ctx context.Context, sandboxID, containerID string, signal syscall.Signal, all bool) error {
|
||||
if m.KillContainerFunc != nil {
|
||||
return m.KillContainerFunc(sandboxID, containerID, signal, all)
|
||||
return m.KillContainerFunc(ctx, sandboxID, containerID, signal, all)
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v, signal: %v, all: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID, signal, all)
|
||||
}
|
||||
|
||||
// ProcessListContainer implements the VC function of the same name.
|
||||
func (m *VCMock) ProcessListContainer(sandboxID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) {
|
||||
func (m *VCMock) ProcessListContainer(ctx context.Context, sandboxID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) {
|
||||
if m.ProcessListContainerFunc != nil {
|
||||
return m.ProcessListContainerFunc(sandboxID, containerID, options)
|
||||
return m.ProcessListContainerFunc(ctx, sandboxID, containerID, options)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// UpdateContainer implements the VC function of the same name.
|
||||
func (m *VCMock) UpdateContainer(sandboxID, containerID string, resources specs.LinuxResources) error {
|
||||
func (m *VCMock) UpdateContainer(ctx context.Context, sandboxID, containerID string, resources specs.LinuxResources) error {
|
||||
if m.UpdateContainerFunc != nil {
|
||||
return m.UpdateContainerFunc(sandboxID, containerID, resources)
|
||||
return m.UpdateContainerFunc(ctx, sandboxID, containerID, resources)
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// PauseContainer implements the VC function of the same name.
|
||||
func (m *VCMock) PauseContainer(sandboxID, containerID string) error {
|
||||
func (m *VCMock) PauseContainer(ctx context.Context, sandboxID, containerID string) error {
|
||||
if m.PauseContainerFunc != nil {
|
||||
return m.PauseContainerFunc(sandboxID, containerID)
|
||||
return m.PauseContainerFunc(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// ResumeContainer implements the VC function of the same name.
|
||||
func (m *VCMock) ResumeContainer(sandboxID, containerID string) error {
|
||||
func (m *VCMock) ResumeContainer(ctx context.Context, sandboxID, containerID string) error {
|
||||
if m.ResumeContainerFunc != nil {
|
||||
return m.ResumeContainerFunc(sandboxID, containerID)
|
||||
return m.ResumeContainerFunc(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// AddDevice implements the VC function of the same name.
|
||||
func (m *VCMock) AddDevice(sandboxID string, info config.DeviceInfo) (api.Device, error) {
|
||||
func (m *VCMock) AddDevice(ctx context.Context, sandboxID string, info config.DeviceInfo) (api.Device, error) {
|
||||
if m.AddDeviceFunc != nil {
|
||||
return m.AddDeviceFunc(sandboxID, info)
|
||||
return m.AddDeviceFunc(ctx, sandboxID, info)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// AddInterface implements the VC function of the same name.
|
||||
func (m *VCMock) AddInterface(sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
func (m *VCMock) AddInterface(ctx context.Context, sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
if m.AddInterfaceFunc != nil {
|
||||
return m.AddInterfaceFunc(sandboxID, inf)
|
||||
return m.AddInterfaceFunc(ctx, sandboxID, inf)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// RemoveInterface implements the VC function of the same name.
|
||||
func (m *VCMock) RemoveInterface(sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
func (m *VCMock) RemoveInterface(ctx context.Context, sandboxID string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
if m.RemoveInterfaceFunc != nil {
|
||||
return m.RemoveInterfaceFunc(sandboxID, inf)
|
||||
return m.RemoveInterfaceFunc(ctx, sandboxID, inf)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// ListInterfaces implements the VC function of the same name.
|
||||
func (m *VCMock) ListInterfaces(sandboxID string) ([]*grpc.Interface, error) {
|
||||
func (m *VCMock) ListInterfaces(ctx context.Context, sandboxID string) ([]*grpc.Interface, error) {
|
||||
if m.ListInterfacesFunc != nil {
|
||||
return m.ListInterfacesFunc(sandboxID)
|
||||
return m.ListInterfacesFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// UpdateRoutes implements the VC function of the same name.
|
||||
func (m *VCMock) UpdateRoutes(sandboxID string, routes []*grpc.Route) ([]*grpc.Route, error) {
|
||||
func (m *VCMock) UpdateRoutes(ctx context.Context, sandboxID string, routes []*grpc.Route) ([]*grpc.Route, error) {
|
||||
if m.UpdateRoutesFunc != nil {
|
||||
return m.UpdateRoutesFunc(sandboxID, routes)
|
||||
return m.UpdateRoutesFunc(ctx, sandboxID, routes)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// ListRoutes implements the VC function of the same name.
|
||||
func (m *VCMock) ListRoutes(sandboxID string) ([]*grpc.Route, error) {
|
||||
func (m *VCMock) ListRoutes(ctx context.Context, sandboxID string) ([]*grpc.Route, error) {
|
||||
if m.ListRoutesFunc != nil {
|
||||
return m.ListRoutesFunc(sandboxID)
|
||||
return m.ListRoutesFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
|
@ -6,6 +6,7 @@
|
||||
package vcmock
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"syscall"
|
||||
"testing"
|
||||
@ -102,14 +103,15 @@ func TestVCMockSetLogger(t *testing.T) {
|
||||
logger := logrus.NewEntry(logrus.New())
|
||||
|
||||
assert.Equal(loggerTriggered, 0)
|
||||
m.SetLogger(logger)
|
||||
ctx := context.Background()
|
||||
m.SetLogger(ctx, logger)
|
||||
assert.Equal(loggerTriggered, 0)
|
||||
|
||||
m.SetLoggerFunc = func(logger logrus.FieldLogger) {
|
||||
m.SetLoggerFunc = func(ctx context.Context, logger *logrus.Entry) {
|
||||
loggerTriggered = 1
|
||||
}
|
||||
|
||||
m.SetLogger(logger)
|
||||
m.SetLogger(ctx, logger)
|
||||
assert.Equal(loggerTriggered, 1)
|
||||
}
|
||||
|
||||
@ -119,22 +121,23 @@ func TestVCMockCreateSandbox(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.CreateSandboxFunc)
|
||||
|
||||
_, err := m.CreateSandbox(vc.SandboxConfig{})
|
||||
ctx := context.Background()
|
||||
_, err := m.CreateSandbox(ctx, vc.SandboxConfig{})
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
m.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
return &Sandbox{}, nil
|
||||
}
|
||||
|
||||
sandbox, err := m.CreateSandbox(vc.SandboxConfig{})
|
||||
sandbox, err := m.CreateSandbox(ctx, vc.SandboxConfig{})
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
|
||||
// reset
|
||||
m.CreateSandboxFunc = nil
|
||||
|
||||
_, err = m.CreateSandbox(vc.SandboxConfig{})
|
||||
_, err = m.CreateSandbox(ctx, vc.SandboxConfig{})
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -145,22 +148,23 @@ func TestVCMockDeleteSandbox(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.DeleteSandboxFunc)
|
||||
|
||||
_, err := m.DeleteSandbox(testSandboxID)
|
||||
ctx := context.Background()
|
||||
_, err := m.DeleteSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.DeleteSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
m.DeleteSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return &Sandbox{}, nil
|
||||
}
|
||||
|
||||
sandbox, err := m.DeleteSandbox(testSandboxID)
|
||||
sandbox, err := m.DeleteSandbox(ctx, testSandboxID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
|
||||
// reset
|
||||
m.DeleteSandboxFunc = nil
|
||||
|
||||
_, err = m.DeleteSandbox(testSandboxID)
|
||||
_, err = m.DeleteSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -171,22 +175,23 @@ func TestVCMockListSandbox(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.ListSandboxFunc)
|
||||
|
||||
_, err := m.ListSandbox()
|
||||
ctx := context.Background()
|
||||
_, err := m.ListSandbox(ctx)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
||||
m.ListSandboxFunc = func(ctx context.Context) ([]vc.SandboxStatus, error) {
|
||||
return []vc.SandboxStatus{}, nil
|
||||
}
|
||||
|
||||
sandboxes, err := m.ListSandbox()
|
||||
sandboxes, err := m.ListSandbox(ctx)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandboxes, []vc.SandboxStatus{})
|
||||
|
||||
// reset
|
||||
m.ListSandboxFunc = nil
|
||||
|
||||
_, err = m.ListSandbox()
|
||||
_, err = m.ListSandbox(ctx)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -197,22 +202,23 @@ func TestVCMockPauseSandbox(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.PauseSandboxFunc)
|
||||
|
||||
_, err := m.PauseSandbox(testSandboxID)
|
||||
ctx := context.Background()
|
||||
_, err := m.PauseSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.PauseSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
m.PauseSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return &Sandbox{}, nil
|
||||
}
|
||||
|
||||
sandbox, err := m.PauseSandbox(testSandboxID)
|
||||
sandbox, err := m.PauseSandbox(ctx, testSandboxID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
|
||||
// reset
|
||||
m.PauseSandboxFunc = nil
|
||||
|
||||
_, err = m.PauseSandbox(testSandboxID)
|
||||
_, err = m.PauseSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -223,22 +229,23 @@ func TestVCMockResumeSandbox(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.ResumeSandboxFunc)
|
||||
|
||||
_, err := m.ResumeSandbox(testSandboxID)
|
||||
ctx := context.Background()
|
||||
_, err := m.ResumeSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.ResumeSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
m.ResumeSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return &Sandbox{}, nil
|
||||
}
|
||||
|
||||
sandbox, err := m.ResumeSandbox(testSandboxID)
|
||||
sandbox, err := m.ResumeSandbox(ctx, testSandboxID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
|
||||
// reset
|
||||
m.ResumeSandboxFunc = nil
|
||||
|
||||
_, err = m.ResumeSandbox(testSandboxID)
|
||||
_, err = m.ResumeSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -249,22 +256,23 @@ func TestVCMockRunSandbox(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.RunSandboxFunc)
|
||||
|
||||
_, err := m.RunSandbox(vc.SandboxConfig{})
|
||||
ctx := context.Background()
|
||||
_, err := m.RunSandbox(ctx, vc.SandboxConfig{})
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.RunSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
m.RunSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
return &Sandbox{}, nil
|
||||
}
|
||||
|
||||
sandbox, err := m.RunSandbox(vc.SandboxConfig{})
|
||||
sandbox, err := m.RunSandbox(ctx, vc.SandboxConfig{})
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
|
||||
// reset
|
||||
m.RunSandboxFunc = nil
|
||||
|
||||
_, err = m.RunSandbox(vc.SandboxConfig{})
|
||||
_, err = m.RunSandbox(ctx, vc.SandboxConfig{})
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -275,22 +283,23 @@ func TestVCMockStartSandbox(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.StartSandboxFunc)
|
||||
|
||||
_, err := m.StartSandbox(testSandboxID)
|
||||
ctx := context.Background()
|
||||
_, err := m.StartSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.StartSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
m.StartSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return &Sandbox{}, nil
|
||||
}
|
||||
|
||||
sandbox, err := m.StartSandbox(testSandboxID)
|
||||
sandbox, err := m.StartSandbox(ctx, testSandboxID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
|
||||
// reset
|
||||
m.StartSandboxFunc = nil
|
||||
|
||||
_, err = m.StartSandbox(testSandboxID)
|
||||
_, err = m.StartSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -301,22 +310,23 @@ func TestVCMockStatusSandbox(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.StatusSandboxFunc)
|
||||
|
||||
_, err := m.StatusSandbox(testSandboxID)
|
||||
ctx := context.Background()
|
||||
_, err := m.StatusSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.StatusSandboxFunc = func(sandboxID string) (vc.SandboxStatus, error) {
|
||||
m.StatusSandboxFunc = func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error) {
|
||||
return vc.SandboxStatus{}, nil
|
||||
}
|
||||
|
||||
sandbox, err := m.StatusSandbox(testSandboxID)
|
||||
sandbox, err := m.StatusSandbox(ctx, testSandboxID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, vc.SandboxStatus{})
|
||||
|
||||
// reset
|
||||
m.StatusSandboxFunc = nil
|
||||
|
||||
_, err = m.StatusSandbox(testSandboxID)
|
||||
_, err = m.StatusSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -327,22 +337,23 @@ func TestVCMockStopSandbox(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.StopSandboxFunc)
|
||||
|
||||
_, err := m.StopSandbox(testSandboxID)
|
||||
ctx := context.Background()
|
||||
_, err := m.StopSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.StopSandboxFunc = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
m.StopSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return &Sandbox{}, nil
|
||||
}
|
||||
|
||||
sandbox, err := m.StopSandbox(testSandboxID)
|
||||
sandbox, err := m.StopSandbox(ctx, testSandboxID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
|
||||
// reset
|
||||
m.StopSandboxFunc = nil
|
||||
|
||||
_, err = m.StopSandbox(testSandboxID)
|
||||
_, err = m.StopSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -353,16 +364,17 @@ func TestVCMockCreateContainer(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.CreateContainerFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
config := vc.ContainerConfig{}
|
||||
_, _, err := m.CreateContainer(testSandboxID, config)
|
||||
_, _, err := m.CreateContainer(ctx, testSandboxID, config)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.CreateContainerFunc = func(sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) {
|
||||
m.CreateContainerFunc = func(ctx context.Context, sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) {
|
||||
return &Sandbox{}, &Container{}, nil
|
||||
}
|
||||
|
||||
sandbox, container, err := m.CreateContainer(testSandboxID, config)
|
||||
sandbox, container, err := m.CreateContainer(ctx, testSandboxID, config)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
assert.Equal(container, &Container{})
|
||||
@ -370,7 +382,7 @@ func TestVCMockCreateContainer(t *testing.T) {
|
||||
// reset
|
||||
m.CreateContainerFunc = nil
|
||||
|
||||
_, _, err = m.CreateContainer(testSandboxID, config)
|
||||
_, _, err = m.CreateContainer(ctx, testSandboxID, config)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -381,22 +393,23 @@ func TestVCMockDeleteContainer(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.DeleteContainerFunc)
|
||||
|
||||
_, err := m.DeleteContainer(testSandboxID, testContainerID)
|
||||
ctx := context.Background()
|
||||
_, err := m.DeleteContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.DeleteContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
m.DeleteContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
return &Container{}, nil
|
||||
}
|
||||
|
||||
container, err := m.DeleteContainer(testSandboxID, testContainerID)
|
||||
container, err := m.DeleteContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(container, &Container{})
|
||||
|
||||
// reset
|
||||
m.DeleteContainerFunc = nil
|
||||
|
||||
_, err = m.DeleteContainer(testSandboxID, testContainerID)
|
||||
_, err = m.DeleteContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -407,16 +420,17 @@ func TestVCMockEnterContainer(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.EnterContainerFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
cmd := vc.Cmd{}
|
||||
_, _, _, err := m.EnterContainer(testSandboxID, testContainerID, cmd)
|
||||
_, _, _, err := m.EnterContainer(ctx, testSandboxID, testContainerID, cmd)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.EnterContainerFunc = func(sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
m.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
return &Sandbox{}, &Container{}, &vc.Process{}, nil
|
||||
}
|
||||
|
||||
sandbox, container, process, err := m.EnterContainer(testSandboxID, testContainerID, cmd)
|
||||
sandbox, container, process, err := m.EnterContainer(ctx, testSandboxID, testContainerID, cmd)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
assert.Equal(container, &Container{})
|
||||
@ -425,7 +439,7 @@ func TestVCMockEnterContainer(t *testing.T) {
|
||||
// reset
|
||||
m.EnterContainerFunc = nil
|
||||
|
||||
_, _, _, err = m.EnterContainer(testSandboxID, testContainerID, cmd)
|
||||
_, _, _, err = m.EnterContainer(ctx, testSandboxID, testContainerID, cmd)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -436,20 +450,21 @@ func TestVCMockKillContainer(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.KillContainerFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
sig := syscall.SIGTERM
|
||||
|
||||
for _, all := range []bool{true, false} {
|
||||
err := m.KillContainer(testSandboxID, testContainerID, sig, all)
|
||||
err := m.KillContainer(ctx, testSandboxID, testContainerID, sig, all)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
m.KillContainerFunc = func(sandboxID, containerID string, signal syscall.Signal, all bool) error {
|
||||
m.KillContainerFunc = func(ctx context.Context, sandboxID, containerID string, signal syscall.Signal, all bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, all := range []bool{true, false} {
|
||||
err := m.KillContainer(testSandboxID, testContainerID, sig, all)
|
||||
err := m.KillContainer(ctx, testSandboxID, testContainerID, sig, all)
|
||||
assert.NoError(err)
|
||||
}
|
||||
|
||||
@ -457,7 +472,7 @@ func TestVCMockKillContainer(t *testing.T) {
|
||||
m.KillContainerFunc = nil
|
||||
|
||||
for _, all := range []bool{true, false} {
|
||||
err := m.KillContainer(testSandboxID, testContainerID, sig, all)
|
||||
err := m.KillContainer(ctx, testSandboxID, testContainerID, sig, all)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -469,22 +484,23 @@ func TestVCMockStartContainer(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.StartContainerFunc)
|
||||
|
||||
_, err := m.StartContainer(testSandboxID, testContainerID)
|
||||
ctx := context.Background()
|
||||
_, err := m.StartContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.StartContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
m.StartContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
return &Container{}, nil
|
||||
}
|
||||
|
||||
container, err := m.StartContainer(testSandboxID, testContainerID)
|
||||
container, err := m.StartContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(container, &Container{})
|
||||
|
||||
// reset
|
||||
m.StartContainerFunc = nil
|
||||
|
||||
_, err = m.StartContainer(testSandboxID, testContainerID)
|
||||
_, err = m.StartContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -495,22 +511,23 @@ func TestVCMockStatusContainer(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.StatusContainerFunc)
|
||||
|
||||
_, err := m.StatusContainer(testSandboxID, testContainerID)
|
||||
ctx := context.Background()
|
||||
_, err := m.StatusContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
m.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{}, nil
|
||||
}
|
||||
|
||||
status, err := m.StatusContainer(testSandboxID, testContainerID)
|
||||
status, err := m.StatusContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(status, vc.ContainerStatus{})
|
||||
|
||||
// reset
|
||||
m.StatusContainerFunc = nil
|
||||
|
||||
_, err = m.StatusContainer(testSandboxID, testContainerID)
|
||||
_, err = m.StatusContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -521,23 +538,24 @@ func TestVCMockStatsContainer(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.StatsContainerFunc)
|
||||
|
||||
_, err := m.StatsContainer(testSandboxID, testContainerID)
|
||||
ctx := context.Background()
|
||||
_, err := m.StatsContainer(ctx, testSandboxID, testContainerID)
|
||||
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.StatsContainerFunc = func(sandboxID, containerID string) (vc.ContainerStats, error) {
|
||||
m.StatsContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStats, error) {
|
||||
return vc.ContainerStats{}, nil
|
||||
}
|
||||
|
||||
stats, err := m.StatsContainer(testSandboxID, testContainerID)
|
||||
stats, err := m.StatsContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(stats, vc.ContainerStats{})
|
||||
|
||||
// reset
|
||||
m.StatsContainerFunc = nil
|
||||
|
||||
_, err = m.StatsContainer(testSandboxID, testContainerID)
|
||||
_, err = m.StatsContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -548,22 +566,23 @@ func TestVCMockStopContainer(t *testing.T) {
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.StopContainerFunc)
|
||||
|
||||
_, err := m.StopContainer(testSandboxID, testContainerID)
|
||||
ctx := context.Background()
|
||||
_, err := m.StopContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.StopContainerFunc = func(sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
m.StopContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
return &Container{}, nil
|
||||
}
|
||||
|
||||
container, err := m.StopContainer(testSandboxID, testContainerID)
|
||||
container, err := m.StopContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(container, &Container{})
|
||||
|
||||
// reset
|
||||
m.StopContainerFunc = nil
|
||||
|
||||
_, err = m.StopContainer(testSandboxID, testContainerID)
|
||||
_, err = m.StopContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -579,24 +598,25 @@ func TestVCMockProcessListContainer(t *testing.T) {
|
||||
Args: []string{"-ef"},
|
||||
}
|
||||
|
||||
_, err := m.ProcessListContainer(testSandboxID, testContainerID, options)
|
||||
ctx := context.Background()
|
||||
_, err := m.ProcessListContainer(ctx, testSandboxID, testContainerID, options)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
processList := vc.ProcessList("hi")
|
||||
|
||||
m.ProcessListContainerFunc = func(sandboxID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) {
|
||||
m.ProcessListContainerFunc = func(ctx context.Context, sandboxID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) {
|
||||
return processList, nil
|
||||
}
|
||||
|
||||
pList, err := m.ProcessListContainer(testSandboxID, testContainerID, options)
|
||||
pList, err := m.ProcessListContainer(ctx, testSandboxID, testContainerID, options)
|
||||
assert.NoError(err)
|
||||
assert.Equal(pList, processList)
|
||||
|
||||
// reset
|
||||
m.ProcessListContainerFunc = nil
|
||||
|
||||
_, err = m.ProcessListContainer(testSandboxID, testContainerID, options)
|
||||
_, err = m.ProcessListContainer(ctx, testSandboxID, testContainerID, options)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -608,22 +628,23 @@ func TestVCMockFetchSandbox(t *testing.T) {
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.FetchSandboxFunc)
|
||||
|
||||
_, err := m.FetchSandbox(config.ID)
|
||||
ctx := context.Background()
|
||||
_, err := m.FetchSandbox(ctx, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.FetchSandboxFunc = func(id string) (vc.VCSandbox, error) {
|
||||
m.FetchSandboxFunc = func(ctx context.Context, id string) (vc.VCSandbox, error) {
|
||||
return &Sandbox{}, nil
|
||||
}
|
||||
|
||||
sandbox, err := m.FetchSandbox(config.ID)
|
||||
sandbox, err := m.FetchSandbox(ctx, config.ID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
|
||||
// reset
|
||||
m.FetchSandboxFunc = nil
|
||||
|
||||
_, err = m.FetchSandbox(config.ID)
|
||||
_, err = m.FetchSandbox(ctx, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
@ -636,21 +657,22 @@ func TestVCMockPauseContainer(t *testing.T) {
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.PauseContainerFunc)
|
||||
|
||||
err := m.PauseContainer(config.ID, config.ID)
|
||||
ctx := context.Background()
|
||||
err := m.PauseContainer(ctx, config.ID, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.PauseContainerFunc = func(sid, cid string) error {
|
||||
m.PauseContainerFunc = func(ctx context.Context, sid, cid string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
err = m.PauseContainer(config.ID, config.ID)
|
||||
err = m.PauseContainer(ctx, config.ID, config.ID)
|
||||
assert.NoError(err)
|
||||
|
||||
// reset
|
||||
m.PauseContainerFunc = nil
|
||||
|
||||
err = m.PauseContainer(config.ID, config.ID)
|
||||
err = m.PauseContainer(ctx, config.ID, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -662,21 +684,22 @@ func TestVCMockResumeContainer(t *testing.T) {
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.ResumeContainerFunc)
|
||||
|
||||
err := m.ResumeContainer(config.ID, config.ID)
|
||||
ctx := context.Background()
|
||||
err := m.ResumeContainer(ctx, config.ID, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.ResumeContainerFunc = func(sid, cid string) error {
|
||||
m.ResumeContainerFunc = func(ctx context.Context, sid, cid string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
err = m.ResumeContainer(config.ID, config.ID)
|
||||
err = m.ResumeContainer(ctx, config.ID, config.ID)
|
||||
assert.NoError(err)
|
||||
|
||||
// reset
|
||||
m.ResumeContainerFunc = nil
|
||||
|
||||
err = m.ResumeContainer(config.ID, config.ID)
|
||||
err = m.ResumeContainer(ctx, config.ID, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -697,18 +720,19 @@ func TestVCMockSetVMFactory(t *testing.T) {
|
||||
HypervisorConfig: hyperConfig,
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
f, err := factory.NewFactory(factory.Config{VMConfig: vmConfig}, false)
|
||||
assert.Nil(err)
|
||||
|
||||
assert.Equal(factoryTriggered, 0)
|
||||
m.SetFactory(f)
|
||||
m.SetFactory(ctx, f)
|
||||
assert.Equal(factoryTriggered, 0)
|
||||
|
||||
m.SetFactoryFunc = func(factory vc.Factory) {
|
||||
m.SetFactoryFunc = func(ctx context.Context, factory vc.Factory) {
|
||||
factoryTriggered = 1
|
||||
}
|
||||
|
||||
m.SetFactory(f)
|
||||
m.SetFactory(ctx, f)
|
||||
assert.Equal(factoryTriggered, 1)
|
||||
}
|
||||
|
||||
@ -719,21 +743,22 @@ func TestVCMockAddInterface(t *testing.T) {
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.AddInterfaceFunc)
|
||||
|
||||
_, err := m.AddInterface(config.ID, nil)
|
||||
ctx := context.Background()
|
||||
_, err := m.AddInterface(ctx, config.ID, nil)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.AddInterfaceFunc = func(sid string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
m.AddInterfaceFunc = func(ctx context.Context, sid string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
_, err = m.AddInterface(config.ID, nil)
|
||||
_, err = m.AddInterface(ctx, config.ID, nil)
|
||||
assert.NoError(err)
|
||||
|
||||
// reset
|
||||
m.AddInterfaceFunc = nil
|
||||
|
||||
_, err = m.AddInterface(config.ID, nil)
|
||||
_, err = m.AddInterface(ctx, config.ID, nil)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -745,21 +770,22 @@ func TestVCMockRemoveInterface(t *testing.T) {
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.RemoveInterfaceFunc)
|
||||
|
||||
_, err := m.RemoveInterface(config.ID, nil)
|
||||
ctx := context.Background()
|
||||
_, err := m.RemoveInterface(ctx, config.ID, nil)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.RemoveInterfaceFunc = func(sid string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
m.RemoveInterfaceFunc = func(ctx context.Context, sid string, inf *grpc.Interface) (*grpc.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
_, err = m.RemoveInterface(config.ID, nil)
|
||||
_, err = m.RemoveInterface(ctx, config.ID, nil)
|
||||
assert.NoError(err)
|
||||
|
||||
// reset
|
||||
m.RemoveInterfaceFunc = nil
|
||||
|
||||
_, err = m.RemoveInterface(config.ID, nil)
|
||||
_, err = m.RemoveInterface(ctx, config.ID, nil)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -771,21 +797,22 @@ func TestVCMockListInterfaces(t *testing.T) {
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.ListInterfacesFunc)
|
||||
|
||||
_, err := m.ListInterfaces(config.ID)
|
||||
ctx := context.Background()
|
||||
_, err := m.ListInterfaces(ctx, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.ListInterfacesFunc = func(sid string) ([]*grpc.Interface, error) {
|
||||
m.ListInterfacesFunc = func(ctx context.Context, sid string) ([]*grpc.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
_, err = m.ListInterfaces(config.ID)
|
||||
_, err = m.ListInterfaces(ctx, config.ID)
|
||||
assert.NoError(err)
|
||||
|
||||
// reset
|
||||
m.ListInterfacesFunc = nil
|
||||
|
||||
_, err = m.ListInterfaces(config.ID)
|
||||
_, err = m.ListInterfaces(ctx, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -797,21 +824,22 @@ func TestVCMockUpdateRoutes(t *testing.T) {
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.UpdateRoutesFunc)
|
||||
|
||||
_, err := m.UpdateRoutes(config.ID, nil)
|
||||
ctx := context.Background()
|
||||
_, err := m.UpdateRoutes(ctx, config.ID, nil)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.UpdateRoutesFunc = func(sid string, routes []*grpc.Route) ([]*grpc.Route, error) {
|
||||
m.UpdateRoutesFunc = func(ctx context.Context, sid string, routes []*grpc.Route) ([]*grpc.Route, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
_, err = m.UpdateRoutes(config.ID, nil)
|
||||
_, err = m.UpdateRoutes(ctx, config.ID, nil)
|
||||
assert.NoError(err)
|
||||
|
||||
// reset
|
||||
m.UpdateRoutesFunc = nil
|
||||
|
||||
_, err = m.UpdateRoutes(config.ID, nil)
|
||||
_, err = m.UpdateRoutes(ctx, config.ID, nil)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
@ -823,21 +851,22 @@ func TestVCMockListRoutes(t *testing.T) {
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.ListRoutesFunc)
|
||||
|
||||
_, err := m.ListRoutes(config.ID)
|
||||
ctx := context.Background()
|
||||
_, err := m.ListRoutes(ctx, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.ListRoutesFunc = func(sid string) ([]*grpc.Route, error) {
|
||||
m.ListRoutesFunc = func(ctx context.Context, sid string) ([]*grpc.Route, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
_, err = m.ListRoutes(config.ID)
|
||||
_, err = m.ListRoutes(ctx, config.ID)
|
||||
assert.NoError(err)
|
||||
|
||||
// reset
|
||||
m.ListRoutesFunc = nil
|
||||
|
||||
_, err = m.ListRoutes(config.ID)
|
||||
_, err = m.ListRoutes(ctx, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
package vcmock
|
||||
|
||||
import (
|
||||
"context"
|
||||
"syscall"
|
||||
|
||||
"github.com/kata-containers/agent/protocols/grpc"
|
||||
@ -38,38 +39,38 @@ type Container struct {
|
||||
// VCMock is a type that provides an implementation of the VC interface.
|
||||
// It is used for testing.
|
||||
type VCMock struct {
|
||||
SetLoggerFunc func(logger logrus.FieldLogger)
|
||||
SetFactoryFunc func(factory vc.Factory)
|
||||
SetLoggerFunc func(ctx context.Context, logger *logrus.Entry)
|
||||
SetFactoryFunc func(ctx context.Context, factory vc.Factory)
|
||||
|
||||
CreateSandboxFunc func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error)
|
||||
DeleteSandboxFunc func(sandboxID string) (vc.VCSandbox, error)
|
||||
ListSandboxFunc func() ([]vc.SandboxStatus, error)
|
||||
FetchSandboxFunc func(sandboxID string) (vc.VCSandbox, error)
|
||||
PauseSandboxFunc func(sandboxID string) (vc.VCSandbox, error)
|
||||
ResumeSandboxFunc func(sandboxID string) (vc.VCSandbox, error)
|
||||
RunSandboxFunc func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error)
|
||||
StartSandboxFunc func(sandboxID string) (vc.VCSandbox, error)
|
||||
StatusSandboxFunc func(sandboxID string) (vc.SandboxStatus, error)
|
||||
StatsContainerFunc func(sandboxID, containerID string) (vc.ContainerStats, error)
|
||||
StopSandboxFunc func(sandboxID string) (vc.VCSandbox, error)
|
||||
CreateSandboxFunc func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error)
|
||||
DeleteSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
||||
ListSandboxFunc func(ctx context.Context) ([]vc.SandboxStatus, error)
|
||||
FetchSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
||||
PauseSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
||||
ResumeSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
||||
RunSandboxFunc func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error)
|
||||
StartSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
||||
StatusSandboxFunc func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error)
|
||||
StatsContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStats, error)
|
||||
StopSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
||||
|
||||
CreateContainerFunc func(sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error)
|
||||
DeleteContainerFunc func(sandboxID, containerID string) (vc.VCContainer, error)
|
||||
EnterContainerFunc func(sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error)
|
||||
KillContainerFunc func(sandboxID, containerID string, signal syscall.Signal, all bool) error
|
||||
StartContainerFunc func(sandboxID, containerID string) (vc.VCContainer, error)
|
||||
StatusContainerFunc func(sandboxID, containerID string) (vc.ContainerStatus, error)
|
||||
StopContainerFunc func(sandboxID, containerID string) (vc.VCContainer, error)
|
||||
ProcessListContainerFunc func(sandboxID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error)
|
||||
UpdateContainerFunc func(sandboxID, containerID string, resources specs.LinuxResources) error
|
||||
PauseContainerFunc func(sandboxID, containerID string) error
|
||||
ResumeContainerFunc func(sandboxID, containerID string) error
|
||||
CreateContainerFunc func(ctx context.Context, sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error)
|
||||
DeleteContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error)
|
||||
EnterContainerFunc func(ctx context.Context, sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error)
|
||||
KillContainerFunc func(ctx context.Context, sandboxID, containerID string, signal syscall.Signal, all bool) error
|
||||
StartContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error)
|
||||
StatusContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error)
|
||||
StopContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error)
|
||||
ProcessListContainerFunc func(ctx context.Context, sandboxID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error)
|
||||
UpdateContainerFunc func(ctx context.Context, sandboxID, containerID string, resources specs.LinuxResources) error
|
||||
PauseContainerFunc func(ctx context.Context, sandboxID, containerID string) error
|
||||
ResumeContainerFunc func(ctx context.Context, sandboxID, containerID string) error
|
||||
|
||||
AddDeviceFunc func(sandboxID string, info config.DeviceInfo) (api.Device, error)
|
||||
AddDeviceFunc func(ctx context.Context, sandboxID string, info config.DeviceInfo) (api.Device, error)
|
||||
|
||||
AddInterfaceFunc func(sandboxID string, inf *grpc.Interface) (*grpc.Interface, error)
|
||||
RemoveInterfaceFunc func(sandboxID string, inf *grpc.Interface) (*grpc.Interface, error)
|
||||
ListInterfacesFunc func(sandboxID string) ([]*grpc.Interface, error)
|
||||
UpdateRoutesFunc func(sandboxID string, routes []*grpc.Route) ([]*grpc.Route, error)
|
||||
ListRoutesFunc func(sandboxID string) ([]*grpc.Route, error)
|
||||
AddInterfaceFunc func(ctx context.Context, sandboxID string, inf *grpc.Interface) (*grpc.Interface, error)
|
||||
RemoveInterfaceFunc func(ctx context.Context, sandboxID string, inf *grpc.Interface) (*grpc.Interface, error)
|
||||
ListInterfacesFunc func(ctx context.Context, sandboxID string) ([]*grpc.Interface, error)
|
||||
UpdateRoutesFunc func(ctx context.Context, sandboxID string, routes []*grpc.Route) ([]*grpc.Route, error)
|
||||
ListRoutesFunc func(ctx context.Context, sandboxID string) ([]*grpc.Route, error)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
package virtcontainers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@ -73,7 +74,7 @@ func TestMain(m *testing.M) {
|
||||
logger.Logger.Level = logrus.DebugLevel
|
||||
}
|
||||
}
|
||||
SetLogger(logger)
|
||||
SetLogger(context.Background(), logger)
|
||||
|
||||
testDir, err = ioutil.TempDir("", "vc-tmp-")
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user