integration: Enables Windows containerd restart test

The test sets container's Linux.SecurityContext.NamespaceOptions.Pid = NamespaceMode_CONTAINER,
which will ensure that the container keeps running even if the sandbox container dies. We do
not have that option on Windows.

Adds additional logging in the test, so it is easier to figure out which assertion failed.

Signed-off-by: Claudiu Belu <cbelu@cloudbasesolutions.com>
This commit is contained in:
Claudiu Belu 2021-06-08 14:00:07 +00:00
parent d58542a9d1
commit abf4de4985
2 changed files with 23 additions and 10 deletions

View File

@ -24,6 +24,7 @@ import (
"os"
"os/exec"
"path/filepath"
goruntime "runtime"
"strconv"
"strings"
"testing"
@ -338,7 +339,14 @@ func Randomize(str string) string {
// KillProcess kills the process by name. pkill is used.
func KillProcess(name string) error {
output, err := exec.Command("pkill", "-x", fmt.Sprintf("^%s$", name)).CombinedOutput()
var command []string
if goruntime.GOOS == "windows" {
command = []string{"tskill", strings.TrimSuffix(name, ".exe")}
} else {
command = []string{"pkill", "-x", fmt.Sprintf("^%s$", name)}
}
output, err := exec.Command(command[0], command[1:]...).CombinedOutput()
if err != nil {
return errors.Errorf("failed to kill %q - error: %v, output: %q", name, err, output)
}

View File

@ -32,9 +32,6 @@ import (
// Restart test must run sequentially.
func TestContainerdRestart(t *testing.T) {
if goruntime.GOOS == "windows" {
t.Skip("Skipped on Windows.")
}
type container struct {
name string
id string
@ -75,10 +72,6 @@ func TestContainerdRestart(t *testing.T) {
name: "created-container",
state: runtime.ContainerState_CONTAINER_CREATED,
},
{
name: "running-container",
state: runtime.ContainerState_CONTAINER_RUNNING,
},
{
name: "exited-container",
state: runtime.ContainerState_CONTAINER_EXITED,
@ -86,6 +79,16 @@ func TestContainerdRestart(t *testing.T) {
},
},
}
// NOTE(claudiub): The test will set the container's Linux.SecurityContext.NamespaceOptions.Pid = NamespaceMode_CONTAINER,
// and the expectation is that the container will keep running even if the sandbox container dies.
// We do not have that option on Windows.
if goruntime.GOOS != "windows" {
sandboxes[1].containers = append(sandboxes[1].containers, container{
name: "running-container",
state: runtime.ContainerState_CONTAINER_RUNNING,
})
}
t.Logf("Make sure no sandbox is running before test")
existingSandboxes, err := runtimeService.ListPodSandbox(&runtime.PodSandboxFilter{})
require.NoError(t, err)
@ -139,7 +142,7 @@ func TestContainerdRestart(t *testing.T) {
}
t.Logf("Pull test images")
for _, image := range []string{GetImage(BusyBox), GetImage(Alpine)} {
for _, image := range []string{GetImage(BusyBox), GetImage(Pause)} {
EnsureImageExists(t, image)
}
imagesBeforeRestart, err := imageService.ListImages(nil)
@ -154,10 +157,11 @@ func TestContainerdRestart(t *testing.T) {
assert.Len(t, loadedSandboxes, len(sandboxes))
loadedContainers, err := runtimeService.ListContainers(&runtime.ContainerFilter{})
require.NoError(t, err)
assert.Len(t, loadedContainers, len(sandboxes)*3)
assert.Len(t, loadedContainers, len(sandboxes[0].containers)+len(sandboxes[1].containers))
for _, s := range sandboxes {
for _, loaded := range loadedSandboxes {
if s.id == loaded.Id {
t.Logf("Checking sandbox state for '%s'", s.name)
assert.Equal(t, s.state, loaded.State)
break
}
@ -165,6 +169,7 @@ func TestContainerdRestart(t *testing.T) {
for _, c := range s.containers {
for _, loaded := range loadedContainers {
if c.id == loaded.Id {
t.Logf("Checking container state for '%s' in sandbox '%s'", c.name, s.name)
assert.Equal(t, c.state, loaded.State)
break
}