mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-10-22 12:29:49 +00:00
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>
172 lines
4.1 KiB
Go
172 lines
4.1 KiB
Go
// Copyright (c) 2017 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var (
|
|
testPauseContainerFuncReturnNil = func(sandboxID, containerID string) error {
|
|
return nil
|
|
}
|
|
|
|
testResumeContainerFuncReturnNil = func(sandboxID, containerID string) error {
|
|
return nil
|
|
}
|
|
)
|
|
|
|
func TestPauseCLIFunctionSuccessful(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
state := vc.State{
|
|
State: vc.StateRunning,
|
|
}
|
|
|
|
testingImpl.PauseContainerFunc = testPauseContainerFuncReturnNil
|
|
|
|
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
|
|
}
|
|
|
|
defer func() {
|
|
testingImpl.PauseContainerFunc = nil
|
|
testingImpl.StatusContainerFunc = nil
|
|
}()
|
|
|
|
set := flag.NewFlagSet("", 0)
|
|
set.Parse([]string{testContainerID})
|
|
|
|
execCLICommandFunc(assert, pauseCLICommand, set, false)
|
|
}
|
|
|
|
func TestPauseCLIFunctionContainerNotExistFailure(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
testingImpl.PauseContainerFunc = testPauseContainerFuncReturnNil
|
|
|
|
path, err := ioutil.TempDir("", "containers-mapping")
|
|
assert.NoError(err)
|
|
defer os.RemoveAll(path)
|
|
ctrsMapTreePath = path
|
|
|
|
defer func() {
|
|
testingImpl.PauseContainerFunc = nil
|
|
}()
|
|
|
|
set := flag.NewFlagSet("", 0)
|
|
set.Parse([]string{testContainerID})
|
|
|
|
execCLICommandFunc(assert, pauseCLICommand, set, true)
|
|
}
|
|
|
|
func TestPauseCLIFunctionPauseContainerFailure(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
state := vc.State{
|
|
State: vc.StateRunning,
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
defer func() {
|
|
testingImpl.StatusContainerFunc = nil
|
|
}()
|
|
|
|
set := flag.NewFlagSet("", 0)
|
|
set.Parse([]string{testContainerID})
|
|
|
|
execCLICommandFunc(assert, pauseCLICommand, set, true)
|
|
}
|
|
|
|
func TestResumeCLIFunctionSuccessful(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
state := vc.State{
|
|
State: vc.StateRunning,
|
|
}
|
|
|
|
testingImpl.ResumeContainerFunc = testResumeContainerFuncReturnNil
|
|
|
|
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
|
|
}
|
|
|
|
defer func() {
|
|
testingImpl.ResumeContainerFunc = nil
|
|
testingImpl.StatusContainerFunc = nil
|
|
}()
|
|
|
|
set := flag.NewFlagSet("", 0)
|
|
set.Parse([]string{testContainerID})
|
|
|
|
execCLICommandFunc(assert, resumeCLICommand, set, false)
|
|
}
|
|
|
|
func TestResumeCLIFunctionContainerNotExistFailure(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
testingImpl.ResumeContainerFunc = testResumeContainerFuncReturnNil
|
|
|
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
|
assert.NoError(err)
|
|
defer os.RemoveAll(path)
|
|
|
|
defer func() {
|
|
testingImpl.ResumeContainerFunc = nil
|
|
}()
|
|
|
|
set := flag.NewFlagSet("", 0)
|
|
set.Parse([]string{testContainerID})
|
|
|
|
execCLICommandFunc(assert, resumeCLICommand, set, true)
|
|
}
|
|
|
|
func TestResumeCLIFunctionPauseContainerFailure(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
state := vc.State{
|
|
State: vc.StateRunning,
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
defer func() {
|
|
testingImpl.StatusContainerFunc = nil
|
|
}()
|
|
|
|
set := flag.NewFlagSet("", 0)
|
|
set.Parse([]string{testContainerID})
|
|
|
|
execCLICommandFunc(assert, resumeCLICommand, set, true)
|
|
}
|