Merge pull request #5579 from claudiubelu/integration/restart-containerd

integration: Enables Windows containerd restart test
This commit is contained in:
Derek McGowan 2021-10-08 10:33:10 -07:00 committed by GitHub
commit 60ffa3ff7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 10 deletions

View File

@ -23,6 +23,7 @@ import (
"fmt"
"os"
"path/filepath"
goruntime "runtime"
"strconv"
"strings"
"testing"
@ -360,7 +361,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
}