mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 15:57:09 +00:00
cli: fix pause-remove container
Instead of pausing the sanbox, this patch just pauses the container allowing the communication with the agent. The communication with the agent should be still possible even if all containers are paused, because of we don't know when a new container can be created in the same sandbox. Depends-on: github.com/kata-containers/agent#246 fixes #317 Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
parent
b99cadb553
commit
df05b2c5bd
@ -103,9 +103,9 @@ func kill(containerID, signal string, all bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// container MUST be created or running
|
||||
if status.State.State != vc.StateReady && status.State.State != vc.StateRunning {
|
||||
return fmt.Errorf("Container %s not ready or running, cannot send a signal", containerID)
|
||||
// container MUST be created, running or paused
|
||||
if status.State.State != vc.StateReady && status.State.State != vc.StateRunning && status.State.State != vc.StatePaused {
|
||||
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 {
|
||||
|
@ -312,7 +312,7 @@ func TestKillCLIFunctionInvalidSignalFailure(t *testing.T) {
|
||||
execCLICommandFunc(assert, killCLICommand, set, true)
|
||||
}
|
||||
|
||||
func TestKillCLIFunctionInvalidStatePausedFailure(t *testing.T) {
|
||||
func TestKillCLIFunctionStatePausedSuccessful(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
state := vc.State{
|
||||
@ -320,24 +320,27 @@ func TestKillCLIFunctionInvalidStatePausedFailure(t *testing.T) {
|
||||
}
|
||||
|
||||
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
|
||||
testingImpl.StopContainerFunc = testStopContainerFuncReturnNil
|
||||
|
||||
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||
return newSingleContainerStatus(testContainerID, state,
|
||||
map[string]string{string(vcAnnotations.ContainerTypeKey): string(vc.PodContainer)}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.KillContainerFunc = nil
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
testingImpl.StopContainerFunc = nil
|
||||
}()
|
||||
|
||||
set := flag.NewFlagSet("", 0)
|
||||
set.Parse([]string{testContainerID})
|
||||
|
||||
execCLICommandFunc(assert, killCLICommand, set, true)
|
||||
execCLICommandFunc(assert, killCLICommand, set, false)
|
||||
}
|
||||
|
||||
func TestKillCLIFunctionInvalidStateStoppedFailure(t *testing.T) {
|
||||
|
@ -42,15 +42,17 @@ Where "<container-id>" is the container name to be resumed.`,
|
||||
|
||||
func toggleContainerPause(containerID string, pause bool) (err error) {
|
||||
// Checks the MUST and MUST NOT from OCI runtime specification
|
||||
_, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
status, sandboxID, err := getExistingContainerInfo(containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
containerID = status.ID
|
||||
|
||||
if pause {
|
||||
_, err = vci.PauseSandbox(sandboxID)
|
||||
err = vci.PauseContainer(sandboxID, containerID)
|
||||
} else {
|
||||
_, err = vci.ResumeSandbox(sandboxID)
|
||||
err = vci.ResumeContainer(sandboxID, containerID)
|
||||
}
|
||||
|
||||
return err
|
||||
|
@ -12,17 +12,16 @@ import (
|
||||
"testing"
|
||||
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
"github.com/kata-containers/runtime/virtcontainers/pkg/vcmock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var (
|
||||
testPauseSandboxFuncReturnNil = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
return &vcmock.Sandbox{}, nil
|
||||
testPauseContainerFuncReturnNil = func(sandboxID, containerID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
testResumeSandboxFuncReturnNil = func(sandboxID string) (vc.VCSandbox, error) {
|
||||
return &vcmock.Sandbox{}, nil
|
||||
testResumeContainerFuncReturnNil = func(sandboxID, containerID string) error {
|
||||
return nil
|
||||
}
|
||||
)
|
||||
|
||||
@ -33,7 +32,7 @@ func TestPauseCLIFunctionSuccessful(t *testing.T) {
|
||||
State: vc.StateRunning,
|
||||
}
|
||||
|
||||
testingImpl.PauseSandboxFunc = testPauseSandboxFuncReturnNil
|
||||
testingImpl.PauseContainerFunc = testPauseContainerFuncReturnNil
|
||||
|
||||
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||
assert.NoError(err)
|
||||
@ -44,7 +43,7 @@ func TestPauseCLIFunctionSuccessful(t *testing.T) {
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.PauseSandboxFunc = nil
|
||||
testingImpl.PauseContainerFunc = nil
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
}()
|
||||
|
||||
@ -57,7 +56,7 @@ func TestPauseCLIFunctionSuccessful(t *testing.T) {
|
||||
func TestPauseCLIFunctionContainerNotExistFailure(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
testingImpl.PauseSandboxFunc = testPauseSandboxFuncReturnNil
|
||||
testingImpl.PauseContainerFunc = testPauseContainerFuncReturnNil
|
||||
|
||||
path, err := ioutil.TempDir("", "containers-mapping")
|
||||
assert.NoError(err)
|
||||
@ -65,7 +64,7 @@ func TestPauseCLIFunctionContainerNotExistFailure(t *testing.T) {
|
||||
ctrsMapTreePath = path
|
||||
|
||||
defer func() {
|
||||
testingImpl.PauseSandboxFunc = nil
|
||||
testingImpl.PauseContainerFunc = nil
|
||||
}()
|
||||
|
||||
set := flag.NewFlagSet("", 0)
|
||||
@ -74,7 +73,7 @@ func TestPauseCLIFunctionContainerNotExistFailure(t *testing.T) {
|
||||
execCLICommandFunc(assert, pauseCLICommand, set, true)
|
||||
}
|
||||
|
||||
func TestPauseCLIFunctionPauseSandboxFailure(t *testing.T) {
|
||||
func TestPauseCLIFunctionPauseContainerFailure(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
state := vc.State{
|
||||
@ -106,7 +105,7 @@ func TestResumeCLIFunctionSuccessful(t *testing.T) {
|
||||
State: vc.StateRunning,
|
||||
}
|
||||
|
||||
testingImpl.ResumeSandboxFunc = testResumeSandboxFuncReturnNil
|
||||
testingImpl.ResumeContainerFunc = testResumeContainerFuncReturnNil
|
||||
|
||||
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||
assert.NoError(err)
|
||||
@ -117,7 +116,7 @@ func TestResumeCLIFunctionSuccessful(t *testing.T) {
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.ResumeSandboxFunc = nil
|
||||
testingImpl.ResumeContainerFunc = nil
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
}()
|
||||
|
||||
@ -130,14 +129,14 @@ func TestResumeCLIFunctionSuccessful(t *testing.T) {
|
||||
func TestResumeCLIFunctionContainerNotExistFailure(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
testingImpl.ResumeSandboxFunc = testResumeSandboxFuncReturnNil
|
||||
testingImpl.ResumeContainerFunc = testResumeContainerFuncReturnNil
|
||||
|
||||
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
defer func() {
|
||||
testingImpl.ResumeSandboxFunc = nil
|
||||
testingImpl.ResumeContainerFunc = nil
|
||||
}()
|
||||
|
||||
set := flag.NewFlagSet("", 0)
|
||||
@ -146,7 +145,7 @@ func TestResumeCLIFunctionContainerNotExistFailure(t *testing.T) {
|
||||
execCLICommandFunc(assert, resumeCLICommand, set, true)
|
||||
}
|
||||
|
||||
func TestResumeCLIFunctionPauseSandboxFailure(t *testing.T) {
|
||||
func TestResumeCLIFunctionPauseContainerFailure(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
state := vc.State{
|
||||
|
Loading…
Reference in New Issue
Block a user