Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
cli: fix pause-remove container
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Julio Montes committed May 31, 2018
1 parent b99cadb commit df05b2c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
6 changes: 3 additions & 3 deletions cli/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions cli/kill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,32 +312,35 @@ 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{
State: vc.StatePaused,
}

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) {
Expand Down
8 changes: 5 additions & 3 deletions cli/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 14 additions & 15 deletions cli/pause_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)

Expand All @@ -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)
Expand All @@ -44,7 +43,7 @@ func TestPauseCLIFunctionSuccessful(t *testing.T) {
}

defer func() {
testingImpl.PauseSandboxFunc = nil
testingImpl.PauseContainerFunc = nil
testingImpl.StatusContainerFunc = nil
}()

Expand All @@ -57,15 +56,15 @@ 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)
defer os.RemoveAll(path)
ctrsMapTreePath = path

defer func() {
testingImpl.PauseSandboxFunc = nil
testingImpl.PauseContainerFunc = nil
}()

set := flag.NewFlagSet("", 0)
Expand All @@ -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{
Expand Down Expand Up @@ -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)
Expand All @@ -117,7 +116,7 @@ func TestResumeCLIFunctionSuccessful(t *testing.T) {
}

defer func() {
testingImpl.ResumeSandboxFunc = nil
testingImpl.ResumeContainerFunc = nil
testingImpl.StatusContainerFunc = nil
}()

Expand All @@ -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)
Expand All @@ -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{
Expand Down

0 comments on commit df05b2c

Please sign in to comment.