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:
parent
d58542a9d1
commit
abf4de4985
@ -24,6 +24,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
goruntime "runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -338,7 +339,14 @@ func Randomize(str string) string {
|
|||||||
|
|
||||||
// KillProcess kills the process by name. pkill is used.
|
// KillProcess kills the process by name. pkill is used.
|
||||||
func KillProcess(name string) error {
|
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 {
|
if err != nil {
|
||||||
return errors.Errorf("failed to kill %q - error: %v, output: %q", name, err, output)
|
return errors.Errorf("failed to kill %q - error: %v, output: %q", name, err, output)
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,6 @@ import (
|
|||||||
// Restart test must run sequentially.
|
// Restart test must run sequentially.
|
||||||
|
|
||||||
func TestContainerdRestart(t *testing.T) {
|
func TestContainerdRestart(t *testing.T) {
|
||||||
if goruntime.GOOS == "windows" {
|
|
||||||
t.Skip("Skipped on Windows.")
|
|
||||||
}
|
|
||||||
type container struct {
|
type container struct {
|
||||||
name string
|
name string
|
||||||
id string
|
id string
|
||||||
@ -75,10 +72,6 @@ func TestContainerdRestart(t *testing.T) {
|
|||||||
name: "created-container",
|
name: "created-container",
|
||||||
state: runtime.ContainerState_CONTAINER_CREATED,
|
state: runtime.ContainerState_CONTAINER_CREATED,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "running-container",
|
|
||||||
state: runtime.ContainerState_CONTAINER_RUNNING,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "exited-container",
|
name: "exited-container",
|
||||||
state: runtime.ContainerState_CONTAINER_EXITED,
|
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")
|
t.Logf("Make sure no sandbox is running before test")
|
||||||
existingSandboxes, err := runtimeService.ListPodSandbox(&runtime.PodSandboxFilter{})
|
existingSandboxes, err := runtimeService.ListPodSandbox(&runtime.PodSandboxFilter{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -139,7 +142,7 @@ func TestContainerdRestart(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("Pull test images")
|
t.Logf("Pull test images")
|
||||||
for _, image := range []string{GetImage(BusyBox), GetImage(Alpine)} {
|
for _, image := range []string{GetImage(BusyBox), GetImage(Pause)} {
|
||||||
EnsureImageExists(t, image)
|
EnsureImageExists(t, image)
|
||||||
}
|
}
|
||||||
imagesBeforeRestart, err := imageService.ListImages(nil)
|
imagesBeforeRestart, err := imageService.ListImages(nil)
|
||||||
@ -154,10 +157,11 @@ func TestContainerdRestart(t *testing.T) {
|
|||||||
assert.Len(t, loadedSandboxes, len(sandboxes))
|
assert.Len(t, loadedSandboxes, len(sandboxes))
|
||||||
loadedContainers, err := runtimeService.ListContainers(&runtime.ContainerFilter{})
|
loadedContainers, err := runtimeService.ListContainers(&runtime.ContainerFilter{})
|
||||||
require.NoError(t, err)
|
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 _, s := range sandboxes {
|
||||||
for _, loaded := range loadedSandboxes {
|
for _, loaded := range loadedSandboxes {
|
||||||
if s.id == loaded.Id {
|
if s.id == loaded.Id {
|
||||||
|
t.Logf("Checking sandbox state for '%s'", s.name)
|
||||||
assert.Equal(t, s.state, loaded.State)
|
assert.Equal(t, s.state, loaded.State)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -165,6 +169,7 @@ func TestContainerdRestart(t *testing.T) {
|
|||||||
for _, c := range s.containers {
|
for _, c := range s.containers {
|
||||||
for _, loaded := range loadedContainers {
|
for _, loaded := range loadedContainers {
|
||||||
if c.id == loaded.Id {
|
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)
|
assert.Equal(t, c.state, loaded.State)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user